Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
4260c7e1a5 | |||
ffcabca487 | |||
bcac3a5e03 | |||
b3f16e9c47 |
@ -1,4 +1,6 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'weekManager.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
@ -12,10 +14,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: 'Deadliner'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -30,14 +32,30 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
late List<WeekManager> _weekManagers;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
@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(
|
||||
@ -49,13 +67,18 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
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.formatDate(weekManager.currentDate)}'),
|
||||
Text('Дней до дедлайна: ${weekManager.daysUntilDeadline}'),
|
||||
Text('Дата дедлайна: ${weekManager.formatDate(weekManager.deadline)}'),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -67,3 +90,34 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 'Воскресенье';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
53
lib/weekManager.dart
Normal file
53
lib/weekManager.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'package:intl/intl.dart';
|
||||
import 'main.dart';
|
||||
|
||||
class WeekManager {
|
||||
final DateTime _deadline;
|
||||
DateTime _currentDate;
|
||||
Weekday _currentDay;
|
||||
|
||||
WeekManager(this._deadline, this._currentDate)
|
||||
: _currentDay = _getCurrentDayOfWeek(_currentDate);
|
||||
|
||||
DateTime get deadline => _deadline;
|
||||
DateTime get currentDate => _currentDate;
|
||||
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 formatDate(DateTime date) {
|
||||
DateFormat formatter = DateFormat('dd-MM-yyyy');
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
void incrementCurrentDate() {
|
||||
_currentDate = _currentDate.add(const Duration(days: 1));
|
||||
}
|
||||
|
||||
void updateCurrentDay() {
|
||||
_currentDay = _getCurrentDayOfWeek(_currentDate);
|
||||
}
|
||||
}
|
@ -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:
|
||||
|
@ -30,6 +30,7 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
intl: ^0.18.0
|
||||
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
|
Loading…
Reference in New Issue
Block a user