вроде готовая лаба 2
This commit is contained in:
parent
601b3434c3
commit
6eb0107e03
@ -1,6 +1,7 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'task.dart';
|
||||||
|
import 'taskManager.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@ -32,50 +33,73 @@ class MyHomePage extends StatefulWidget {
|
|||||||
State<MyHomePage> createState() => _MyHomePageState();
|
State<MyHomePage> 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<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
int _counter = 0;
|
|
||||||
Color _color = Colors.orangeAccent;
|
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(() {
|
setState(() {
|
||||||
_counter++;
|
|
||||||
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: _color,
|
backgroundColor: _color,
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
|
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const Text(
|
Expanded(
|
||||||
'You have pushed the button this many times:',
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: <Widget>[
|
||||||
|
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(
|
floatingActionButton: FloatingActionButton(
|
||||||
onPressed: _incrementCounter,
|
onPressed: () async {
|
||||||
|
_addRandomTask();
|
||||||
|
await _taskManager.simulateTaskProcessing();
|
||||||
|
},
|
||||||
backgroundColor: _color,
|
backgroundColor: _color,
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
8
lib/task.dart
Normal file
8
lib/task.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import 'main.dart';
|
||||||
|
|
||||||
|
class Task {
|
||||||
|
final String title;
|
||||||
|
final TaskPriority priority;
|
||||||
|
|
||||||
|
Task(this.title, this.priority);
|
||||||
|
}
|
18
lib/taskManager.dart
Normal file
18
lib/taskManager.dart
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import 'task.dart';
|
||||||
|
|
||||||
|
class TaskManager {
|
||||||
|
final List<Task> _tasks = [];
|
||||||
|
|
||||||
|
void addTask(Task task) {
|
||||||
|
_tasks.add(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Task> getTasks() {
|
||||||
|
return _tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> simulateTaskProcessing() async {
|
||||||
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
print('Задание выполнено');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user