PMU/lib/main.dart

124 lines
3.2 KiB
Dart
Raw Normal View History

2024-09-10 23:49:54 +04:00
import 'dart:math';
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();
2024-09-10 23:49:54 +04:00
final random = Random();
2024-09-10 23:39:25 +04:00
_weekManagers = List.generate(5, (index) {
2024-09-10 23:49:54 +04:00
DateTime deadline = DateTime.now().add(Duration(days: random.nextInt(365)));
2024-09-11 15:25:59 +04:00
DateTime currentDate = DateTime.now().add(Duration(days: random.nextInt(365)));
return WeekManager(deadline, currentDate);
2024-09-10 23:39:25 +04:00
});
}
2024-09-11 15:25:59 +04:00
Future<void> _incrementCounter() async {
2024-09-10 23:39:25 +04:00
for (var weekManager in _weekManagers) {
2024-09-11 15:25:59 +04:00
await Future.delayed(const Duration(milliseconds: 500), () {
2024-09-10 23:39:25 +04:00
setState(() {
2024-09-11 15:25:59 +04:00
weekManager.incrementCurrentDate();
2024-09-10 23:39:25 +04:00
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}'),
2024-09-11 15:25:59 +04:00
Text('Текущая дата: ${weekManager.formatDate(weekManager.currentDate)}'),
2024-09-10 23:39:25 +04:00
Text('Дней до дедлайна: ${weekManager.daysUntilDeadline}'),
2024-09-11 15:25:59 +04:00
Text('Дата дедлайна: ${weekManager.formatDate(weekManager.deadline)}'),
2024-09-10 23:39:25 +04:00
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 'Воскресенье';
}
}
}