Flutter Basic Training - 12 Minute Bootcamp

Fireship
16 Nov 202112:08

Summary

TLDRThis video script offers an introduction to Flutter, a popular cross-platform framework for developing high-quality apps across iOS, Android, the web, and desktop. The training covers essential concepts such as UI building blocks, layout, state management, and navigation. It also highlights productivity tips, like code refactoring shortcuts, and introduces advanced features like the Hero widget for animated transitions. The script is designed to transform viewers into productive full-stack Flutter developers, with a certificate of completion and an invitation to a more in-depth course for further learning.

Takeaways

  • πŸš€ Flutter is becoming the world's most popular cross-platform framework due to its developer experience and ability to ship high-quality apps on multiple platforms.
  • πŸ› οΈ Flutter has a steeper learning curve, and to master it, one should focus on building projects rather than just watching tutorials.
  • πŸ“š The instructor provides satisfying examples to make learners productive full stack Flutter developers.
  • πŸ”‘ Refactoring code in Flutter is much faster using shortcuts like 'control period' compared to manual editing.
  • πŸ›‘ Productivity boosters and hot reload features are highlighted as key to efficient Flutter development.
  • πŸ“ The script emphasizes the importance of following directions and using resources like flutter.dev for installation instructions.
  • πŸ” DartPad is introduced as a tool for editing and running Flutter code directly in the browser.
  • πŸ—οΈ The basics of creating a Flutter app involve using the 'Material App' as the root widget and 'Scaffold' for building screens with common UI elements.
  • 🎨 Layout in Flutter is managed using widgets like 'Container', 'Center', 'Row', 'Column', and 'Stack', with explanations on how to use them effectively.
  • πŸ”„ The concept of state in Flutter is introduced, explaining the difference between 'Stateless' and 'Stateful' widgets and how to manage mutable data.
  • πŸ”„ 'setState' is used in stateful widgets to update the UI in response to user interactions or data changes.
  • 🌐 Navigation in Flutter is achieved using the Navigator 1.0, with 'push' and 'pop' methods to manage screen transitions.
  • πŸŽ‰ The 'Hero' widget in Flutter is showcased for creating animated transitions between screens, enhancing user experience.

Q & A

  • What is the primary goal of the Flutter Basic Training video?

    -The primary goal of the Flutter Basic Training video is to teach viewers how to develop and ship high-quality apps on multiple platforms such as iOS, Android, the web, and desktop using Flutter, which is a cross-platform framework.

  • Why is Flutter becoming popular among developers?

    -Flutter is becoming popular due to its excellent developer experience and its ability to create high-quality apps that can be deployed on multiple platforms, making it a unique and powerful tool in the market.

  • What are some productivity boosters mentioned in the video for Flutter development?

    -The video mentions several productivity boosters such as using the 'control period' shortcut for refactoring code, leveraging the IDE's auto-completion features, and using hot reload for instant UI updates without a full rebuild.

  • What is the importance of the 'runApp' function in Flutter?

    -The 'runApp' function is a global function in Flutter that is used to start the execution of the program. It takes a single widget as an argument and inflates that widget to the screen on the device it is running on.

  • How does Flutter handle UI updates when data changes?

    -Flutter uses the 'build' method in widgets to handle UI updates when data changes. This method returns a widget and is called anytime Flutter needs to rebuild the UI, such as when the underlying data changes.

  • What is the purpose of the 'Material App' widget in Flutter?

    -The 'Material App' widget serves as the root of the application in Flutter. It allows developers to configure themes, routes, and other properties that are consistent across the entire app.

  • What is the difference between a 'StatelessWidget' and a 'StatefulWidget' in Flutter?

    -A 'StatelessWidget' in Flutter is used when creating a UI element that does not have any internal data and does not change. In contrast, a 'StatefulWidget' is used when the widget needs to have mutable data or state that can change over time.

  • How can developers navigate to a different screen in Flutter?

    -Developers can navigate to a different screen in Flutter by using the 'Navigator' class and calling the 'push' method with a 'MaterialPageRoute' that includes a builder function returning the new screen.

  • What is the 'Hero' widget used for in Flutter, and how does it enhance the user experience?

    -The 'Hero' widget in Flutter is used to create an animated transition between two screens, making it look like an element is moving from one screen to another. This enhances the user experience by providing a smooth and visually appealing transition.

  • What is the significance of using a 'ListView' widget in Flutter when dealing with overflow?

    -The 'ListView' widget in Flutter is significant when dealing with overflow because it allows the UI to scroll, both horizontally and vertically, and can even perform lazy loading and garbage collection of off-screen items, keeping the UI smooth and efficient.

  • How can developers create dynamic UI elements in Flutter based on data?

    -Developers can create dynamic UI elements in Flutter using 'builders', which are functions that map a list of data to a list of widgets. This allows for the creation of scrollable lists that can be infinitely long, with children rendered lazily as needed.

