How To Find Last Date of Month In Flutter ?

Today now in this post i will show you How To Find Last Date of Month In Flutter ? Here in this post i am going to show you an example of flutter to find last date of month example. Now in this tutorial i will give you a very simple example of how to find the last day of month. So in this post i will give you a very simple example of flutter getting the last day of month in date example. Here I will explained this simply step by step find the last day of the current month in flutter. Just need to follow the bellow step for flutter datetime get last day of month.

Here I will give you a simple Example of flutter find last date of month

So let’s start and see the bellow example:

Step 1: Create Flutter Project

Just need to Follow the along with the setup, i will be creating an Flutter app.

$flutter create flutter_get_last_day_of_month_tutorial   

Navigate to the project directory:

$cd flutter_get_last_day_of_month_tutorial   
Step 2: Main File

Just need to Create a main.dart file in the lib directory

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
        return MaterialApp(
            home: Scaffold(
                appBar: AppBar(
                    title: Text('Get Last Day of Month')
                ),
                body: Center(
                    child: GetDate()
                )
            )
        );
    }
}

class GetDate extends StatefulWidget {

    _GetDateState createState() => _GetDateState();

}

class _GetDateState extends State<GetDate> {

    String finalDate = '';

    getCurrentDate(){

        final now = DateTime.now();

        var date = DateTime(now.year, now.month+1, 0).toString();

        var dateParse = DateTime.parse(date);

        var formattedDate = "${dateParse.day}/${dateParse.month}/${dateParse.year}";

        setState(() {

            finalDate = formattedDate.toString() ;

        });

    }

    @override
    Widget build(BuildContext context) {
        return Scaffold(
            body: Center(
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[

                        Padding(
                            padding: EdgeInsets.all(8.0),
                            child :
                            Text("Date = $finalDate", style: TextStyle(fontSize: 20), textAlign: TextAlign.center,)
                        ),

                        RaisedButton(
                            onPressed: getCurrentDate,
                            color: Colors.green,
                            textColor: Colors.white,
                            padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                            child: Text('Click Here To Last Day of Month'),
                        ),

                    ],
                ),
            )
        );
    }
}

Read Also: How To Get Tomorrow Date In Flutter ?

close

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →