How to Get First Day of Next Week in Flutter?
Jun 30, 2022 . Admin
Hi Guys,
In this example, I will show you How to Get First Day of Next Week in Flutter?. We will use How to get start day of next week in flutter. We will use How to find the first date of a next week. we will help you to give example of Find the First day of the Next Week in Flutter. So, let's follow few step to create example of how to find start day of the Next Week in Flutter.
I will give you simple Flutter get start day of the Next Week example tutorial
So let's see bellow example:
Step 1: Create Flutter ProjectFollow along with the setup, you will be creating an Flutter app.
$flutter create flutter_get_first_day_of_next_week_tutorial
Navigate to the project directory:
$cd flutter_get_first_day_of_next_week_tutorialStep 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 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 = findFirstDateOfNextWeek(now); var formattedDate ="${dateParse.day}/${dateParse.month}/${dateParse.year}"; setState(() { finalDate = formattedDate.toString() ; }); } DateTime findFirstDateOfNextWeek(DateTime dateTime) { final DateTime sameWeekDayOfNextWeek = dateTime.add(const Duration(days: 7)); return findFirstDateOfTheWeek(sameWeekDayOfNextWeek); } DateTime findFirstDateOfTheWeek(DateTime dateTime) { return dateTime.subtract(Duration(days: dateTime.weekday - 1)); } @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 The Next Week'), ), ], ), ) ); } }Step 3: Run this Debug App Output:

I hope it will help you....