Outlines

00:00

πŸš€ Flutter Basics and Productivity Tips

This paragraph introduces the viewer to Flutter, a popular cross-platform framework for developing high-quality apps on multiple platforms. It emphasizes the framework's rapid rise in popularity due to its developer-friendly experience and the need for hands-on learning to master it. The instructor promises to guide the viewer through practical examples to become a proficient Flutter developer. It also highlights the importance of utilizing IDE tooling and productivity shortcuts, such as code refactoring with 'control period', and offers a certificate upon completion of basic training. For those looking to advance, a new Flutter course for Pro members is mentioned, along with a discount for the viewer. The paragraph concludes with instructions on setting up the Flutter development environment and creating a new project.

05:01

πŸ›  Understanding Flutter's Layout and UI Components

The second paragraph delves into the intricacies of Flutter's layout system, starting with the fundamental 'Container' widget, which is analogous to HTML's 'div' or Android's 'View'. It explains how to manipulate the layout properties like margin, padding, height, width, and decoration. The paragraph then introduces 'Row' and 'Column' for arranging widgets in a linear fashion, either horizontally or vertically, and discusses the concepts of 'main axis' and 'cross axis'. It also covers the use of 'Expanded' and 'Flexible' widgets to control the distribution of space among children. The paragraph further explores advanced layout widgets like 'Stack' for overlapping elements and 'Positioned' for precise placement. It touches on the importance of code formatting and the use of Flutter's built-in widgets for common UI elements, such as 'FloatingActionButton', 'BottomNavigationBar', and 'Drawer'. The discussion on layout concludes with the use of 'ListView' for scrollable content and dynamic widget creation with builders.

10:02

πŸ”„ State Management and Navigation in Flutter

This paragraph focuses on state management and navigation within Flutter apps. It begins by explaining the difference between 'StatelessWidget' and 'StatefulWidget', and how to convert a StatelessWidget to a StatefulWidget for mutable data. The paragraph details the use of 'setState' to update UI elements in response to user interactions and the importance of lifecycle methods like 'initState' and 'dispose'. It also discusses various approaches to state management, including the use of the 'provider' package for real-time data sharing and mentions other solutions like 'Bloc' and 'Cubit'. The paragraph then moves on to navigation, explaining how to use Flutter's Navigator 1.0 to push and pop screens onto a stack, and introduces the concept of 'Hero' animations for seamless transitions between screens. The summary concludes with a congratulatory note for completing the basic training and an invitation to join the full course for advanced Flutter development with Firebase.

Mindmap

Keywords

πŸ’‘Flutter

Flutter is an open-source UI software development kit created by Google, used for developing cross-platform applications. It allows developers to compile code written in Dart into native applications for iOS, Android, Windows, macOS, and the web. In the video, Flutter is presented as the main focus, being the framework that enables the development of high-quality apps across multiple platforms.

πŸ’‘Cross-platform framework

A cross-platform framework is a software tool that allows developers to write code once and deploy it across multiple platforms. In the context of the video, Flutter is highlighted as a popular cross-platform framework due to its ability to ship apps on iOS, Android, the web, and desktop, which is a key selling point for developers looking to reach a wide audience with a single codebase.

