diff --git a/lib/main.dart b/lib/main.dart index 2ec3f9d..b3027d4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,7 @@ import 'dart:math'; - import 'package:flutter/material.dart'; +import 'task.dart'; +import 'taskManager.dart'; void main() { runApp(const MyApp()); @@ -32,50 +33,73 @@ class MyHomePage extends StatefulWidget { State createState() => _MyHomePageState(); } +enum TaskPriority { + low, + medium, + high, +} + +extension TaskPriorityExtension on TaskPriority { + String get displayName { + switch (this) { + case TaskPriority.low: + return 'Low'; + case TaskPriority.medium: + return 'Medium'; + case TaskPriority.high: + return 'High'; + } + } +} + class _MyHomePageState extends State { - int _counter = 0; Color _color = Colors.orangeAccent; - void _incrementCounter() { + final TaskManager _taskManager = TaskManager(); + + void _addRandomTask() { + const priorities = TaskPriority.values; + final randomPriority = priorities[Random().nextInt(priorities.length)]; + final newTask = Task('Task ${_taskManager.getTasks().length + 1}', randomPriority); + _taskManager.addTask(newTask); setState(() { - _counter++; _color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); }); } @override Widget build(BuildContext context) { - return Scaffold( appBar: AppBar( backgroundColor: _color, title: Text(widget.title), ), body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, children: [ - const Text( - 'You have pushed the button this many times:', + Expanded( + child: SingleChildScrollView( + child: Column( + children: [ + for (var task in _taskManager.getTasks()) + Text( + '${task.title} - Priority: ${task.priority.displayName}', + style: const TextStyle(fontSize: 18), + ), + ], + ), + ), ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - if (_counter > 10) - Text( - 'Why are you clicking?', - style: Theme.of(context).textTheme.headlineMedium, - ) ], ), ), floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, + onPressed: () async { + _addRandomTask(); + await _taskManager.simulateTaskProcessing(); + }, backgroundColor: _color, - tooltip: 'Increment', child: const Icon(Icons.add), ), ); diff --git a/lib/task.dart b/lib/task.dart new file mode 100644 index 0000000..c81873b --- /dev/null +++ b/lib/task.dart @@ -0,0 +1,8 @@ +import 'main.dart'; + +class Task { + final String title; + final TaskPriority priority; + + Task(this.title, this.priority); +} \ No newline at end of file diff --git a/lib/taskManager.dart b/lib/taskManager.dart new file mode 100644 index 0000000..3e05345 --- /dev/null +++ b/lib/taskManager.dart @@ -0,0 +1,18 @@ +import 'task.dart'; + +class TaskManager { + final List _tasks = []; + + void addTask(Task task) { + _tasks.add(task); + } + + List getTasks() { + return _tasks; + } + + Future simulateTaskProcessing() async { + await Future.delayed(const Duration(seconds: 2)); + print('Задание выполнено'); + } +} \ No newline at end of file