Flutter - Slider with Gradient
Last Updated :
26 Apr, 2025
In this article, we will create a slide to confirm the button using the widget in Flutter. A sample video is given below to get an idea about what we are going to do in this article.
Step By Step Implementation
Step 1: Create a New Project in Android Studio
To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.
Step 2: Add the dependency into your pubspec yaml file
flutter pub add gradient_slide_to_act
This will add a line like this to your package’s pubspec.yaml (and run an implicit flutter pub get):
Step 3: Import the package into the main file
Adding material package that gives us the important functions and calls the runApp method in the main function that will call our application.
import 'package:flutter/material.dart';
import 'package:gradient_slide_to_act/gradient_slide_to_act.dart';
void main() {
runApp(RunMyApp());
}
Step 4: Creating Stateful Widget
Now we have to make a stateful widget because our application does change its state and then returns the MaterialApp widget which allows us the set the title and theme and many more.
class RunMyApp extends StatefulWidget {
const RunMyApp({super.key});
@override
State<RunMyApp> createState() => _RunMyAppState();
}
class _RunMyAppState extends State<RunMyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp();
}
}
Step 5: Working with Scaffold
Give the home property and there can be a scaffold widget with AppBar and body property. AppBar allows us to give the title of AppBar, color, leading, and trailing icon.
home: Scaffold(
appBar: AppBar(
title: Text('Gradient Slide to act'),
),
body:
),
Step 6: Now create the Gradient slide to act widget and assign its parameters like - width, backgroundColor, gradient, etc.,
Center(
child: GradientSlideToAct(
width: 400,
textStyle: TextStyle(color: Colors.white, fontSize: 15),
backgroundColor: Color.fromARGB(255, 23, 99, 29),
onSubmit: () {
Print("Submitted!");
},
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromARGB(255, 13, 194, 28),
Color.fromARGB(255, 8, 87, 5),
]),
),
),
),
Final Code:
Dart
import 'package:flutter/material.dart';
import 'package:gradient_slide_to_act/gradient_slide_to_act.dart';
void main() {
runApp(RunMyApp());
}
class RunMyApp extends StatefulWidget {
const RunMyApp({super.key});
@override
State<RunMyApp> createState() => _RunMyAppState();
}
class _RunMyAppState extends State<RunMyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(
title: Text('Gradient Slide to Act'),
),
body: Center(
child: GradientSlideToAct(
width: 400,
textStyle: TextStyle(color: Colors.white, fontSize: 15),
backgroundColor: Color.fromARGB(255, 23, 99, 29),
onSubmit: () {
Print("Submitted!");
},
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromARGB(255, 13, 194, 28),
Color.fromARGB(255, 8, 87, 5),
]),
),
),
),
);
}
}
Output:
Similar Reads
Flutter - Custom Gradient Switch
If you are using Flutter you must hear that it is very easy to make UI in this. All widgets are easy to use. So now let's make one common widget that you must have seen in almost every app i.e. Switch. Now you will say it is very easy to make from the switch widget. But we will make it a Gradient Sw
5 min read
SliverList in Flutter
In Flutter, with slivers, we can create different scrolling effects. Slivers give an amazing view of the lists when they scroll up or down. The slivers allow us to impact the Lists, Grids scrolling experience. In this article, we will be looking at Slivers features offered by the sliver_tools packag
4 min read
Flutter - Gradient TextFields
Decorating text fields can be a big task if you have a large application. There is a package gradient_textfield that could make this time-consuming task pretty simple and fast. Although in Flutter we can create text fields using TextField, for beginners especially, it takes time to understand decora
3 min read
Flutter - GridPaper Widget
A grid paper is a paper that has a grid on it with divisions and subdivisions, for example, graph paper. We may use grid paper in creating the graphs in our flutter application. A sample image is given below to get an idea about what we are going to do in this article. Â How to use it?Dart GridPaper(
3 min read
Flutter - OrientationBuilder Widget
OrientationBuilder is a Flutter widget that allows you to build a widget tree based on the orientation (portrait or landscape) of the device. It's useful when you want to create a different UI layout or make adjustments based on the device's orientation. In this article, we are going to implement th
4 min read
Switches in Flutter
The major seen usage of the switch is in switching between dark and light theme of app. It depends upon UI what kind of switch is required. In Flutter, with flutter_switch we can create from simple to customized switch with custom height, width, colors, text, etc. Let us see its usage and implementa
4 min read
Flutter - Set Device Volume with Slider
A slider is a widget to select a value from a given range in the application. We can slide through the value and select the desired value from it. We donât need to install any dependency to implement a slider. In this article, we will learn how to control the volume of the device from our Flutter ap
4 min read
Flutter - Slider and RangeSlide
A slider is a widget to select a value from a given range in the application. We can slide through the value and select the desired value from it. We don't need to install any dependency to implement a slider. A Range Slider is very similar to a Slider widget but instead of selecting a single value,
3 min read
Flutter - Add Gradient Effect to ListTile
In Flutter, a gradient effect is a visual effect that smoothly transitions between two or more colours, creating a gradual blend or progression of colours. To add a gradient background to a ListTile in Flutter, you can wrap the ListTile with a Container or another widget that supports gradients, suc
3 min read
Flutter - GestureDetector Widget
A GestureDetector is a very useful Flutter widget that allows you to recognize and respond to various touch gestures, such as taps, swipe, double taps, drags, and more. It provides a way to make your Flutter app interactive and responsive to user input. In this article, we are going to implement and
4 min read