Format Dates in Flutter

The Dart in built method,for formatting ,date in flutter application while dealing with dates it should be in number readable format. In the article . We will look at examples of change date format on mobile applications.

Step 1:  Add the below line in dependencies to your pubspec.yaml file 
 dependencies:
intl: ^0.17.0
Step 2:  Add using terminal, Open terminal and write below code.

  Flutter pub add intl

Strep 3 :  import intl package in dart code. 
 import 'package:flutter/cupertino.dart';
Strep 4 : Final code of date format in application.

 import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
runApp(HomeScreen());
}

class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Date Format Demo",
home: Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue,
title: Text("Date format demo"),
),
body: Container(
margin: EdgeInsets.fromLTRB(95, 80, 0, 0),
child: Text(
DateTime.now().toString(),
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 30),
),
)),
);
}
}
Strep 5 : Output of above example.



Happy coding!

365Bloggy May 30, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive