PMU/lib/main.dart

131 lines
3.3 KiB
Dart
Raw Normal View History

2024-09-05 18:23:03 +04:00
import 'package:flutter/material.dart';
2024-09-10 23:39:25 +04:00
import 'weekManager.dart';
2024-09-05 18:23:03 +04:00
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(
2024-09-10 23:39:25 +04:00
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
2024-09-05 18:23:03 +04:00
useMaterial3: true,
),
2024-09-10 23:45:47 +04:00
home: const MyHomePage(title: 'Deadliner'),
2024-09-05 18:23:03 +04:00
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
2024-09-10 23:39:25 +04:00
late List<WeekManager> _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<void> _updateDeadlines() async {
for (var weekManager in _weekManagers) {
await Future.delayed(const Duration(seconds: 1), () {
setState(() {
weekManager.updateCurrentDate();
weekManager.updateCurrentDay();
});
});
}
}
2024-09-05 18:23:03 +04:00
void _incrementCounter() {
setState(() {
2024-09-10 23:39:25 +04:00
for (var weekManager in _weekManagers) {
weekManager.incrementCurrentDate();
weekManager.updateCurrentDay();
}
2024-09-05 18:23:03 +04:00
});
}
@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>[
2024-09-10 23:39:25 +04:00
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),
],
)),
2024-09-05 18:23:03 +04:00
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
2024-09-10 23:39:25 +04:00
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 'Воскресенье';
}
}
}