πŸ’‘Developer experience

Developer experience, often abbreviated as DX, refers to the overall experience of a programmer while using a particular tool or framework. The video emphasizes Flutter's 'awesome developer experience' as one of the reasons for its growing popularity, suggesting that it is user-friendly and efficient for developers to work with.

πŸ’‘Productivity boosters

Productivity boosters are features or techniques that increase the efficiency and speed of development work. The script mentions several productivity boosters in Flutter, such as the ability to refactor code quickly using keyboard shortcuts, which are essential for developers to maximize their output and minimize manual coding efforts.

πŸ’‘Hot reload

Hot reload is a feature in Flutter that allows developers to see the changes they make in the code instantly reflected in the app without needing to restart the app. The video script describes how hot reload can be performed by typing a lowercase 'r' in the terminal, which is a significant productivity feature for developers to quickly iterate on their UI changes.

πŸ’‘Widgets

In Flutter, a widget is the basic building block of the UI. Widgets can be simple or complex, and they are used to construct the user interface. The script explains how Flutter provides hundreds of pre-built widgets that developers can combine to create a complex UI, ranging from basic elements like 'Text' to more complex ones like 'PageView'.

πŸ’‘Layout

Layout in Flutter refers to the arrangement and organization of widgets on the screen. The video script discusses various layout widgets such as 'Container', 'Center', 'Row', 'Column', and 'Stack', which are used to position and align widgets in different ways, essential for creating a visually appealing and functional user interface.

πŸ’‘State

State in Flutter refers to the mutable data that can change during the lifecycle of an app. The script introduces the concept of 'Stateless' and 'Stateful' widgets, where 'StatelessWidget' is used for UI elements that do not change, while 'StatefulWidget' allows for mutable data and UI changes over time, such as a counter app that updates as buttons are pressed.

πŸ’‘Navigator

Navigator in Flutter is a core widget for handling navigation between pages in an app. The video script explains the use of 'Navigator 1.0' for basic training, where screens are pushed onto a stack and popped off to navigate between pages, demonstrating how to move between different screens in a Flutter app.

πŸ’‘Hero widget

The Hero widget in Flutter is used for creating a hero animation that transitions an element from one screen to another, providing a smooth and visually appealing experience. The script illustrates this by showing how an image can be animated between two screens, making it appear as if it transitions seamlessly as the user navigates.

πŸ’‘State management

State management in Flutter refers to the strategies and techniques used to handle the state of an application. The video script briefly touches on this by mentioning different approaches to state management, including the use of the 'setState' function for simple state changes and the mention of packages like 'Provider' for more complex state management solutions.

Highlights

Flutter is becoming the world's most popular cross-platform framework due to its developer experience and ability to ship high-quality apps on multiple platforms.

The learning curve for Flutter is steep, requiring hands-on building rather than passive learning.

Productivity boosters like code refactoring shortcuts are essential for efficient Flutter development.

A certificate of completion is provided for the Flutter basic training.

For advanced learning, a new Flutter course is available for pro members on Fireship.io with an ephemeral discount.

Flutter development requires following installation instructions on flutter.dev or using Dartpad for an easier start.

VS Code with the Flutter extension is essential for Flutter development, enabling hot reload for instant UI updates.

Auto-completion in the IDE is crucial for productivity in Flutter development.

Flutter's material package provides access to pre-built widgets for UI construction.

Understanding the widget tree structure is fundamental for combining widgets in Flutter.

The 'runApp' function is central to starting Flutter applications, taking a single widget as an argument.

Stateless widgets in Flutter are used for UI elements without internal data, making them immutable.

The 'build' method in Flutter is key for returning a widget and is called whenever the UI needs to be rebuilt.

Layout in Flutter can be managed using fundamental widgets like Container, Center, and Flex (Row and Column).

Advanced layout widgets like Stack and Positioned allow for overlapping and precise positioning of widgets.

Flutter's built-in widgets like Scaffold, AppBar, and BottomBar simplify common UI element implementations.

Handling UI overflow requires using scrollable widgets like ListView to enable scrolling.

