PIbd-32_Chubykina_P.P._mobilki/lib/main.dart

108 lines
2.6 KiB
Dart
Raw Normal View History

2024-09-18 16:29:46 +04:00
import 'dart:math';
import 'package:flutter/material.dart';
2024-09-23 15:47:27 +04:00
import 'task.dart';
import 'taskManager.dart';
2024-09-18 16:29:46 +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',
2024-09-18 16:52:27 +04:00
debugShowCheckedModeBanner: false,
2024-09-18 16:29:46 +04:00
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
2024-09-18 17:26:27 +04:00
home: const MyHomePage(title: 'Чубыкина Полина Павловна'),
2024-09-18 16:29:46 +04:00
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
2024-09-23 15:47:27 +04:00
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';
}
}
}
2024-09-18 16:29:46 +04:00
class _MyHomePageState extends State<MyHomePage> {
Color _color = Colors.orangeAccent;
2024-09-23 15:47:27 +04:00
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);
2024-09-18 16:29:46 +04:00
setState(() {
_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: <Widget>[
2024-09-23 15:47:27 +04:00
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
for (var task in _taskManager.getTasks())
Text(
2024-09-23 20:36:31 +04:00
'${task.title}: Priority - ${task.priority.displayName}',
2024-09-23 15:47:27 +04:00
style: const TextStyle(fontSize: 18),
),
],
),
),
2024-09-18 16:29:46 +04:00
),
],
),
),
floatingActionButton: FloatingActionButton(
2024-09-23 15:47:27 +04:00
onPressed: () async {
_addRandomTask();
await _taskManager.simulateTaskProcessing();
},
2024-09-18 16:29:46 +04:00
backgroundColor: _color,
child: const Icon(Icons.add),
),
);
}
}