Flutter Tutorial for Beginners #9 - Buttons & Icons

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

Key Takeaways

Builds a Flutter app using the Scaffold and AppBar widgets

Full Transcript

or rather than gang so in this video I'd like to show you how to use icons and buttons and then a mixture of the two as well so I'm right here in the center widget now and I've stripped out the images from the last video and we have this child property we need to specify a widget for the child and what we're going to do is look at icons first and to do that we'll use the icon widget that's simple so let's open this up and the first item inside this icon widget is going to be what icon we actually want to use now we can use any icons from the material design library and to access those and to see them we say icons and then dots and then we can see all of the different icons available to us right here the name of them and a sync preview of how they look as well the one I'm going to use is called airport underscore shuttle which is like a little boss so that's all I need to do that's the first parameter and if I save this now then you should see that little icon right there in the center now we can customize this a little bit if we want to so I could give this a color by saying color and then that's going to be equal to colors dots light blue for example if I save it again then now this is going to be a light blue now that's tiny in a minute so if I wanted to increase the size I could give it a size property and so 250 for example and save that and now it's a bit bigger okay so that's it that's an icon that's how simple it is we just use the icon widget the first argument is going to be the actual icon we want to use then we have these other different properties as well and again if you select one of these widgets and press ctrl Q while it's selected you can see all of the different properties we can use inside the icon widget okay so we've seen an icon now let's have a look at buttons so there's a couple of different type of buttons first of all I'll show you the raised button and by raised I mean that it sits away from the page so we should have some kind of shadow and inside this button first of all we're going to do an on pressed property because if we don't have that then flutter is going to shout us because buttons are there to be pressed and this is a acquired property so impressed is gonna equal two and then all of us function for now meaning that it doesn't have a name and we might come to that in a minute and I'll show you what can happen when we press a button but for now let's just leave it blank now what else do we want inside this button well we can specify text inside a child property so remember when we're nesting a widget inside a widget we use this child property a lot of the time now we want text inside this raised button widget so we're going to use the child property and then nest a text widget inside it alright so whatever we type in this text widget is going to appear on the button so I'll just say click me like so and I'm going to save that now and we should see a button now that says click me awesome now if we wanted to we could open this up and we could you know do a textile as well to style a text inside the button I'm not going to do that I'm going to leave it as this for now keep it nice and simple but what it will do is add on any color property to this button and I'm gonna say colors and then let's just use light blue again you can choose whatever color you want save that and it says click me and if you look really closely by the way you can see that this is a raised button because it has a little shadow it's raising it away from the page giving it that kind of 3d effect so that's a raised button just as easily we can do a flat's button so I can say flat button and then save this and then now it's going to take away that shadow so that's the major difference there one of them has a shadow that's the raised button one of them doesn't ok so I said I'd come back to this on pressed property right here so this on pressed property takes a function as a value and inside the function this is code that we can execute when someone presses this button so for example I could do something like print a statement to the console and I'll just say you flicked me okay so now if anyone ever clicks this button then is going to fire this function and print this to the console now I'm gonna save it and I'm also going to open up this run tab down here and I'm gonna go to click me and you can see now this is printed to the console so whenever anyone clicks on this button now this function is going to fire I can do it again and it happens again awesome so that's buttons in a nutshell and again if you click on this press ctrl Q you can see all of the different properties that we can give to a button as well so now I'd like to show you how to add an icon inside a button with some text as well so let me now get rid of the flat button and what I'm gonna do instead is say okay we'll have a raised button and then I'm going to also say after this button dot icon and that means basically we want an icon inside this button as well so inside this and first of all we're going to say unpressed I'm going to leave this as a blank function we don't need to do anything inside it and then under that I'm going to do an icon property and this needs to use the icon widgets and then the icon I want to use is going to be just the mail icon like that now I'm not going to edit with the color of the icon or anything like that I'm just going to leave it as is the next property I'd like to do is going to be a label praten and a label property is going to be the text which sits next to the icon so I'll just use a text widget for this and the text can be male me something like that and then finally let's give this a color and we'll do colors dots amber something like that okay cool so if we save this now it looks something like this and again if we wanted to customize the icon with the color and the size we can do same goes for the text we could make this white and bit bigger something like that it's up to you all the customization options are there and available to use but anyway that's how we add icons inside buttons like this now I want to show you one more thing and that is something called an icon button which is basically just a small icon which can be pressed basically so let's get rid of this again and finally I'm going to say this time we want an icon button and then inside this we need the on pressed property first of all which is going to be a we're not going to put anything inside that function for now we know how it works now and then underneath that I'm gonna say the icon is going to be an icon widget and we want the icons and then dots let's just use alternate email which is the @ symbol and then after that we'll specify a color and we'll make this Amber so we'll say colors dots amber like so okay so have we done this correct I think so let me save it now and now we can see this little @ symbol doesn't look much different from where we just had an icon the only difference is now it's pressable on this function will fire when we press it so let's just say prints and then you clicked me like so save it and now when we click this icon we can see you click me so that's the major difference between just using an icon and an icon button so hopefully now you've got the general idea of how to use icons and buttons we are going to be using them a lot in our project as we go forward so don't worry you will get more practice and I will show you different properties we can use inside them this is your introduction to them

Original Description

Hey gang, in this Flutter tutorial we'll see how to use both the Icon and the various Button widgets (flat & raised), as well as how both can work together to create icons inside buttons. ---------------------------------------- 🐱‍💻 🐱‍💻 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 Reads

📰
I need a way to Translate Audio/ Automatically make and translate subtitles from German to Portuguese
Learn to automatically translate audio and generate subtitles from German to Portuguese using AI tools
Reddit r/artificial
📰
Building a WhatsApp AI CRM in Google Sheets with Apps Script, Twilio & GPT-4
Build a WhatsApp AI CRM using Google Sheets, Apps Script, Twilio, and GPT-4 to automate customer interactions
Dev.to · Hayrullah Kar
📰
I built an open-source internship tracker that polls 3,593 company career feeds
Learn how to build an open-source internship tracker that polls company career feeds to stay ahead of the recruitment game
Dev.to AI
📰
Meta Just Realized Owning GPUs Is Not a Strategy
Having powerful computing resources like GPUs is not enough without a clear strategy or purpose
Medium · Programming
Up next
How to Use Jotform AI App Builder (Step-by-Step Tutorial)
Kevin Stratvert
Watch →