How to Get End Date of Next Week Example in Flutter?

Jul 02, 2022

.

Admin

How to Get End Date of Next Week Example in Flutter?

Hi Guys,

Here, I will show you how to works How to Get End Date of Next Week Example in Flutter?. it's simple example of How to find the last date of a next week in flutter. This article will give you simple example of How to get Last Day of a next Week in Dart. We will look at example of Finding the Last Day of next week in flutter. you will do the following things for finding the last day of next week in flutter app.

I will give you simple example of Flutter Get Last Day of Next Week Example,

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_last_day_of_next_week_tutorial

Navigate to the project directory:

$cd flutter_get_last_day_of_next_week_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 Last Day of The Next Week')

),

body: Center(

child: GetDate()

)

)

);

}

}

class GetDate extends StatefulWidget {

_GetDateState createState() => _GetDateState();

}

class _GetDateState extends State<GetDate> {

String finalDate = '';

getCurrentDate(){

final now = DateTime.now();

var dateParse = findLastDateOfNextWeek(now);

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

setState(() {

finalDate = formattedDate.toString() ;

});

}

DateTime findLastDateOfNextWeek(DateTime dateTime) {

final DateTime sameWeekDayOfNextWeek = dateTime.add(const Duration(days: 7));

return findLastDateOfTheWeek(sameWeekDayOfNextWeek);

}

DateTime findLastDateOfTheWeek(DateTime dateTime) {

return dateTime.add(Duration(days: DateTime.daysPerWeek - dateTime.weekday));

}

@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 The Next Week'),

),

],

),

)

);

}

}

Step 3: Run this Debug App

Output:

I hope it will help you....

#Flutter