Flutter Get First Day of Month Example

16-Jun-2022

.

Admin

Flutter Get First Day of Month Example

Hi friends,

This article will give you example of Flutter Get First Day of Month Example. Here you will learn flutter return first day of month Code Example. This article goes in detailed on How to get month start date in Flutter. let’s discuss about How to find first day of month?.

I will give you simple Example of How to Get First Day of Month in Flutter?

Let's see bellow example flutter get first day of current month.

So let's see bellow example:

Step 1: Create Flutter Project


Follow along with the setup, you will be creating an Flutter app.

$flutter create flutter_get_first_day_of_month_tutorial

Navigate to the project directory:

$cd flutter_get_first_day_of_month_tutorial

Step 2: Main File

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 First 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).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 First Day of Month'),

),

],

),

)

);

}

}

Run this Debug App

Output :

I hope it will help you....

#Flutter