Flutter Libraries We Love 2
Flutter Libraries We Love 2
3/11
codemagic.io 18
FLUTTER LIBRARIES WE LOVE Text and Fonts
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
FLUTTER LIBRARIES WE LOVE Text and Fonts
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
FLUTTER LIBRARIES WE LOVE Text and Fonts
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
FLUTTER LIBRARIES WE LOVE Text and Fonts
Reference links
Package
Documentation
Wavy Liquid Animation for Text
Sample app
codemagic.io 22
FLUTTER LIBRARIES WE LOVE Text and Fonts
codemagic.io 23
FLUTTER LIBRARIES WE LOVE UX/UI
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
FLUTTER LIBRARIES WE LOVE UX/UI
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
FLUTTER LIBRARIES WE LOVE UX/UI
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
FLUTTER LIBRARIES WE LOVE UX/UI
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
FLUTTER LIBRARIES WE LOVE UX/UI
Reference links
Package
Documentation
VelocityX Tutorials on MTECHVIRAL
Sample app
codemagic.io 28
FLUTTER LIBRARIES WE LOVE UX/UI
codemagic.io 29
FLUTTER LIBRARIES WE LOVE Location and connectivity
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
FLUTTER LIBRARIES WE LOVE Location and connectivity
Geolocator
API for generic location services
by Baseflow
codemagic.io 31
FLUTTER LIBRARIES WE LOVE Location and connectivity
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
FLUTTER LIBRARIES WE LOVE Location and connectivity
@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
FLUTTER LIBRARIES WE LOVE Location and connectivity
codemagic.io 34
FLUTTER LIBRARIES WE LOVE Location and connectivity
Reference links
Package
Documentation
Sample app
codemagic.io 35
FLUTTER LIBRARIES WE LOVE Location and connectivity
codemagic.io 36
FLUTTER LIBRARIES WE LOVE Images and videos
6/11
codemagic.io 37
FLUTTER LIBRARIES WE LOVE Images and videos
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
FLUTTER LIBRARIES WE LOVE Images and videos
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
FLUTTER LIBRARIES WE LOVE Images and videos
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
FLUTTER LIBRARIES WE LOVE Images and videos
codemagic.io 41
FLUTTER LIBRARIES WE LOVE Data persistence and file system
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
FLUTTER LIBRARIES WE LOVE Data persistence and file system
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
FLUTTER LIBRARIES WE LOVE Data persistence and file system
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
FLUTTER LIBRARIES WE LOVE Data persistence and file system
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
FLUTTER LIBRARIES WE LOVE Data persistence and file system
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
FLUTTER LIBRARIES WE LOVE Data persistence and file system
child: Container(),
),
// TODO: Show a button for adding colors to the Box
],
);
}
}
codemagic.io 47
FLUTTER LIBRARIES WE LOVE Data persistence and file system
ElevatedButton(
onPressed: () {
// Function generating random colors
codemagic.io 48
FLUTTER LIBRARIES WE LOVE Data persistence and file system
Reference links
Package
Documentation
Sample app
codemagic.io 49
FLUTTER LIBRARIES WE LOVE Data persistence and file system
codemagic.io 50
FLUTTER LIBRARIES WE LOVE Animations and transitions
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
FLUTTER LIBRARIES WE LOVE Animations and transitions
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
FLUTTER LIBRARIES WE LOVE Animations and transitions
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
FLUTTER LIBRARIES WE LOVE Animations and transitions
enableLoop: true,
positionSlideIcon: 0.8,
waveType: WaveType.liquidReveal,
);
}
}
Reference links
Package
Documentation
Sample app
codemagic.io 54
FLUTTER LIBRARIES WE LOVE Animations and transitions
codemagic.io 55
FLUTTER LIBRARIES WE LOVE Utility
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
FLUTTER LIBRARIES WE LOVE Utility
Easy Localization
Easy and fast internationalization
by Aissat
codemagic.io 57
FLUTTER LIBRARIES WE LOVE Utility
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
FLUTTER LIBRARIES WE LOVE Utility
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
FLUTTER LIBRARIES WE LOVE Utility
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
FLUTTER LIBRARIES WE LOVE Utility
codemagic.io 61
FLUTTER LIBRARIES WE LOVE Code generator and build tools
10/11
codemagic.io 62
FLUTTER LIBRARIES WE LOVE Code generator and build tools
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
FLUTTER LIBRARIES WE LOVE Code generator and build tools
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
FLUTTER LIBRARIES WE LOVE Code generator and build tools
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
FLUTTER LIBRARIES WE LOVE Code generator and build tools
// application.g.dart
part of ‘application.dart’;
Reference links
Package
Documentation
Sample app
codemagic.io 66
FLUTTER LIBRARIES WE LOVE Code generator and build tools
codemagic.io 67
FLUTTER LIBRARIES WE LOVE Testing
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
FLUTTER LIBRARIES WE LOVE Testing
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
FLUTTER LIBRARIES WE LOVE Testing
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
FLUTTER LIBRARIES WE LOVE Testing
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
FLUTTER LIBRARIES WE LOVE Testing
‘{“application”:{“_id”: “1”,”appName”:”sign_in_
flutter”,”lastBuildId”:”123”}}’,
200,
));
expect(fetchApps(client), throwsException);
});
});
}
Reference links
Package
Documentation
Sample app
codemagic.io 72
FLUTTER LIBRARIES WE LOVE Testing
codemagic.io 73
FLUTTER LIBRARIES WE LOVE
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