This website will be permanently discontinued and will no longer be accessible.
FINAL DAY OF SERVICE: 26 November 2024
Thank You for Your Support
Dear valued users,
We want to inform you that this website will be permanently shutting down. After this date, all services and content will no longer be accessible.
We sincerely thank you for your support and trust throughout our journey.
Important Dates:
Last Day: 26/11/2024
Data Access:Until the last day
Dear valued users,
We want to inform you that this website will be permanently shutting down. After this date, all services and content will no longer be accessible.
We sincerely thank you for your support and trust throughout our journey. Important Dates: Last Day: 26/11/2024 Data Access:Until the last day
Modern UIs use gradients in their app. In Flutter, you can also create gradients. Let’s see how you can change your app’s background color to the gradient.
You will learn about gradient backgrounds using the BoxDecoration widget inside the Container Widget decoration property.
For a more quick approach, you will use the scaffold_gradient_background package.
In this Article
Method 1: Gradient Background with BoxDecoration
You will create a gradient background by using the Container widget.
How do you do that?
First You will create a scaffold screen and make the scaffold background transparent.
class GradientBackgroundScreen extends StatelessWidget {
const GradientBackgroundScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Scaffold(
//Make sure you make the scaffold background transparent
backgroundColor: Colors.transparent,
body: Center(child: Text('Welcome!')),
);
}
}
Then wrap this Scaffold with the Container widget and define the decoration property.
decoration property will take BoxDecoration as an argument. You will pass the BoxDecoration with gradient property.
In this example, you will use the LinearGradient widget, in which you define colors and the begin and end properties.
Most of the time above method is enough but sometimes you want a more quick solution for the Flutter gradient background. You will exactly learn that method below.
Method 2: Create Gradient Background Using scaffold_gradient_background Package
This is the single-line solution for adding a gradient background.
You will install the scaffold_gradient_background package from the pub.dev.
You find out about the two super easy ways to add gradients to your flutter app. you first use the Container widget with the BoxDecoration property then you use a gradient package from the flutter packages.