Dynamic UI creation in Flutter is facilitated by builders, allowing for the programmatic generation of widgets from data.

State management in Flutter involves converting a Stateless Widget to a Stateful Widget for mutable data.

The 'setState' function in Stateful Widgets is used to mutate data and trigger UI re-rendering.

Flutter's navigation involves pushing and popping screens onto a stack using Navigator 1.0.

The Hero widget in Flutter enables animated transitions of elements between screens.

Upon completion of basic training, participants are encouraged to take a screenshot of their certificate.

For comprehensive learning, joining as a pro member on Fireship.io provides access to the full Flutter 2 course.

Transcripts

play00:00

welcome to flutter basic training by the

play00:02

end of this video you'll be shipping

play00:03

apps on ios android the web and desktop

play00:06

you will not laugh you will not cry you

play00:09

will learn by the numbers i will teach

play00:11

you flutter is quickly becoming the

play00:12

world's most popular cross-platform

play00:14

framework thanks to its awesome

play00:15

developer experience and ability to ship

play00:17

high quality apps on multiple platforms

play00:19

it's unlike anything else out there

play00:21

which also means that it has a steeper

play00:23

learning curve to get good at it you'll

play00:24

need to stop watching youtube and start

play00:26

building something i created a bunch of

play00:28

satisfying examples that will go through

play00:30

together designed to make you a

play00:32

productive full stack flutter developer

play00:34

there are certain things they don't tell

play00:35

you when you first get started like it's

play00:37

100 times faster to refactor your code

play00:39

by hitting control period than it is to

play00:40

do manually we'll look at a ton of

play00:42

productivity boosters like this and at

play00:43

the end of basic training i'll give you

play00:45

a certificate that you can frame on your

play00:47

wall and if you want to go beyond the

play00:48

basics i just released a brand new

play00:50

flutter course available to pro members

play00:52

on fireship io there's an ephemeral

play00:54

discount in the video description to get

play00:56

started you'll need to use the most

play00:57

important skill for any developer

play00:59

following directions head over to

play01:01

flutter.dev and follow the install

play01:03

instructions for your system or if you

play01:05

want an easier way to get started

play01:06

dartpad allows you to edit and run

play01:08

flutter code in the browser now open the

play01:10

terminal and create a new project by

play01:12

running flutter create now open it in vs

play01:14

code and make sure to have the flutter

play01:16

extension installed at the bottom you'll

play01:18

see an option to select a device like

play01:20

windows chrome or a mobile emulator i'm

play01:22

going to run my app and android by

play01:24

running flutter run from the command

play01:25

line now find your application code in

play01:27

the main dart file read in between the

play01:29

lines to find a color or icon in your ui

play01:32

change one of these values to something

play01:34

else you'll notice that when you type

play01:35

after the period everything is

play01:37

auto-completed in the ide tooling is

play01:39

partly what makes flutter development so

play01:41

productive if you don't leverage it you

play01:43

are not going to survive basic training

play01:45

if you survive recruit training it will

play01:47

be a weapon save the file now type a

play01:50

lowercase r into the terminal that

play01:52

performs a hot reload allowing you to

play01:54

instantly see the changes in the ui

play01:56

without having to rebuild the entire app

play01:58

now take all the code in this file and

play02:00

delete it we're going to start from

play02:01

scratch first import the flutter

play02:03

material package at the top this gives

play02:06

you access to hundreds of pre-built

play02:07

widgets in your code ranging from

play02:09

low-level building blocks like text to

play02:11

complex ui elements like a page view

play02:14

that performs animation and layout as a

play02:16

flutter developer you'll need to learn

play02:18

how to combine these widgets together

play02:20

into a tree-like structure to create a

play02:22

complex ui but first we need a main

play02:25

function this is where the program will

play02:26

start executing flutter has a global

play02:28

function called run app it takes a

play02:30

single widget as its argument and will

play02:32

inflate that widget to the screen on

play02:34

whatever device it happens to be running

play02:35

on let's create a custom widget to

play02:37

represent the application type st into

play02:40

