Ebook Flutter Libraries We Love by Codemagic
Ebook Flutter Libraries We Love by Codemagic
All rights reserved. This publication text may not be uploaded or posted online without the prior
written permission of the publisher. For permission requests, write to the publisher, addressed
“Ebook permissions request”: liina@nevercode.io
Want to use a
Flutter or Dart library
in your application?
Check which package versions are
compatible with your Flutter version
SEARCH PACKAGE
We build the 1,000 most popular packages on pub.dev against multiple Flutter
channels and versions to test their compatibility so you don’t have to.
Table of contents
Editorial note
It all started with a tweet, like so many things nowadays. Marie Jaksman, the CMO
of Codemagic, tweeted a question in March to find out which Flutter Libraries are
absolutely necessary for developers.
We got so many great ideas from the answers that it was impossible to squeeze all
those libraries into one article. Instead, we decided to create our first-ever ebook.
The idea was to cover a wide range of categories and to showcase different
libraries – some that are less known gems but also some that are already quite popular
and have the Flutter Favorite label on them.
Unfortunately, we couldn’t cover all the libraries from the tweets we got but we
tried to find a great balance between famous libraries and hidden treasures.
This book is not a beginners book, although feel free to take a look if you are one.
You won’t find all “must have” libraries here but you might find an interesting
selection of something unique. We tried to pick libraries that might not be popular yet
but have both great potential and our wholehearted support. In addition to that, there
are also some libraries that we just had to mention because the Flutter community
simply loves them.
codemagic.io 2
Introduction
When talking to developers, one question always comes up – what tools should we
use? Flutter is relatively new but the selection of Flutter libraries is growing fast.
We focused on 11 different Flutter library categories. After selecting the categories,
we made a list of libraries under each category and chose the libraries we wanted to
highlight the most.
1. State management
2. Networking
3. Text and fonts
4. UX/UI
5. Location and connectivity
6. Images and videos
7. Data persistence and file system
8. Animations and transitions
9. Utility
10. Code generator and build tools
11. Testing
Each category has a list of Flutter libraries as well as a highlighted library that we
dig deeper into.
In addition to an overall description, all highlighted libraries consist of pros and
cons, developer’s perspective and real‑life code examples.
codemagic.io 3
STATE MANAGEMENT
State management is a crucial aspect when working on a large scale
production app. That said, every state management solution is
unique and is fit for a certain architecture of the app.
Let’s take a look at one of the state management libraries that
does a great job of separating the business logic
from the UI – Flutter BLoC.
1/11
codemagic.io 4
Flutter BLoC
Helps implement BLoC pattern
by Felix Angelov
Flutter BLoC is a predictable state management library that helps to implement the
Business Logic Component (BLoC) design pattern. It uses reactive programming to
handle the flow of data within an app.
codemagic.io 5
Why BLoC?
BLoC helps to encapsulate the business logic from the UI. Events are fed in as the
input to the logic component and states are generated as the output. It relies heavily
on Streams and is often used in conjunction with the Provider for exposing the BLoC
to the UI. Testing BLoC is really easy using the library bloc_test.
Developer’s perspective
There are a lot of options while choosing a state management library for Flutter, and
every app’s structure is unique. So, there is no state management library best for every
use case. BLoC is really nice if you are working on a large-scale production app, but
due to the amount of boilerplate code, it might not be suitable for smaller apps.
Example
An app for fetching applications using Codemagic API is implemented using the BLoC
pattern.
The FetchApplication event will be added to the BLoC to fetch the applications
from the server. It will mostly be used right after the initial state when there are no
applications fetched yet.
codemagic.io 6
// BLoC Event
@override
List<Object> get props => [];
}
ApplicationState will define all possible states while fetching the applications from
the server.
// BLoC State
@override
List<Object> get props => [];
}
codemagic.io 7
ApplicationLoaded({required this.application});
@override
List<Object> get props => [application];
}
// BLoC
ApplicationBloc({required this.applicationRepository})
: super(ApplicationEmpty());
@override
Stream<ApplicationState> mapEventToState(ApplicationEvent
event) async* {
if (event is FetchApplication) {
yield ApplicationLoading();
try {
final Application? application =
await (applicationRepository.fetchApplication());
if (application != null) {
codemagic.io 8
ApplicationPage({required this.repository});
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) =>
ApplicationBloc(applicationRepository: repository),
child: ApplicationView(),
);
}
}
BlocBuilder is used to build the UI based upon the state returned by the Application-
Bloc. When the state is ApplicationEmpty, the FetchApplication event is added to the
ApplicationBloc.
codemagic.io 9
codemagic.io 10
Reference links
Package
Documentation
Sample app
codemagic.io 11
codemagic.io 12
NETWORKING
Fetching data from the internet is necessary for most apps. Stated
below are some Flutter libraries that will help you to make network
requests and handle the responses gracefully in your app.
2/11
codemagic.io 13
Dio
A powerful HTTP client for Dart
by Flutter China
Dio is a Flutter networking library for handling HTTP requests with ease. It
supports interceptors, global configuration, FormData, request cancellation, file
downloading, timeout, etc.
“Dio is a powerful tool for API calls and much more. With
customer interceptors with Dio, I have super powers!”
codemagic.io 14
Why Dio?
Dio is a quite helpful library for anyone working with APIs in their application. It helps
with making API calls and provides good control over them. With Dio, you can easily
manage uploading and downloading of multiple files. Using Dio Interceptor allows
you to intercept and lock/unlock requests for performing some operations in between
an API request.
Developer’s perspective
There is a similar library for handling HTTP requests in Dart, known as http. But it is
quite verbose and does not allow much control over the HTTP calls. Interceptor is a
vital part of Dio that is useful in different scenarios, for example if you want to auto‑
matically retry a request when the internet connection is restored. You can even track
the download progress of large files easily using Dio.
Pros
+ Make API calls over HTTP
+ Track download/upload progress
+ Ability to intercept requests
Example
// Initialize Dio
BaseOptions options = new BaseOptions(
baseUrl: ‘https://api.codemagic.io’,
connectTimeout: 5000,
receiveTimeout: 3000,
headers: {
codemagic.io 15
“Content-Type”: “application/json”,
“x-auth-token”: _token,
});
// POST Data
Response response = await _dio.post(
“/builds”,
data: {
“appId”: _appId,
“workflowId”: _workflowId,
“branch”: _branch,
},
);
if (response.statusCode == 200) {
print(response.data);
}
// GET Data
Response response = await _dio.get(
“/builds/$_buildId”,
);
if (response.statusCode == 200) {
print(response.data);
}
Reference links
Package
Documentation
Sample app
codemagic.io 16
codemagic.io 17
3/11
codemagic.io 18
Animated Text Kit provides you with easy implementation of beautiful and nice text
animations to your Flutter app. It contains 7 types of text animations, including
Rotate, Fade, Typer, Typewriter, Scale, Colorize and TextLiquidFill.
codemagic.io 19
Developer’s perspective
Animated Text Kit is an impressive text animation package that lets you add
subtle but eye‑catching texts to your app. This package comes with several types
of text animations, but the most distinguishable among these is the TextLiquidFill,
which adds a liquid filling-like text animation.
Pros
+ Easy implementation
+ Large number of customization options
+ Support for any TextStyle
Example
codemagic.io 20
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 200),
TextLiquidFill(
text: ‘CODE’,
waveColor: Colors.blueAccent.shade700,
boxBackgroundColor: Colors.orange.shade600,
textStyle: style,
waveDuration: Duration(seconds: 4),
boxHeight: 120,
boxWidth: 300,
),
TextLiquidFill(
text: ‘MAGIC’,
waveColor: Colors.blueAccent.shade700,
boxBackgroundColor: Colors.orange.shade600,
textStyle: style,
waveDuration: Duration(seconds: 2),
boxHeight: 120,
boxWidth: 300,
),
],
),
);
}
}
codemagic.io 21
Reference links
Package
Documentation
Wavy Liquid Animation for Text
Sample app
codemagic.io 22
codemagic.io 23
UX/UI
Getting User Interface and User Experience right is a crucial thing
in modern applications. Flutter is known as Google’s UI toolkit for
creating beautiful and natively compiled apps.
To further improve your app design, let’s take a look at some UI
libraries that caught our attention.
The most unique UI library that we want to highlight is VelocityX.
4/11
codemagic.io 24
VelocityX
A minimalist UI framework for Flutter
by Pawan Kumar
VelocityX gives you access to all the building blocks you need to create beautiful and
responsive UI designs. This package uses Tailwind CSS‑like property naming and
SwiftUI style declarative syntax to facilitate rapid development.
codemagic.io 25
Why VelocityX?
VelocityX can make developers more productive because of its declaration style. It
uses extension methods to form a chain of properties, rather than using the nested
style, which is default in Flutter.
Developer’s perspective
Though this package can make you more productive, this property chaining style can
be quite intimidating for the beginners.
The best thing about this package is that it makes every widget responsive, which is
great if you are building Flutter apps for Web or Desktop.
This makes VelocityX quite popular among everyone who wants to create
Flutter apps that are mainly focused on the web and desktop platform. But those who
are mostly focused on mobile cross‑platform support might prefer the nested style of
Flutter. Also, using this package compromises the readability of the code.
Example
codemagic.io 26
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
‘VelocityX’
.text.orange500.semiBold.size(40).make()
.p16(),
VxZeroList(
length: 3,
isDark: true,
isBottomLinesActive: false,
),
[
“Velocity 1”
.text.white.uppercase.size(20).make()
.box.rounded.alignCenter.purple600.make()
.p4(),
“Velocity 2”
.text.white.uppercase.size(20).make()
.box.rounded.alignCenter.green500.make()
.p4(),
“Velocity 3”
.text.white.uppercase.size(20).make()
.box.rounded.alignCenter.orange500.make()
.p4(),
].swiper(enlargeCenterPage: true).py12(),
‘Codemagic’.text.uppercase.red600.bold
.letterSpacing(8).size(40).make()
.p16(),
],
),
).make(),
),
);
}
}
codemagic.io 27
Reference links
Package
Documentation
VelocityX Tutorials on MTECHVIRAL
Sample app
codemagic.io 28
codemagic.io 29
LOCATION AND
CONNECTIVITY
If you are working with an app that requires you to
access some platform-specific services like device location, Bluetooth,
WiFi, etc., then you may want a helpful plugin to achieve that. If you
are dealing with any of the above, there are some Flutter libraries
that may come in handy.
Let us introduce you to a Flutter plugin that allows you to work with
locations and gives you easy access to geocoding.
5/11
codemagic.io 30
Geolocator
API for generic location services
by Baseflow
codemagic.io 31
Why Geolocator?
Geolocator helps to retrieve the current location of the device comfortably on both
the Android and iOS platforms. You can even generate an approximate address based
on the coordinates of that location or vice versa. It also allows for fetching the last
known location of the device. In addition, this plugin provides an excellent method for
determining the distance between two coordinates.
Developer’s perspective
Geolocator is an essential library for people dealing with GPS or Maps in their app.
This plugin is a perfect fit for the google_maps_flutter library, as it often accepts the
location of a place in the form of coordinates. Being a quite popular and useful library,
it is holding a position in the Flutter Favorite package list.
Pros
+ Location addresses can be easily retrieved from the coordinates
+ Background location access is available
+ Distance between two locations can be measured with ease
+ Addresses can be formatted to the specified locale
Example
codemagic.io 32
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_currentPosition != null
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
‘Latitude: ${_currentPosition?.latitude}’,
style: _style,
),
Text(
‘Longitude: ${_currentPosition?.
longitude}’,
style: _style,
)
],
)
: Container(),
Padding(
codemagic.io 33
codemagic.io 34
Reference links
Package
Documentation
Sample app
codemagic.io 35
codemagic.io 36
6/11
codemagic.io 37
Cached network image helps to load images from a given network URL and
caches them by storing all data in the temporary directory of the app. It uses sqflite for
storing the image file information, which is later used for retrieving the image from
the cache directory if present.
codemagic.io 38
Developer’s perspective
This library is very useful for everyone working with network images in their app.
Most of the well‑known apps use this kind of feature to prevent the annoying loading
screen from being popped up every time by caching commonly used images in the
local storage.
Example
codemagic.io 39
CachedNetworkImage(
imageUrl: ‘https://loremflickr.com/100/100/
music?lock=$index’,
placeholder: (context, url) => Center(
child: CircularProgressIndicator(),
),
errorWidget: (context, url, image) => Center(
child: Icon(Icons.error),
),
),
);
}
}
Reference links
Package
Documentation
Sample app
codemagic.io 40
codemagic.io 41
DATA PERSISTENCE
AND FILE SYSTEM
It is really frustrating for any user of your app if they have to log
in every time or if a theme switches back to the default every time
they come back to it. To prevent these situations from arising, data
persistence and the ability to interact with the device’s file system
should be an essential part of any app.
Flutter has several libraries to help you with that. Let’s take a look at
a lightweight and performant pure Dart library that proves to be an
excellent solution for the local database.
7/11
codemagic.io 42
Hive
Lightweight and blazing fast key-value database
by HiveDB
Hive is a lightweight yet powerful database that is easy to manage and is very
performant on every platform. It is a pure Dart package with no native dependencies,
so it can even run smoothly on Flutter Web.
codemagic.io 43
Why Hive?
Hive works seamlessly on all platforms, including mobile, web and desktop. Data is
stored in the key-value pair format on the Hive Database. It is strongly encrypted
using AES-256 and has a great performance across all the platforms. You can check
out the benchmark .
Hive supports only regular Dart types out of the box, but behind the scenes it works
with binary data. You can define custom types easily using TypeAdapter with the help
of the hive_generator package.
Developer’s perspective
Unless you absolutely need to deal with a lot of relations in your database, Hive being
a pure Dart library is one of the best options out there. If you are not using a heavy-
weight state management library, it is very tedious to manually rebuild the UI every
time a value changes in the database. In that case, you might appreciate the hive_
flutter package that monitors for changes and renders the widgets accordingly.
codemagic.io 44
Example
An example showing how to build a simple Color Generator using the Hive database.
Initializing Hive:
// Initializing Hive
Hive.init(appDocDir.path);
runApp(MyApp());
}
Opening a Hive box for storing the key‑value pairs in the database:
@override
Widget build(BuildContext context) {
codemagic.io 45
UI for showing the ListView of colors and the button for generating random colors:
// ...
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
// TODO: Show the ListView of colors present
// in the Box
codemagic.io 46
child: Container(),
),
// TODO: Show a button for adding colors to the Box
],
);
}
}
codemagic.io 47
ElevatedButton(
onPressed: () {
// Function generating random colors
codemagic.io 48
Reference links
Package
Documentation
Sample app
codemagic.io 49
codemagic.io 50
ANIMATIONS AND
TRANSITIONS
Animations always make your app more attractive and help to
enhance the user experience. But overdoing it may also result in a bad
UX. Let’s take a look at some Flutter packages that can help you add
precisely the right amount of animations to your app.
8/11
codemagic.io 51
Liquid Swipe
Amazing liquid-like swipe
by Sahdeep Singh
Liquid Swipe is a Flutter package that brings the liquid swipe animation to stacked
Container. It adds an interesting liquid animation when swiping between different
pages. This is inspired by Cuberto’s liquid swipe and IntroViews.
“Liquid Swipe was all about learning. The thing that makes
Liquid Swipe great is its growth, from its initial commit to
last, everything was so challenging but fun. Support and
encouragement from the community is also a wonderful
add-on.”
codemagic.io 52
Developer’s perspective
Liquid Swipe package would be quite useful for anyone who wants to add some
kind of out-of-the-box animation to their app. An animation like this is otherwise
quite complex and time‑consuming to design but this package makes it simple to
implement within a matter of minutes.
Example
@override
Widget build(BuildContext context) {
return LiquidSwipe(
pages: pages,
fullTransitionValue: 200,
slideIconWidget: Icon(Icons.arrow_back_ios),
codemagic.io 53
enableLoop: true,
positionSlideIcon: 0.8,
waveType: WaveType.liquidReveal,
);
}
}
Reference links
Package
Documentation
Sample app
codemagic.io 54
codemagic.io 55
UTILITY
Some assortments of important Flutter libraries have caught our
attention. These include libraries that will help you debug your app,
get device information, set up authentication, show advertisements
and other essential utilities for enhancing your app’s functionality.
Highlighting a Flutter library that will help you easily add
internationalization and localization support to your apps
with no tedious setup.
9/11
codemagic.io 56
Easy Localization
Easy and fast internationalization
by Aissat
codemagic.io 57
Developer’s perspective
Though English is widely spoken throughout the world, internationalization is a must
if you are releasing your app for a specific region or want to reach a variety of audiences.
Easy Localization package not only helps with localization, but it also has support for
plural, gender, nesting and RTL locales. It supports extension methods on both Text
and BuildContext widgets for easy translation. It is also reactive to locale changes.
Pros
+ Load translations in any format (JSON, CSV, YAML, XML)
+ Supports plural, gender, nesting, RTL locales
+ Extension methods on Text and BuildContext
+ Built‑in Error widget
+ Code generation for localization files
Example
Add the EasyLocalization widget inside the main function:
codemagic.io 58
languages
supportedLocales: [Locale(‘en’), Locale(‘es’), Locale(‘hi’)],
// Path to the localization files (JSON)
path: ‘assets/translations’,
fallbackLocale: Locale(‘en’),
child: MyApp(),
),
);
}
Then you can easily use this text from the translation file (in this case JSON):
codemagic.io 59
To change the locale, you can use the following with the specific language code:
// Changing to Spanish
context.setLocale(Locale(‘es’));
Reference links
Package
Documentation
Sample app
codemagic.io 60
codemagic.io 61
10/11
codemagic.io 62
Json Serializable
Automatically generate code for JSON
by Dart
Json Serializable provides Dart Build System builders to generate code for converting
to and from JSON by annotating Dart classes. To indicate that a class is serializable you
have to annotate it with @JsonSerializable().
codemagic.io 63
Developer’s perspective
If you are dealing with any kind of JSON data retrieved from an API, structuring the
data using the model class is very important. But that needs a lot of boilerplate code if
it is a large JSON response. You can prevent a huge chunk of this boilerplate using the
JSON Serializable library. It also provides a number of properties that you can apply
to the classes annotated with @JsonSerializable and @JsonKey. Besides setting argu‑
ments on the associated annotation classes, you can also configure code generation by
setting values in build.yaml.
codemagic.io 64
Example
The following is a model class for retrieving applications using Codemagic API:
// application.dart
import ‘package:json_annotation/json_annotation.dart’;
part ‘application.g.dart’;
Application({
required this.id,
required this.appName,
this.iconUrl,
this.lastBuildId,
});
codemagic.io 65
// application.g.dart
part of ‘application.dart’;
Reference links
Package
Documentation
Sample app
codemagic.io 66
codemagic.io 67
TESTING
Testing is a must for every app before it gets into production. It helps
to prevent bugs and logical errors, which may otherwise result in an
unsatisfactory experience for the user. Some Flutter libraries that can
make testing easier and faster are listed below.
A testing framework that makes it easy to test classes that depend on
live web services or databases is discussed in detail.
11/11
codemagic.io 68
Mockito
Mock library for Dart
by Dart
Mockito is a mocking framework written in Dart and inspired by the original Mockito
(available in JAVA). It is useful when it comes to unit testing classes that depend on the
data fetched from live web services or databases.
codemagic.io 69
Why Mockito?
Unit testing classes that depend on dynamic data, i.e. data that can change at any time,
is quite difficult. Testing this kind of dynamic data with respect to static data defined
in your test class may result in an error. Using the Mockito library, you don’t have
to depend on dynamic data anymore and you can test the logic with fewer errors by
mocking the data.
Developer’s perspective
Mockito helps to emulate a live web service or database and return specific results
depending upon the situation. This allows you to run unit tests faster and reliably. Also,
it is quite easy to test all the possible success and failure scenarios using this library.
Pros
+ Prevents errors caused by dynamic data
+ Helps to test all possible scenarios
+ Allows faster test execution
Example
This example shows how to test an API response from a live web service using
Mockito library.
Generate MockClient class using the Mockito package.
// fetch_app_test.dart
import ‘package:flutter_test/flutter_test.dart’;
import ‘package:mockito/annotations.dart’;
import ‘package:mockito/mockito.dart’;
import ‘package:http/http.dart’ as http;
import ‘package:mockito_demo/constants/constants.dart’;
import ‘package:mockito_demo/models/application.dart’;
codemagic.io 70
import ‘package:mockito_demo/secrets.dart’;
import ‘fetch_app_test.mocks.dart’;
// fetch_app_test.dart
@GenerateMocks([http.Client])
main() {
group(‘fetchApplication’, () {
test(‘returns an Application if the HTTP call is
successfully’,
() async {
final client = MockClient();
codemagic.io 71
‘{“application”:{“_id”: “1”,”appName”:”sign_in_
flutter”,”lastBuildId”:”123”}}’,
200,
));
expect(fetchApps(client), throwsException);
});
});
}
Reference links
Package
Documentation
Sample app
codemagic.io 72
codemagic.io 73
Conclusion
We hope that each and every one of you has found something useful from this ebook.
As you can see – there are so many great Flutter libraries! And it’s amazing to see
how you – Flutter enthusiasts and developers – are creating even more highly useful
libraries. Big thank you to all of you!
codemagic.io 74
codemagic.io 75
About Codemagic
Codemagic is a productivity tool for professional developers. The idea is to help
developers to become more successful and support them with a hassle‑free
continuous integration platform, so they could concentrate on building awesome apps
with shorter time and less errors. Join Codemagic community on Slack.
Codemagic offers continuous integration and continuous delivery for Flutter and
mobile app projects, including React Native, native iOS and native Android projects.
Build, test and deliver mobile apps in record time with Codemagic CI/CD!
codemagic.io
codemagic.io 76
THANK YOU!
by Nevercode