Flutter Tutorial for Beginners #31 - Formatting & Showing Dates

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

Key Takeaways

Formats and displays dates in a Flutter application using the intl package

Full Transcript

okay then going so now we've got to the point where inside our home screen we have access to the data we need including the time which we ultimately want to output to the screen but at the minute this time kind of looks a bit cruddy I'd like to maybe format this in a different way that looks a bit better so to do that we're going to use a package from flutter and that package is called intel over here and you can see inside this contains some date formatting and passing so we're going to use a function from this package that is going to help us format our date in a nicer way so to install this we just have to grab this thing right here and we're going to paste it inside this file if I minimize this we want to go to pub spec gamal and we want to go down to our dependencies and they are here so let me come underneath the HTTP and paste this one in and save it then going to close this off I'm going to click get dependencies to update that and grab that dependency so once that's done I need to go now to our service file which is this world time and this is where we're going to format the date so first of all we need to import this package and to do that I'll say import and then I'm just going to look for intel and it's gonna be this one down here okay so now down here we want to use a function provided towards by this package and all willing to do is delete this dot first of all and then I'm gonna say date format which is provided to us by that package we just imported then use a method called JM and then a method on that called format and inside here we're just gonna pass in now so I'm gonna say now like so and this is going to format that date into something that looks a lot more palatable so if I save this now and if we go to run again hopefully when we see the new data printed it's gonna be a bit better and get a hot restart and in a second we should see the time and there we can see it's now 1:20 p.m. that looks a lot more human readable and that is ultimately what we're going to output to the screen so now we have this data inside the home screen let's go about using it inside the template over here so currently this flat button this is inside a column so we're just gonna add some more widgets to this column the first thing I'm gonna do is a sized box because that gives us a bit of breathing room between different widgets in a column we've seen our already and this is gonna have a height of 20 pixels alright so the next one I'd like to do is a row and the reason I'm gonna do a row is because underneath this flat bottom we're gonna have two things next to each other on the same level and that is going to be a little icon of the flag and also next to that we're going to have a text widget which is going to output the location now we're not going to do the icon just yet but I'm placing this row therefore in the future what I will do is say children and then this will be a list of widgets and we'll do the text widget for now so this text widget is going to say inside it the location so we need to grab the data variable that we have now and then inside that we want the location property so if I save it we should see that on the screen now cool looking good but we want to style this a bit better so I'm going to say now we want a style property inside this text widget and this will be a text style and inside here we want to format the text a bit better we want to make it bigger for a start so I'll say font size is going to be 28 like so 28 pixels and then also the letter spacing will give a value of about 2 pixels okay so save that and that looks a bit better now while I'm here what I'm going to do to this row is go to the main axis alignment and I'm going to set that to be Center so this now is going to sit in the center so let me save it and preview and that looks a lot better now I also want to bring this down quite a bit as well so I think what I'm going to do inside the safe area and surrounding this column is add some padding so let me go to this Action menu and then go to add padding and then I'm going to change this to instead of all I'm going to control each side separately so I'm going to say from and then it's l CR B so we can control the left top right bottom independently and the left is going to be 0 the top is going to be 120 pixels and that's what's going to bring it down quite a bit now then the right is going to be 0 and the bottom is going to be 0 so if I save it now hopefully yep it brings it down a fair whack okay so then for now after this row what is the next thing we want well that is the time itself but before that we need another sized box you know I can do this correctly so size box and then in there we'll say the height is going to be this time 20 pixels again maybe so let's do 20 and then after that we want a text widget to output the time so again this time is now stored on the data so we need something similar to this we'll say data and then it's the time property that we want so let's save that and see it okay looking good but this time what we need to do is make this style a bit better so we'll say style and then text style and all I'm going to do is probably just increase the font size so I'll say fonts size and we want to make it nice and large so 66 pixels save it and that is looking pretty good okay cool so now if we hop restart we should see the updated time so 1:24 p.m. in building and there we go my friends we've now formatted our time down here inside whoops wrong file so we'll time so we format at the time right here just by using this junior method and the format method and we did that using date format by installing and importing this package or right here so we get that updated format which looks a lot better for the user then inside the home screen all we're doing is outputting this data that we get back from the loading screen so we receive it here we store it in data and then we output in that data down here inside the widget tree so this is all looking pretty good so far what I'd like to do in the next video is go back to the loading screen because currently the loading screen looks a bit pumps if I hot restart will quickly see it over here so hot restart we see the loading screen there it looks a bit rubbish I'd like to make that look a bit better by using a spinner and to do that we'll use another package for flutter and we'll see in the next video

Original Description

Hey gang, in this Flutter tutorial I'll show you how we can quickly format our date and output it to the home screen. ---------------------------------------- 🐱‍💻 🐱‍💻 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

📰
3 Free AI Tools I Use to Save Hours Every Week
Discover 3 free AI tools to automate repetitive tasks and save hours every week, boosting productivity
Dev.to · Hari Haran
📰
My AI Bill Dropped 95% When I Switched to Chinese Models
Switching to Chinese AI models can significantly reduce costs, with one company experiencing a 95% drop in their AI bill, making it a viable option for businesses looking to cut expenses.
Dev.to AI
📰
AI Dubbing for Short Drama: The 2026 Playbook That Actually Scales
Learn how to scale AI dubbing for short drama with the 2026 playbook, improving efficiency and quality in audio post-production
Dev.to AI
📰
Why AI App Backends Are Becoming Accounting Systems
Learn how AI app backends are evolving into accounting systems and why it matters for SaaS businesses
Dev.to · StructureIntelligence
Up next
Advanced Tutorial NotebookLM Slides For Powerpoint
Russell Stannard (TTVideos)
Watch →