your editor and it should automatically

play02:42

give you a snippet for a flutter

play02:44

stateless widget hit tab to insert it

play02:46

then give it a name like my app notice

play02:48

how this class extends a stateless

play02:51

widget that's a class built into flutter

play02:53

that you use when creating a ui element

play02:55

that doesn't have any internal data in

play02:57

other words it's just a dumb widget that

play02:59

paints some pixels to the screen you'll

play03:01

notice it has a constructor with a key

play03:03

you don't need to worry about that for

play03:04

right now but if you hover over it

play03:06

you'll notice that it has a link to a

play03:07

youtube video explaining more because

play03:09

flutter's documentation is absolutely

play03:11

awesome the thing you do need to know

play03:12

about is the build method this method

play03:14

returns a widget and will be called

play03:16

anytime flutter needs to rebuild the ui

play03:19

like when your data changes the first

play03:20

widget we'll return is a material app

play03:23

it's used as the root of the application

play03:25

and allows us to configure themes and

play03:27

routes perform a hot reload and you

play03:29

should have a blank canvas to work with

play03:30

we can quickly add a screen to it by

play03:32

adding a scaffold to the home property a

play03:35

scaffold allows you to build screens

play03:36

with common ui elements like an app bar

play03:39

at the top every pre-built widget has a

play03:41

bunch of name parameters where you can

play03:42

customize its appearance put your cursor

play03:44

inside a widget then hit ctrl spacebar

play03:47

to bring up all the options go ahead and

play03:48

add a background color then add a title

play03:51

by creating a text widget now hot reload

play03:53

to check out your first flutter screen

play03:55

that's pretty cool but there's no time

play03:57

to celebrate now we need to talk about

play03:58

layout or how do i put widgets where

play04:00

they need to go in the screen the most

play04:02

fundamental way to layout a widget is

play04:04

with a container it's kind of like a div

play04:06

in html or a view in android it takes

play04:08

one child widget as an argument we can

play04:10

make that a text widget for now which

play04:12

will place it in the top left corner of

play04:14

the screen you can think of it being

play04:15

surrounded by a box and we can change

play04:17

the dimensions of that box by adding

play04:19

margin and padding we can also customize

play04:22

things like the height width and color

play04:24

we can also make the box look a lot

play04:25

cooler using the decoration property it

play04:28

takes a box decoration widget as its

play04:30

argument which allows us to customize

play04:32

things like the border gradient shape

play04:34

and shadow of the box containers do a

play04:37

lot but flutter has some other widgets

play04:38

that are more focused for example if you

play04:41

just want to center a widget in the

play04:42

middle of the screen you can do so by

play04:44

wrapping it with center now you could

play04:46

write that code manually but if you want

play04:47

to have a good time you'll right-click

play04:49

on the widget or hit control period to

play04:51

find the refactor tool then select the

play04:53

option to wrap with center to write that

play04:55

code for you automatically another tip

play04:57

is that if you're using a container to

play04:59

apply some padding use the padding

play05:01

widget instead or if you're creating a

play05:02

container with a fixed width and height

play05:04

use the size box widget instead but how

play05:07

do we deal with multiple related widgets

play05:08

like a row or column that's where flex

play05:11

layout comes in if you're familiar with

play05:12

css flexbox you'll be way ahead of the

play05:14

game here flutter provides row and

play05:16

column widgets used to layout multiple

play05:18

children horizontally or vertically

play05:21

unlike a container that takes only one

play05:22

widget as a child a column takes

play05:24

multiple children as a list create a

play05:27

column then add three icons inside of it

play05:29

you'll notice that each icon is laid out

play05:31

one after the other vertically change

play05:33

that widget to a row and now they flow

play05:35

horizontally the direction they flow is

play05:37

called the main axis while the opposite

play05:39

direction is the cross axis you can

play05:41

change the spacing and alignment between

play05:43

the children by modifying the cross axis

play05:46

and main axis alignment on the widget by

play05:48

default each child has a flex value of 1

play05:51

which means that each sibling occupies

play05:53

the same amount of space if that's not

