Flutter Crash Course #9 - Containers
Skills:
AI Workflow Automation60%
Key Takeaways
This video covers the basics of the Container widget in Flutter, including how to use it to wrap other widgets, apply margin and padding, and override its width and height. It also demonstrates how to style text using the TextStyle argument.
Full Transcript
okay then so now we're in a position where we can start playing with a few different flutter widgets and using them within our application to begin with I want to quickly talk about one of the most basic layout widgets available to us which is the container widget now containers act as wrappers to other content or to other widgets I should say for example we might have this text widget which we can wrap with a container widget but why would we do that well when we use a container we can apply margin and padding to that container very easily which then gives the child text widget in this case some more space around it we can also apply a color to The Container if we wanted to Now by default a container's width and height matches whatever its child's width and height is but we can also override this and specify a different width and height for the container if we want to and when the container doesn't have a child it takes up all of the available space around it by default so these containers are quite flexible anyway that's a container in a nutshell now let's try using one in our code so I'm going to come over here and remove this text widget and instead we'll have a container widget now at the minute this Con gets an error so let's remove that shouldn't be there and now inside the container widget we have a child argument now the child argument would be whatever widget this container wraps so that could be a text widget for example now to begin with I don't want to add a child widget because I want to show you that by default the container takes up the full space available to it on the screen so all I'll do is give this a color instead we'll say color and then we'll use the colors class right here to use material design color which is going to be orange and then a comma remember after every property or argument we have a comma save that and we can see this big container all colored orange taking up all the available room now if we add a child property so I can say child is a text widget that says hello Ninjas like so and we get this blue squiggly line so we know we can add a const right here to optimize this I'm going to save it and notice now it no longer takes up the available space to it it just takes up the space required by the child widget so the same size as this right now if we want to override the width and Heights of the container we can do using width and height properties but just one quick thing if I come under the child and add a property like width for example notice this blue line right here and it says that the child argument should be last in the widget Constructor so again this is just basically not an error it's not going to not work but it wants you to put the child at the bottom all the time it should be the last argument so I'm going to remove that and then come up here put the width here instead so we'll set the width to be I don't know 200 for example pixels and then also we can set a height which is going to be 100 if I save that now notice we get this container which is 200 wide and 100 high so that's how we override the width and height now I'm not actually going to do that I want it to be the same size as the text so let's comment those out and now it goes back to this we can also add padding and margin to do that we can say padding as an argument name and then this is going to be Edge insets Dot and we use a method on this called all so this is how we provide padding and margins by using this Edge insets thing and then one of several different methods on that so when I use the all method it means apply padding to all of the sides equally so I just pass one value in here and then it applies padding to the top right bottom and left together 20 pixels now this is given us a blue squiggly line so just apply const in front of that all right so now if I save this we should see 20 pixels are padding all around the text awesome we can also give this margin so I'll say margin is going to be const and then again Edge insets this time we'll use a different method so we'll try this one right here but before we do that if you want to apply padding or margin to only one side you can use the only method and then a named argument so if we take a look at this only except these different arguments left top right and bottom so if we only want to apply margin to the left we'd say left here and then that would be I don't know 50 and then comma right at the end save this and we can see 50 pixels of margin on the left but nowhere else we're not going to use that what I'm going to you uh do is use this from ltrb so this stands for left top right bottom so they're just positional arguments this time we don't have to name them so I'm going to say 10 pixels on the left 40 pixels at the top to the right zero and then bottom is going to be zero like so save that and now we can see at the top we have 40 pixels to the left we have 10 pixels and no margin elsewhere awesome all right so there's one more thing I'd like to show you in this lesson and that's how we apply text styles to text that we display on the screen so for example we might want to color it differently we might want to give it a different font size different font weight Etc and we can do that by using the style argument right here and the value of that if we hover over this you're going to see is text style so a lot of the time you might not remember what the value of an argument should be just always hover over that argument to find out the value so I know this is text style like so and if we hover over text style we're going to see that we can pass in a bunch of different arguments to stylize the text like color background color font size font weight font style letter spacing Etc all these different things so I'm going to enter down and we're going to just use a few of these different things so then the first one is going to be the font size so we'll say font size like so and if we hover over this then we're going to see that this should be a double so I could just pass in 18 like so all right so letter spacing again it's just going to be a number and I can say four for that we'll say decoration which is the text decoration and if we hover over this you're going to see the type of this is text decoration okay so we know to say text decoration right here and you can see we have these different properties on the text decoration which we can use so let me finish typing this out text decoration and then dots and then I'm going to go with underline like so after that we're going to say font style and the font style if we hover over this we can see the type is font style so font style and then press dots and we can see italic there so we're going to use italic and this is the way we work with flutter applications to provide values like we wouldn't just say here for example a string and then italic instead we use different enom and classes and things like that and use properties and methods on those like this or like this to provide value okay and just remember if you're ever unsure of what a value should be you can't always hover over the argument name and look at what the property value should be all right so let me save this now hopefully we'll see that update over here which we do it now has some space between the letters that's the letter spacing bigger font size it's underline and italic awesome
Original Description
In this Flutter Crash Course tutorial series, you'll learn how to make Flutter applications from scratch.
🥷🏼🔥 Get the Flutter Masterclass Course:
https://netninja.dev/p/flutter-masterclass
💎 Use promo FLUTTERNINJA50 for 50% off!
🥷🏼🔥 Sign up to Net Ninja Pro:
https://netninja.dev/p/net-ninja-pro
📂🥷🏼 Access the course files on GitHub:
https://github.com/iamshaunjp/flutter-masterclass
🔗🥷🏼 Flutter Getting Started Guides - https://docs.flutter.dev/get-started/install
🔗🥷🏼 Install Node.js - https://nodejs.org/en
🔗🥷🏼 VS Code - https://code.visualstudio.com/
🔗🥷🏼 DartPad (Dart sandbox) - https://dartpad.dev/
🔗🥷🏼 Homebrew (for mac) - https://brew.sh/
🔗🥷🏼 Zapp (Flutter sandbox) https://zapp.run/new
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: AI Workflow Automation
View skill →Related Reads
🎓
Tutor Explanation
DeepCamp AI