Flutter Tutorial for Beginners #11 - Rows

Net Ninja · Beginner ·🛠️ AI Tools & Apps ·6y ago
Skills: UI Design90%

Key Takeaways

Creates a row layout in a Flutter app using the Row widget

Full Transcript

okay then gang so far we've only been adding one widget at a time to the body of our app whether that be a text widget or an image or a button our container or something else and that is a pretty boring so what I'd like to do is now expand our layout so that we can have multiple different widgets on the page at once da da and to do that we're going to be using a combination of row and column widgets now if you've ever used CSS grids or flexbox before this kind of layout might be second nature to you and you're gonna pick it up pretty quickly it's one of the ways in which flutter has kind of borrowed from the web but if not don't worry it's not too hard to grasp after a little bit of practice so anyway a row in itself is a widget and that widget can then contain several different widgets inside it which makes sense because we can have multiple widgets in a row on a screen can't we so let's try adding this row I'm going to get rid of that padding I don't want that anymore and instead I want to replace this with a row widget now since we can have more than one child inside a row we don't have a child property anymore instead we have a children property so we can see the suggestion or right there so I'm gonna press tab to accept that suggestion and we can see that this is now a list and the type of things in that list should be widgets so we're saying now the children property should be a list of widgets and those widgets inside that list other things that will be inside this row that makes sense so if we open this up now I can add different widgets inside this row what I'm gonna do is a text widget first of all that just says like hello world standard and then after that I'm gonna do a flat button and inside the button will do an unprecedent shout at me and we don't have to put anything inside this function for now we'll also do a color and this is going to be colors dots amber will say a nice yellow color and then also we'll do a child property so that we can have a text widget inside that button but this is how we add text inside a button it needs a child property and then a text widget so the text will just say you know click me okay so we've got two widgets now inside this row let's just do a third for good measure by the way notice and commerce separating these widgets inside this list when we looked at lists at the start of the whole series that's what I said you can comma separate different values inside a list it's just like an array in JavaScript anyway I digress the third element or the third widget is going to be a container so inside this container will do a color property first of all to colorize this so I'll say colors and then dots cyan let's go for something different and then we'll also do a padding property just to give this a bit of breathing space inside and this padding property is going to be the edge in sets and we'll choose all so all the way around it's going to have the same value which will be 30 pixels now we want something to show inside this container so I'll do a child property which is also going to be text and then I'll just say inside container in case you didn't already know who okay so now we have these three widgets bunched up together inside this single row and they're all inside this widget list right here so if I save this now then we're gonna see all of these widgets in a single row like this awesome now we have more than one widget on the page at a time so that is progress and they're all inside one row so that's good that's a good first step but notice this they all bunched up on the left side pressed against each other now that's fine maybe that's how you want them to look but you might want to spread these out differently inside the rope so to do that what we could do is use a property on the row and make sure it's on the row itself not inside the children or any other widget inside that on the rule itself we can use a property called main axis alignment so if I use that I can control how these widgets are aligned on the main axis now to explain all this axis thing I prepared a cool little picture which I'm going to show you so imagine we have our row going across like this with three different widgets our main axis is the direction of the row and the cross axis is the perpendicular direction so we have a main axis going across and across axis going downwards so we can control the layout on the main axis and also the cross axis so we're going to do the main one first of all and this is the property we use to control the layout now we have different options here and all those options are on the main axis alignment object so we can see we can use the sensor property space even less space around and space between and start now start is the default one where they're all bunched up to the start next to each other but we could use for example the sensor property now if I say this they're all going to be in the center of the world so that's nicely if you want to centrally align them in the middle we could also use a different property so I'll say dots space between and if I save this you can see now we have space between them but no space on the end of the row on the left or the right but that's good let's try something else I can use start that was the default one a space evenly is still going to space these out a little bit but now we get a bit of space on the left and a right as well and you can see the space between each element or each widget and the sides is the same it's evenly spaced let's do another one so dots end you can probably guess what this is going to do it's going to bunch them up to the right to the end of the row like this so the opposite of start and final it let's look at the other one we've got space around if I save this then we can see we have space around the elements as well and it's a bit like space evenly but notice this time the space here between the widgets is double the space between the widgets and the sides so they're the different things we can use all the different properties we can use on the main axis alignment to align these difference widgets so what I'm going to do is stick where this space evenly for now and save that so it looks something like this and we can also control how they're displayed on the cross axis as well this direction so at the minute they're all kind of in the center this is in the center of the row vertically if you like it's not at the top it's not at the bottom it's in the center but we can control this differently and the way we do that is by using the cross axis alignment property again we use the cross axis alignment object right here we have different properties we have stretch so if I did that and saved then notice they stretch the whole height of the available space we don't want that so let me take that off and choose something different I'm going to choose Center see what that does okay well that was the default value because that's how it looked before well let's choose something else will go with start and if I save this notice now that at the start of the cross axis so at the top if you like and if we do end then you'll probably guess it they're going to be at the end now it's not going to be down here and I'll show you that it's going to be at the bottom of the highest widget so this is the highest widget and this is now going to the bottom of the row which now takes up that height okay and I think what I'll do is I'll just put this to be start for now and save that so they all go to the start so there we go my friends that is rose and how we can add multiple different widgets inside the row so we can see all of those on the screen the next part of the layout puzzle is going to be columns and we're going to look at that in the next video

Original Description

Hey gang, in this Flutter tutorial I'll explain we can start to put more than 1 widget on a page by using rows (the Row widget!). ---------------------------------------- 🐱‍💻 🐱‍💻 Course Links: Course files - https://github.com/iamshaunjp/flutter-beginners-tutorial Android Studio - https://developer.android.com/studio Git - https://git-scm.com/downloads Flutter Installation - https://flutter.dev/docs/get-started/install 🐱‍💻 🐱‍💻 Other Related Courses: + Modern JavaScript Tutorial - https://www.udemy.com/modern-javascript-from-novice-to-ninja/?couponCode=NINJAYT
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 0 of 60

← Previous Next →
1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
52 Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

Related AI Lessons

Up next
How to Open HPL Files (HP-GL Plotter)
File Extension Geeks
Watch →