play05:55

desirable you can wrap a child in a

play05:57

flexible or expanded widget expanded

play05:59

tells a child to take up any available

play06:01

space and you can give it more space

play06:03

than the other children by modifying its

play06:05

flex value but in some cases you may

play06:07

want to have one widget overlap another

play06:10

like a button that floats on top of some

play06:12

other ui element in that case the widget

play06:14

we're looking for is a stack just like a

play06:16

rower column it takes a list of children

play06:19

as an argument and just one little side

play06:20

note here you'll notice that i'm using a

play06:22

trailing comma after every block of code

play06:25

the comma is not required but it keeps

play06:26

your code nicely formatted if you

play06:28

right-click and choose format document

play06:30

it will format it with multiple lines as

play06:32

opposed to one line when the comma is

play06:34

missing now in our stack we might have a

play06:36

container and an icon if we want to

play06:38

display the icon on top of the container

play06:40

we make sure that it comes after the

play06:41

container in the list now if we want to

play06:43

move things around we can use positioned

play06:45

to move a widget into a specific spot

play06:47

kind of like absolute positioning in css

play06:50

or if we want to modify its positioning

play06:52

relative to its parent we can use a line

play06:54

to move it to the top left bottom right

play06:56

or center those are your low-level

play06:57

building blocks for layout but flutter

play06:59

takes care of many ui elements out of

play07:00

the box for example if we add a floating

play07:03

action button to our scaffold that

play07:05

button magically appears down here at

play07:06

the bottom right the floating action

play07:08

button widget has an event handler

play07:10

called on pressed we can define an

play07:12

anonymous function here to handle the

play07:13

gesture if we then want to add a bottom

play07:16

bar to it we can use the bottom bar

play07:18

widget to add some navigation icons to

play07:20

the scaffold we also need a drawer that

play07:22

animates out from the left we can

play07:23

achieve that by simply adding a drawer

play07:25

to the scaffold that's pretty awesome

play07:27

but eventually you'll lay out your

play07:28

widgets and they will overflow the

play07:30

bounds of their parent which will summon

play07:32

the red screen of death or this black

play07:33

and yellow error tape when you get an

play07:35

error like this the terminal output will

play07:37

link you to flutter's built-in debugger

play07:39

that'll give you more information about

play07:40

layout to help debug things like this in

play07:42

this case the problem is that our parent

play07:44

is not a scrollable view things don't

play07:46

just scroll automatically instead you

play07:48

need to use a widget like list view it

play07:50

takes a list of children as its argument

play07:52

but will scroll between them it can

play07:54

scroll both horizontally and vertically

play07:56

and you can even tell it to garbage

play07:58

collect items that are no longer on the

play07:59

screen you'll notice that in this list

play08:01

we're adding each widget individually

play08:03

but in real life you'll often need to

play08:04

fetch a bunch of items from a database

play08:06

and then create each list item

play08:08

programmatically in flutter many widgets

play08:10

can be built dynamically using builders

play08:12

which is just a function that you define

play08:14

that can map a list of data to a list of

play08:16

widgets and that means you can create a

play08:18

scrollable list that is infinitely long

play08:20

where the children are rendered lazily

play08:22

keeping the ui smooth and fast now that

play08:24

you know how to build a ui we need to

play08:26

talk about state or the data that

play08:28

changes throughout the life cycle of the

play08:30

app a stateless widget has no state as

play08:32

the name implies to give this widget

play08:34

mutable data we need to convert it to a

play08:36

stateful widget which we can do by

play08:38

right-clicking going to the refactor

play08:40

tool and choosing the option to convert

play08:42

it that will break the widget up into

play08:44

two different classes that keeps the

play08:45

widget itself immutable while giving us

play08:47

a state class where we can play with

play08:49

mutable data it has a build method but

play08:51

we can also define variables on this

play08:53

class

play08:54

and then change them by using the

play08:56

built-in set state function somewhere

play08:58

else in our code like when a button is

play09:00

pressed we can create a counter app by

play09:02

defining a property called count then

play09:04

reference the value in the ui using a

