Flutter & Firebase App Tutorial — Part 9 loading Spinkit and theme & layout
Create a flutter authenticate app in 10 mins by using firebase as the back-end. You will learn to create a fancy Flutter app and show a loading animation while waiting for Firebase’s response.
More Tutorials:
- Flutter & Firebase App Tutorial — Part 1 Get Started
- Flutter & Firebase App Tutorial — Part 2 App Structure
- Flutter & Firebase App Tutorial — Part 3 Firebase Sign In Anonymously
- Flutter & Firebase App Tutorial — Part 4 Custom model in Flutter App
- Flutter & Firebase App Tutorial — Part 5 Stream & Provider in Flutter
- Flutter & Firebase App Tutorial — Part 6 Firebase Sign Out
- Flutter & Firebase App Tutorial — Part 7 Firebase Sign In and Register With Email
- Flutter & Firebase App Tutorial — Part 8 toggle between forms and form validation
- Flutter & Firebase App Tutorial — Part 9 loading Spinkit and theme & layout
- Flutter Animation Tutorial
- Using SQLite In Flutter
Table of Contents
- Loading
- Theme & Layout
Step 1️⃣: Loading animation
✅ Install a package: flutter_spinkit: ^5.1.0
in the pubspec.yaml
✅ Create a new file called loading.dart
under the folder shared
✅Show the loading Spinkit if it takes a long time to get a response from the Firebase
import 'package:firebase/shared/loading.dart';bool loading = false;return loading ? Loading() : Scaffold();
Step 1.1 Declare a bool property loading
and set its default value as false.
Step 1.2 If loading
is false
, then we show the Scaffold
widget. Whereas, if loading
is true
, then we show the Loading
widget.
Step 1.3 Change the value of the loading
property to true
when clicking the “Sign In” button.
In our Loading
widget, we use SquareCircle
as the loading Spinkit. Visit flutter_spinkit to see more showcases.
Step 2️⃣: Theme and layout
UI is everything for a mobile App. Today I will briefly explain the layout used in the app. You can see more layouts through this link.
➡️ MaterialApp: Using MaterialApp
as the root widget. The MaterialApp
acts as a wrapper for the rest of our app and it lets you design the UI by using a standard Material library.
Material is a visual design language that is standard on mobile and the web. Flutter offers a rich set of Material widgets.
Inside the MaterialApp,
thehome
property specifies the Text
on the Home screen when loading the app.
The
main()
method uses=>
for one-line functions or methods.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Lumei Digital'),
),
body: const Center(
child: Text('Hello World'),
),
),
);
}
}
A widget’s main job is to provide a
build()
method that describes how to display a wedget or a screen.
➡️ Theme:
We use a theme to share colors and fonts throughout an app. If you do not provide a theme, Flutter creates a deafult theme for you.
Other than using the default theme, you can extend the parent theme by using thecopyWith().
Text(
"Sign In",
style: Theme.of(context).textTheme.headline5!.copyWith(fontWeight: FontWeight.bold, color: LumeiColors.primary),
)
After defining a theme, use it within the widget’s build()
methods by using the Theme.of(content)
method.
The Theme.of(context)
method looks up the widget tree and returns the nearest Theme
in the tree. If you have a standalone Theme
defined above your widget, that’s returned. If not, the app’s theme is returned.
➡️ Scaffold: Using Scaffold
widget from the Material library to implement a basic layout such as a appBar
on the top, background color, floating action buttons, and more. It holds the widget tree for the home screen.
all built-in Flutter widgets start with a capital latter
runApp(MaterialApp(
home: Scaffold(
//a appBar property, the value of the property is AppBar widget
appBar: AppBar(),
)));
➡️ Standard widgets:
✅ Stack
: overlaps a widget on top of another. Often it’s used to arrange an image on top of a base widget.
️✅ Container
: allows you to customize its child widget and add padding, margins, borders, background color, other decorations, and more.
✅ ListView
: displays widgets as a scrollable list.
✅ GridView
: displays widgets as a scrollable grid.
Stack(
fit: StackFit.loose,
children : [
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
color: LumeiColors.primary,
child: SvgPicture.asset(
'assets/icons/bg.svg',
fit: BoxFit.cover,
allowDrawingOutsideViewBox: true,
matchTextDirection: true,
),
),
]
);
We use Stack
so we can have an svg as a background image.
The difference between MediaQuery and double.infinity
MediaQuery: It’s used when you want the widget as big as the screen
double.infinity: It’s used when you want the widget as big as the parent widget
➡️ Colors:
Colors are important to your UI.
We add a property to the AppBar
called backgroundColor
and the value of it would be a material design color. We have full access to Material Design color palettes in the flutter app. In this example, we give the AppBar
a blue color with a strength of 600.
ctrl + Q in VS code to see different strength of blue
appBar:AppBar(
backgroundColor: Colors.blue[600]
)
More Tutorials:
- Flutter & Firebase App Tutorial — Part 1 Get Started
- Flutter & Firebase App Tutorial — Part 2 App Structure
- Flutter & Firebase App Tutorial — Part 3 Firebase Sign In Anonymously
- Flutter & Firebase App Tutorial — Part 4 Custom model in Flutter App
- Flutter & Firebase App Tutorial — Part 5 Stream & Provider in Flutter
- Flutter & Firebase App Tutorial — Part 6 Firebase Sign Out
- Flutter & Firebase App Tutorial — Part 7 Firebase Sign In and Register With Email
- Flutter & Firebase App Tutorial — Part 8 toggle between forms and form validation
- Flutter & Firebase App Tutorial — Part 9 loading spinkit and theme & layout
- Flutter Animation Tutorial
- Using SQLite In Flutter
Seeing my followers grow will encourage me to write more articles. If you have any questions or anything to be improved please write a comment in the comments section.
I am a Flutter lover, and I talk about flutter, mobile development, and artificial intelligence.
👉 The source code is updated in Github