DEV Community

Cover image for How to Display Current DateTime in Flutter - fluttercorner.com
FlutterCorner
FlutterCorner

Posted on • Edited on

How to Display Current DateTime in Flutter - fluttercorner.com

Hello Guys How are you all? Hope you all are fine. Today We are going to learn How to Display Current DateTime in Flutter?

Many Times We have to display Current Date time with date, month, year, hours, minutes and second, with real time clock in flutter. in very easy way we are going to learn in this tutorial a=here. so without wasting your time lets start this tutorial.

How to Display Current DateTime in Flutter
How to Display Current DateTime in Flutter?
First of All Import material.dart, async, and intl Package in your main.dart file.

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
Enter fullscreen mode Exit fullscreen mode

Then, Create void main and Define MyApp in your runApp.

void main() {
  runApp(MyApp());
}
Enter fullscreen mode Exit fullscreen mode

Now, Create a class named MyApp extends with a Stateless widget. This is our main View class. and define

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {

  }
}
Enter fullscreen mode Exit fullscreen mode

Then, After making Scaffold in MyApp Widget. The scaffold is the Base of every flutter apps, Scaffold provides app bar, background color, drawer, body, bottom sheet, etc.
We need a center widget in our body so add the Center widget in the body.

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Display Current DateTime - Fluttercorner'),
        ),
        body: Center(),
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

Now Define DateTime String name that you want to display.

Full Article Is At Here Take a look https://fluttercorner.com/how-to-display-current-datetime-in-flutter/

Top comments (1)

Collapse
 
pablonax profile image
Pablo Discobar

Helpful article! Thanks! If you are interested in this, you can also look at my article about Flutter templates. I made it easier for you and compared the free and paid Flutter templates. I'm sure you'll find something useful there, too. - dev.to/pablonax/free-vs-paid-flutt...