play09:06

text widget when working with strings in

play09:07

dart you can interpolate a variable

play09:09

inside of it with a dollar sign now when

play09:11

our button is pressed we call setstate

play09:13

to change the value and the widget will

play09:15

automatically re-render to reflect the

play09:17

latest data another thing you might want

play09:19

to do in a stateful widget is initialize

play09:21

data like maybe fetch a record from a

play09:22

database the init state method is called

play09:24

once when the widget is first

play09:26

initialized and there's also another

play09:28

lifecycle hook called dispose that runs

play09:30

when the widget is removed from the ui

play09:32

now you should know that this is not the

play09:34

only way to manage state and flutter in

play09:36

fact there are many different approaches

play09:38

and many strong opinions out there about

play09:39

this topic in my full course i use a

play09:41

package called provider that allows us

play09:43

to share real-time data throughout the

play09:45

entire widget tree without ever needing

play09:47

to use a stateful widget at all there

play09:49

are also full-blown solutions out there

play09:51

like block and qubit the full course

play09:53

also contains a repo of the same app

play09:55

built with qubit i want to give a shout

play09:57

out to raleigh perez for putting that

play09:58

demo together if you're looking to hire

play10:00

a flutter developer you'll definitely

play10:01

want to get in touch with him now that

play10:03

we have a fully functional counter app

play10:05

the question becomes how do we navigate

play10:06

to a different screen well confusingly

play10:09

flutter has navigator 1.0 and 2.0 and

play10:11

all you need to know for basic training

play10:13

is 1.0 at this point go ahead and build

play10:15

two different stateless widgets then

play10:17

give each one of them a scaffold make

play10:19

sure that each scaffold has an app bar

play10:21

at the top in the first page go ahead

play10:23

and add a button to the body of the

play10:24

scaffold now think of your navigation

play10:26

like a stack where you can push and pop

play10:29

different screens onto it to add a new

play10:31

screen to the top of the stack we use

play10:32

navigator push with the build context

play10:35

then create a new material page route

play10:37

the route expects a builder function

play10:39

which then returns the screen that you

play10:41

want to render which in our case will be

play10:43

page 2. now do a full restart of the

play10:45

application by typing a capital r into

play10:47

the command line and you should be able

play10:49

to navigate back and forth between the

play10:50

two pages one magic thing that flutter

play10:52

is doing here is adding a back button to

play10:54

the app bar which under the hood is

play10:56

calling the navigator pop method that

play10:59

was easy but i want to finish things off

play11:01

with something really cool flutter has a

play11:02

hero widget that can animate elements

play11:04

from one screen to another so check this

play11:07

out on page 1 i have an icon button with

play11:09

an image as the background then on page

play11:11

2 i'm showing the same image taking up

play11:13

the full screen that works but i think

play11:15

we could do a little better the magic

play11:16

comes into play when i wrap these images

play11:18

in a hero the only argument the hero

play11:20

needs is an id to identify it when it

play11:22

gets animated to the other page flutter

play11:24

will use the id to keep the image in the

play11:26

ui on both pages while the navigation is

play11:29

taking place now on the other screen

play11:31

we'll also use a hero widget with the

play11:33

image inside of it when we navigate to

play11:35

this route you'll notice the image

play11:36

itself is animated between the two

play11:38

screens automatically it makes the

play11:40

biggest impact when you have a list of

play11:42

images to navigate to not only does it

play11:44

look awesome but it would be extremely

play11:45

difficult to implement from scratch

play11:47

congratulations you just completed basic

play11:49

training for flutter take a screenshot

play11:51

of the certificate and frame it on your

play11:53

wall if you want to go beyond the basics

play11:55

become a pro member at fireship io to

play11:57

get access to the full flutter 2 course

play12:00

where we build a complex application

play12:02

with firebase thanks for watching and i

play12:04

will see you in the next one

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Flutter TrainingCross-PlatformUI DevelopmentApp BuildingMobile AppsWeb AppsDesktop AppsDeveloper ToolsProductivity TipsCoding TutorialFlutter UI