Flutter - Implement LinearGradient to CircularProgressIndicator
Last Updated :
16 Oct, 2023
The LinearGradient widget in Flutter allows you to create linear gradients, which are smooth transitions of colors along a straight line. In this article, we are going to see how can we implement LinearGradient Widget to CircularProgressIndicator in Flutter. A sample video is given below to get an idea about what we are going to do in this article.
Basic Syntax of LinearGradient
LinearGradient(
begin: Alignment.topLeft, // Starting point of the gradient
end: Alignment.bottomRight, // Ending point of the gradient
colors: [Color1, Color2, ...], // List of colors for the gradient
stops: [Stop1, Stop2, ...], // Optional list of color stops
)
Required Tools
To build this app, you need the following items installed on your machine:
- Visual Studio Code / Android Studio
- Android Emulator / iOS Simulator / Physical Device device.
- Flutter Installed
- Flutter plugin for VS Code / Android Studio.
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: Import the Package
First of all import material.dart file.
import 'package:flutter/material.dart';
Step 3: Execute the main Method
Here the execution of our app starts.
Dart
void main() {
runApp(MyApp());
}
Step 4: Create MyApp Class
In this class we are going to implement the MaterialApp , here we are also set the Theme of our App.
Dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green, // Set the app's primary theme color
),
debugShowCheckedModeBanner: false,
title: 'Linear Gradient CircularProgressIndicator',
home: CircularLinearGradientExample(),
);
}
}
Step 5: Create CircularLinearGradientExample Class
In this class we are going to Implement the LinearGradient widget to the CircularProgressIndicator . Comments are added for better understanding.
Center(
child: Container(
width: 70, // Width of the container
height: 70, // Height of the container
decoration: BoxDecoration(
shape: BoxShape.circle, // Make it a circle
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.green, Colors.orange], // Gradient colors
),
),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white), // Indicator color
strokeWidth:
5, // Set the width of the circular progress indicator
),
),
),
),
Dart
class CircularLinearGradientExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Linear Gradient CircularProgressIndicator'),
),
body: Center(
child: Container(
width: 70, // Width of the container
height: 70, // Height of the container
decoration: BoxDecoration(
shape: BoxShape.circle, // Make it a circle
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.green, Colors.orange], // Gradient colors
),
),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white), // Indicator color
strokeWidth:
5, // Set the width of the circular progress indicator
),
),
),
),
);
}
}
Here is the full Code of main.dart file
Dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green, // Set the app's primary theme color
),
debugShowCheckedModeBanner: false,
title: 'Linear Gradient CircularProgressIndicator',
home: CircularLinearGradientExample(),
);
}
}
class CircularLinearGradientExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Linear Gradient CircularProgressIndicator'),
),
body: Center(
child: Container(
width: 70, // Width of the container
height: 70, // Height of the container
decoration: BoxDecoration(
shape: BoxShape.circle, // Make it a circle
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.green, Colors.orange], // Gradient colors
),
),
child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white), // Indicator color
strokeWidth:
5, // Set the width of the circular progress indicator
),
),
),
),
);
}
}
Output:
Similar Reads
Flutter - Set Size to CircularProgressIndicator
In Flutter, we can simply wrap the CircularProgressIndicator widget as a Container widget and gives the height and width of the container that result in the increase and decrease in the size of the CircularProgressIndicator. A sample video is given below to get an idea about what we will do in this
3 min read
Flutter - Implementing Calendar
Nowadays in most of the apps, we see Calendar in most of the apps for displaying birth dates or for any appointment application. Displaying the date in the app with the help of the Calendar view gives a better user experience. In this article, we are going to see how to implement Calendar in our Flu
3 min read
Implementing Rest API in Flutter
Along with building a UI in Flutter, we can also integrate it with the backend. Most applications use APIs to display user data. We will use the http package, which provides advanced methods to perform operations. REST APIs use simple HTTP calls to communicate with JSON data because: It uses await
5 min read
Flutter - Implementing Swipe to Dismiss Feature
The Swipe to dismiss feature is used by us in many mobile apps. In this article, we will create a list of items and implement a swipe to dismiss in it. When we want to dismiss the content using swipe then we can do this with the help of swipe to dismiss widget in a flutter. Generally, we use this wh
2 min read
Flutter - Circular & Linear Progress Indicators
Progress Indicator in any application displays the time which is needed for some tasks to complete such as downloading, installation, uploading, file transfer, etc. This shows the progress of a task or the time to display the length of the processes. In Flutter, progress can be displayed in two ways
4 min read
Flutter - Implementing Badges
Badges can be used for various purposes in an application. For example, showing the number of messages, number of items in the cart, etc. In this article, we will see the implementation of badges in Flutter using the badges Flutter package. Install the library: In the pubspec.yaml file, add badges l
5 min read
How to Implement Adaptive and Responsive NavBar in Flutter?
NavigationBar in web applications plays a crucial role. And different frameworks have different styles to implement. In Flutter, we have to mention differently for both mobile and website. But we can implement, the same navigation items in the drawer with this adaptive_navbar package in Flutter. How
2 min read
Flutter - Implement Stepper Widget Inside an AlertDialog
The Stepper widget in Flutter is a user interface element used to create a step-by-step process interface. It allows users to progress through a series of steps or stages, with each step typically representing a specific task or some information. An Alert Dialog is a useful way to grab users' attent
5 min read
How to Implement Fancy Bottom NavigationBar in Flutter?
Fancy Bottom NavigationBar is a MaterialApp widget that displays a bottom fancy navbar, Where items go between 2 and 4. Bottom NavigationBar is the list of icons or text in the horizontal form called a tab and Each tab contains their own page. Step By Step ImplementationStep 1: Create a New Project
3 min read
ClipRRect Widget in Flutter
The ClipRRect widget in flutter is used to clips its child using a rounded rectangle. It associates with the Clippers family. The main use of clippers is to clip out any portion of the widget as required. It behaves similar to that of ClipRect and is used to Clip a Rectangle portion of the child wid
2 min read