Flutter Crash Course #9 - Containers

Net Ninja · Beginner ·🛠️ AI Tools & Apps ·2y ago

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 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

This video teaches the basics of the Container widget in Flutter and how to use it to layout content and style text. It covers how to apply margin and padding, override the width and height, and use the TextStyle argument to style text.

Key Takeaways
  1. Create a new Flutter project
  2. Import the necessary libraries
  3. Use the Container widget to wrap other widgets
  4. Apply margin and padding to the Container widget
  5. Override the width and height of the Container widget
  6. Use the TextStyle argument to style text
💡 The Container widget is a versatile widget in Flutter that can be used to layout content and apply styles to text.

Related Reads

Up next
I Tested Every AI Tool for Ranking #1 on Google
Adam Hamdan - ABHMedia
Watch →