Shimmer Container in Flutter
Last Updated :
24 Apr, 2025
A Shimmer Container is the fade-in and fade-out effect, We can show it instead using CircularProgressIndicator or Linear progress indicator that looks decent. While fetching the data from the API or from the database we need to wait as it is an asynchronous process, we need to do something on the user screen, shimmer containers do that job for use further if we got the data we will show them.
A sample output gives you an idea of what we are going to implement in this article:
How to Use:
Dart
ShimmerContainer(
height: 80, // height of container
width: double.maxFinite, // width of container
radius: 4, // corner radius of container
highlightColor: Color(0xffF9F9FB), // color of container
baseColor: Color(0xffE6E8EB),
);
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 in the pubspec.yaml file
Now we need to import the package into the pubspec.yaml file, which you find at the last of the root folder.
From the command line:
flutter pub add shimmer_container
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
import 'package:shimmer_container/shimmer_container.dart';
import 'package:flutter/material.dart';
void main() {
runApp(RunMyApp());
}
In the above code, runApp method calls the class RunMyApp, Now we have to create it.
Step 4: Creating Stateless Widget
Now we have to make a stateless widget because our application does not go to change its state and then return the MaterialApp widget which allows us the set the title and theme and many more of the application.
Shortcut for Creating Stateless or Stateful Widgets:
You can create a stateless widget by just typing three alphabets ‘stl’ and you can see a stateless widget and then hit enter.
class RunMyApp extends StatelessWidget {
const RunMyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home:
);
}
}
Step 5: Working with the Body of the Scaffold
In the body of the scaffold use the column widget that will contain the multiple children, now we can use various functions called to show the numerous shimmer containers.
Scaffold(
appBar: AppBar(
title: Text('Shimmer Container'),
),
body: Column(
children: [
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
],
),
),
As you saw we call the Shimmer method (not defined yet) to show multiple shimmer containers. Now create the Shimmer method.
Step 6: Define the Shimmer Function
Widget Shimmer() {
return ShimmerContainer(
height: 80,
width: double.maxFinite,
radius: 4,
highlightColor: Color(0xffF9F9FB),
baseColor: Color(0xffE6E8EB),
);
}
This function returns the widget ShimmerContainer with height, width, radius, highlightColor, and baseColor.
Complete Code:
Dart
import 'package:flutter/material.dart';
import 'package:shimmer_container/shimmer_container.dart';
void main() {
runApp(RunMyApp());
}
class RunMyApp extends StatelessWidget {
const RunMyApp({
super.key
});
Widget Shimmer() {
return ShimmerContainer(
height: 80,
width: double.maxFinite,
radius: 4,
highlightColor: Color(0xffF9F9FB),
baseColor: Color(0xffE6E8EB),
);
}
@
override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.green),
home: Scaffold(
appBar: AppBar(
title: Text('Shimmer Container'),
),
body: Column(
children: [
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
SizedBox(
height: 2,
),
Shimmer(),
],
)
),
);
}
}
Output:
Similar Reads
Flutter - Container Styling
In this article we will look at the most basic and simple widget in flutter Container. We will look that how can we style our container in different ways according to our need , so that we can effectively use this widget in our app . First of all we have to write some starting code for our project
4 min read
Container class in Flutter
Container class in flutter is a convenience widget that combines common painting, positioning, and sizing of widgets. A Container class can be used to store one or more widgets and position them on the screen according to our convenience. Basically, a container is like a box to store contents. A bas
8 min read
Center widget in Flutter
Center widget comes built-in with flutter, it aligns its child widget to the center of the available space on the screen. The size of this widget will be as big as possible if the widthFactor and heightFactor properties are set to null and the dimensions are constrained. And in case the dimensions a
2 min read
Flutter - Shimmer
In Flutter, Shimmer is used to add beautiful animations while content is loading from the servers in an application. This makes the UI look more responsive and secures users from leaving a slow internet interaction. It can be used instead of conventional ProgressBar or usual loaders available in the
4 min read
Flutter - AnimatedContainer Widget
In Flutter a container is a simple widget with well-defined properties like height, width, and color, etc. The AnimatedContainer widget is a simple container widget with animations. These types of widgets can be animated by altering the values of their properties which are the same as the Container
3 min read
Flutter - ConstrainedBox Widget
ConstrainedBox is a built-in widget in flutter SDK. Its function is to add size constraints to its child widgets. It comes quite handy if we want a container or image to not exceed a certain height and width. It is also good to keep text in a wrapped layout by making the Text widget a child on Const
2 min read
Align Widget in Flutter
Align Widget is the widget that is used to align its child within itself and optionally sizes itself based on the child's size. Align Widget is quite flexible and can change its size according to the size of its child. Constructor of Align class: Syntax: Align({Key key, AlignmentGeometry alignment:
2 min read
Recipe Finder Application in Flutter
This app will display a list of recipes in a card format, each containing the recipe title, a rating, the cooking time, and a thumbnail image to give users a visual preview. The app is dynamic and flexible, allowing you to easily update the recipe list or modify the UI as needed.By the end of this t
5 min read
Flutter - Collapse Sidebar
Sidebar is also called the Drawer of the Application and mainly use in every android and iOS Application. Sidebar is used to work with more screens and make the application more user interactive. Sidebar provides the users to use the different screens in the single-page application. A collapsible si
4 min read
Drawer Widget in Flutter
Drawer widget is used to provide access to different destinations and functionalities provided in your application. It is represented by three horizontal parallel lines on the upper end of the scaffold. It has a horizontal movement from the edge of the Scaffold that navigates the link to different r
5 min read