124 lines
3.2 KiB
Dart
124 lines
3.2 KiB
Dart
import 'dart:math';
|
|
import 'package:flutter/material.dart';
|
|
import 'weekManager.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
|
|
useMaterial3: true,
|
|
),
|
|
home: const MyHomePage(title: 'Deadliner'),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
final String title;
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
late List<WeekManager> _weekManagers;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
final random = Random();
|
|
_weekManagers = List.generate(5, (index) {
|
|
DateTime deadline = DateTime.now().add(Duration(days: random.nextInt(365)));
|
|
DateTime currentDate = DateTime.now().add(Duration(days: random.nextInt(365)));
|
|
return WeekManager(deadline, currentDate);
|
|
});
|
|
}
|
|
|
|
Future<void> _incrementCounter() async {
|
|
for (var weekManager in _weekManagers) {
|
|
await Future.delayed(const Duration(milliseconds: 500), () {
|
|
setState(() {
|
|
weekManager.incrementCurrentDate();
|
|
weekManager.updateCurrentDay();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
title: Text(widget.title),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Text('Дедлайнер',
|
|
style: Theme.of(context).textTheme.headlineMedium),
|
|
const SizedBox(height: 20),
|
|
..._weekManagers.map((weekManager) => Column(
|
|
children: [
|
|
Text('Текущий день недели: ${weekManager.currentDay.name}'),
|
|
Text('Текущая дата: ${weekManager.formatDate(weekManager.currentDate)}'),
|
|
Text('Дней до дедлайна: ${weekManager.daysUntilDeadline}'),
|
|
Text('Дата дедлайна: ${weekManager.formatDate(weekManager.deadline)}'),
|
|
const SizedBox(height: 20),
|
|
],
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: _incrementCounter,
|
|
tooltip: 'Increment',
|
|
child: const Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
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 'Воскресенье';
|
|
}
|
|
}
|
|
}
|