Building A Flutter Project An Understanding The Terms
Building A Flutter Project An Understanding The Terms
Building A Flutter Project An Understanding The Terms
First the project is developed in visual studio code hitting ctrl+shift+p or cmd+shift+p and giving
it a name.
Android - where Android-related files are stored. If you’ve done any sort of cross-
platform mobile app development before, this, along with the IOS folder should be pretty
familiar.
Ios - where IOS-related files are stored.
lib - this is where you’ll be working on most of the time. By default, it contains
a main.dart file, this is the entry point file of the Flutter app.
test - this is where you put the unit testing code for the app. We won’t really be
working on it in this tutorial.
pubspec.yaml - this file defines the version and build number of your app. It’s also
where you define your dependencies. If you’re coming from a web development
background, this file has the same job description as the package.json file so you can
define the external packages (from the Dart packages website) you want to use in here.
Defining assets
The images, fonts and icons are stored here.
//../pubspec.yaml
name: flutter_login_ui
description: A new Flutter project.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- logo.png
fonts:
- family: Montserrat
fonts:
- asset: fonts/Montserrat-Regular.ttf
Creating an assets and fonts directories into the root of your Flutter project. we should
respectively find their content and add a picture.png to our ../assets folder and th fonts.ttf font to
our ../fonts folder.
Build the UI
First, we import the Material library from Flutter:
import 'package:flutter/material.dart';
Among those are the MaterialApp, Scaffold, and AppBar widgets using inside our app. The
methods that using are either part of a library you’ve imported, or part of the Flutter framework
itself.
Note that almost everything in Flutter is a widget, and each one can have its own set of
properties and child widgets. We have two main types of widget in Flutter:
Stateful widget: manages its own internal state and keeps track of it.
Stateless widget: while this kind of widget doesn’t. For example a button doesn’t
need to track of anything.
Then we define our MyApp widget. Amend your MyApp class like the following (only change the
title property) :
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter login UI',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Login'),
);
}
}
The code above returns a new MaterialApp widget defining our app title, our app theme, and our
home page. As you can notice, it is a stateless widget. To create a stateless widget, you need to
extend the StatelessWidget class like the following:
class MyApp extends StatelessWidget {
// ...
}
Now defineing our home widget, this time it is a stateful widget, this means it will contain fields
that affect how it looks. No change here!
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(36.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 155.0,
child: Image.asset(
"assets/logo.png",
fit: BoxFit.contain,
),
),
SizedBox(height: 45.0),
emailField,
SizedBox(height: 25.0),
passwordField,
SizedBox(
height: 35.0,
),
loginButon,
SizedBox(
height: 15.0,
),
],
),
),
),
),
);
}
}
Once everything is done, the app should already be functional. If you don’t already have the app
running, launch an Android emulator or iOS simulator instance and execute the following
command from the root of the project directory:
flutter run
[ CITATION Flu19 \l 1033 ]