With the advent of technology, Flutter stands out as a game-changer in app development. One of its popular features is the 'loading indicator.'
Imagine you're a user inputting data into a Flutter app, and the app has to execute a network request, which might be a very quick operation or even take a bit longer. Without a loading indicator, the user might perceive the app has stalled, leading to bad user experiences.
This is where the flutter_easyloading package becomes your go-to tool for a smooth, user-friendly application.
The flutter_easyloading package is a clean and lightweight loading toast widget for Flutter. Think of the excellent loaders it enables you to create: loading indicators animated delightfully, exhibiting creative loading animations that don't require any extra dependency.
In this blog, we delve deep into the workings of the Flutter easy-loading package. With solid examples, essential tips, and everything in between, this comprehensive guide will empower you to implement effective loading indicators in your Flutter apps.
Flutter Easyloading is a powerful Flutter package created to implement seamless and interactive loading indicators in your Flutter app. It offers many customizable options to bring your creativity to life when loading widgets. Flutter Easyloading provides a clean, lightweight loading toast widget, making your loading status more exciting and less bothersome for the user.
Why is Easyloading so important? Imagine performing an asynchronous operation that requires a definite period for execution. With Easyloading, you control what the user sees during that period. You can display the progress indicator on the current screen, projecting the loading status of your background work. This feature helps to enhance user interactions, keeping your users engaged even when the screen seems passive.
This package stands out because of its independent context support for iOS, Android, and the web, something very few packages offer. In other words, you can use Easyloading without context support for iOS, Android, and the web. It delivers a pure Dart plugin, which means you get a Flutter plugin and a Dart plugin in one package. Its rich features, like animated loading indicators and water-like effects, make Easyloading a must-use for every Flutter developer.
The first step towards utilizing the power of Flutter Easyloading revolves around installing and importing the package to your project.
To start, add the flutter_easyloading package to your project's pubspec.yaml file. This file houses the list of dependencies necessary for your Flutter application.
The process is simple and works similarly to adding any other Flutter package. You can locate the latest stable version of Flutter Easyloading on pub.dev and use it in your pubspec.yaml file like so:
1dependencies: 2 flutter: 3 sdk: flutter 4 5 flutter_easyloading: ^3.0.5
Remember to replace ^3.0.5 with the latest version number of the package.
Next, run the flutter pub get command in your project's terminal to fetch the package. After successful installation, import flutter_easyloading to the Dart file where you plan to use it as follows:
1import 'package:flutter_easyloading/flutter_easyloading.dart';
Once installed and imported, we can implement our first loading indicator using Flutter Easyloading.
After successfully installing the package, it's time to create your first loading indicator. Flutter Easyloading provides a very simple full-screen loader setup that can be easily implemented.
Here's a simple step-by-step guide on how to create a primary loading indicator.
Firstly, configure Easy loading in your primary function before running your app:
1void main() { 2 runApp( 3 MaterialApp( 4 home: MyApp(), 5 builder: (BuildContext context, Widget child) { 6 return FlutterEasyLoading( 7 child: MyApp(), 8 ); 9 }, 10 ), 11 ); 12}
Please note that you must wrap the EasyLoading widget below the MaterialApp.
Here's a simple implementation of your main App:
1class MyApp extends StatelessWidget { 2 // This widget is the root of your application. 3 @override 4 Widget build(BuildContext context) { 5 return MaterialApp( 6 home: Scaffold( 7 appBar: AppBar( 8 title: Text("Flutter Easyloading"), 9 ), 10 body: Center( 11 child: RaisedButton( 12 child: Text('Show Loader'), 13 onPressed: () { 14 EasyLoading.show(status: 'loading...'); 15 // Perform your task and then hide loader 16 Future.delayed(Duration(seconds: 3), () { 17 EasyLoading.dismiss(); 18 }); 19 }, 20 ), 21 ), 22 ), 23 ); 24 } 25}
The EasyLoading.show(status: 'loading...') line will display the loading indicator on the screen with the status as 'loading...', and the EasyLoading.dismiss() command will close the overlay after the task is completed.
Remember that these are just simple loading indicators, but Easyloading allows you to customize and create your progress indicator.
Part of the beauty of Flutter Easyloading is the vast extent to which loading indicators can be customized. From the loading animations to the water-like effect, it provides a flexible mechanism to create more engaging loading instances.
First, follow the steps mentioned in the earlier sections to install and import the package. Next, use the available EasyLoading properties to customize your indicators. Let's imagine we want a more fascinative loading toast widget for the Flutter app; the code snippet below shows you how to implement this:
1import 'package:flutter_easyloading/flutter_easyloading.dart'; 2 3void main() { 4 runApp( 5 MaterialApp( 6 home: MyApp(), 7 builder: (BuildContext context, Widget child) { 8 EasyLoading.instance 9 ..displayDuration = const Duration(milliseconds: 2000) 10 ..indicatorType = EasyLoadingIndicatorType.fadingCircle 11 ..loadingStyle = EasyLoadingStyle.custom 12 ..indicatorSize = 45.0 13 ..radius = 10.0 14 ..progressColor = Colors.yellow 15 ..backgroundColor = Colors.green 16 ..indicatorColor = Colors.yellow 17 ..textColor = Colors.yellow 18 ..maskColor = Colors.blue.withOpacity(0.5) 19 ..userInteractions = false; 20 21 return FlutterEasyLoading(child: child); 22 }, 23 ), 24 ); 25}
In the example above, you can notice how cleanly and comfortably you can adapt the look and feel of your loading widget by changing the properties of EasyLoading.instance.
Choosing different indicatorType values will present you with more IndicatorType options. The progressColor, backgroundColor, indicatorColor, and textColor values are pretty straightforward - they set the colors for the corresponding components.
A special mention goes to the circular progress indicator among the various loading indicators the flutter_easyloading package offers. Whether you're waiting for a file to download or waiting for a network request, displaying a circular progress bar enhances the user experience, making the wait less frustrating.
With Flutter Easyloading, we have several style options for building circular progress indicators. Let's see how we can implement a primary circular progress indicator:
1class MyApp extends StatelessWidget { 2 @override 3 Widget build(BuildContext context) { 4 return MaterialApp( 5 builder: EasyLoading.init(), 6 home: Scaffold( 7 appBar: AppBar(), 8 body: Center( 9 child: RaisedButton( 10 onPressed: () async { 11 EasyLoading.showProgress(0.3, status: "loading..."); 12 await Future.delayed(const Duration(seconds: 5)); 13 EasyLoading.showProgress(0.7, status: 'downloading...'); 14 await Future.delayed(const Duration(seconds: 5)); 15 EasyLoading.showProgress(1.0, status: 'Success!'); 16 await Future.delayed(const Duration(seconds: 2)); 17 EasyLoading.dismiss(); 18 }, 19 child: Text('Show Progress'), 20 ), 21 ), 22 ), 23 ); 24 } 25}
The EasyLoading.showProgress function displays a circular progress indicator with a custom progress and status display, while the EasyLoading.dismiss function closes the indicator.
However, there's a lot more to create with Flutter Easyloading. With some creativity and bending code, you can create outstanding and fully customizable circular progress indicators that enhance user experiences and blend perfectly with your application.
Moving beyond simple indicators, the Flutter Easyloading package provides the tools to create your loading widget. This is particularly useful when your app has a particular design guideline or wants to display more than just a loading status.
Creating your loading widget is as simple as the other operations we have done before and gives you additional control over how your app interacts with the user. Here's an example of creating a custom loading widget:
1class MyApp extends StatelessWidget { 2 @override 3 Widget build(BuildContext context) { 4 return MaterialApp( 5 builder: (BuildContext context, Widget child) { 6 EasyLoading.instance 7 ..indicatorWidget = Center( 8 child: Padding( 9 padding: const EdgeInsets.all(8.0), 10 child: Container( 11 width: 150, 12 height: 90, 13 decoration: BoxDecoration( 14 color: Colors.teal, 15 borderRadius: BorderRadius.circular(10), 16 ), 17 child: Column( 18 mainAxisAlignment: MainAxisAlignment.center, 19 crossAxisAlignment: CrossAxisAlignment.center, 20 children: <Widget>[ 21 CircularProgressIndicator( 22 valueColor: AlwaysStoppedAnimation<Color>(Colors.white), 23 ), 24 SizedBox( 25 height: 5, 26 ), 27 Text( 28 'Loading...', 29 style: TextStyle(color: Colors.white), 30 ), 31 ], 32 ), 33 ), 34 ), 35 ) 36 ..userInteractions = false; 37 38 return FlutterEasyLoading(child: child); 39 }, 40 home: Scaffold( 41 appBar: AppBar( 42 title: const Text('Creating Custom Loading Widget'), 43 ), 44 body: Center( 45 child: ElevatedButton( 46 onPressed: () { 47 EasyLoading.show(); 48 Future.delayed(const Duration(milliseconds: 2000), () { 49 EasyLoading.dismiss(); 50 }); 51 }, 52 child: const Text('Show Custom Loader!'), 53 ), 54 ), 55 ), 56 ); 57 } 58}
In this example, we define an entirely new widget that animates a circular progress bar and displays a text status within a styled container. You can replace this setup with any Widget that suits your needs.
By creating custom loading widgets, you can provide richer feedback to your users, control user interactions effectively, and highlight the uniqueness of your app.
Interactive and practical user interfacing separates the wheat from the chaff in today's flood of mobile applications. To stay one step ahead, you must ensure your application is seamless, responsive, and engaging. Loading times are a crucial component of this, as leaving a user confused during a more extended asynchronous operation can lead to dissatisfaction.
Fortunately, with flutter_easyloading, you possess a magical tool that can transform the loading experience from dull to delightful. Whether it's a simple full-screen loader, a circular progress bar, or a fully customized loading widget that matches the aesthetics of your app, flutter_easyloading has got you covered.
By adequately employing this package, you can maintain a seamless user experience, even during the most data-intensive operations. This guide walked you through the process from installing the Flutter plugin and implementing your first loader to crafting fully customized loaders.
Happy loading!
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.