diff --git a/lib/main.dart b/lib/main.dart index 3af3bce..852c351 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'weekManager.dart'; void main() { runApp(const MyApp()); @@ -12,10 +13,10 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), - home: const MyHomePage(title: 'Иванов Вячеслав Николаевич'), + home: const MyHomePage(title: 'Dart Flutter Demo'), ); } } @@ -30,11 +31,35 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; + late List _weekManagers; + + @override + void initState() { + super.initState(); + _weekManagers = List.generate(5, (index) { + DateTime deadline = DateTime.now().add(Duration(days: (index + 1) * 7)); + return WeekManager(deadline); + }); + _updateDeadlines(); + } + + Future _updateDeadlines() async { + for (var weekManager in _weekManagers) { + await Future.delayed(const Duration(seconds: 1), () { + setState(() { + weekManager.updateCurrentDate(); + weekManager.updateCurrentDay(); + }); + }); + } + } void _incrementCounter() { setState(() { - _counter++; + for (var weekManager in _weekManagers) { + weekManager.incrementCurrentDate(); + weekManager.updateCurrentDay(); + } }); } @@ -49,13 +74,18 @@ class _MyHomePageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), + Text('Дедлайнер', + style: Theme.of(context).textTheme.headlineMedium), + const SizedBox(height: 20), + ..._weekManagers.map((weekManager) => Column( + children: [ + Text('Текущий день недели: ${weekManager.currentDay.name}'), + Text('Текущая дата: ${weekManager.formattedCurrentDate}'), + Text('Дней до дедлайна: ${weekManager.daysUntilDeadline}'), + Text('Дата дедлайна: ${weekManager.formattedDeadline}'), + const SizedBox(height: 20), + ], + )), ], ), ), @@ -67,3 +97,34 @@ class _MyHomePageState extends State { ); } } + +enum Weekday { + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + Sunday +} + +extension WeekdayExtension on Weekday { + String get name { + switch (this) { + case Weekday.Monday: + return 'Понедельник'; + case Weekday.Tuesday: + return 'Вторник'; + case Weekday.Wednesday: + return 'Среда'; + case Weekday.Thursday: + return 'Четверг'; + case Weekday.Friday: + return 'Пятница'; + case Weekday.Saturday: + return 'Суббота'; + case Weekday.Sunday: + return 'Воскресенье'; + } + } +} diff --git a/lib/weekManager.dart b/lib/weekManager.dart new file mode 100644 index 0000000..f9bc6be --- /dev/null +++ b/lib/weekManager.dart @@ -0,0 +1,65 @@ +import 'dart:math'; + +import 'package:intl/intl.dart'; + +import 'main.dart'; + +class WeekManager { + DateTime deadline; + DateTime currentDate; + Weekday _currentDay; + + WeekManager(this.deadline) + : currentDate = DateTime.now(), + _currentDay = _getCurrentDayOfWeek(DateTime.now()); + + Weekday get currentDay => _currentDay; + + static Weekday _getCurrentDayOfWeek(DateTime date) { + switch (date.weekday) { + case 1: + return Weekday.Monday; + case 2: + return Weekday.Tuesday; + case 3: + return Weekday.Wednesday; + case 4: + return Weekday.Thursday; + case 5: + return Weekday.Friday; + case 6: + return Weekday.Saturday; + case 7: + return Weekday.Sunday; + default: + return Weekday.Monday; + } + } + + int get daysUntilDeadline { + return deadline.difference(currentDate).inDays; + } + + String get formattedDeadline { + DateFormat formatter = DateFormat('dd-MM-yyyy'); + return formatter.format(deadline); + } + + String get formattedCurrentDate { + DateFormat formatter = DateFormat('dd-MM-yyyy'); + return formatter.format(currentDate); + } + + void updateCurrentDay() { + _currentDay = _getCurrentDayOfWeek(currentDate); + } + + void updateCurrentDate() { + final random = Random(); + currentDate = DateTime.now().add(Duration(days: random.nextInt(365))); + } + + void incrementCurrentDate() { + currentDate = currentDate.add(const Duration(days: 1)); + } +} diff --git a/pubspec.lock b/pubspec.lock index 07514d0..c03ad15 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -75,6 +75,14 @@ packages: description: flutter source: sdk version: "0.0.0" + intl: + dependency: "direct main" + description: + name: intl + sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d" + url: "https://pub.dev" + source: hosted + version: "0.18.1" leak_tracker: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 55af1a5..7a99d67 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,6 +30,7 @@ environment: dependencies: flutter: sdk: flutter + intl: ^0.18.0 # The following adds the Cupertino Icons font to your application.