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

108 lines
2.6 KiB
Dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'task.dart';
import 'taskManager.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Чубыкина Полина Павловна'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
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> {
Color _color = Colors.orangeAccent;
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(() {
_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>[
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
for (var task in _taskManager.getTasks())
Text(
'${task.title}: Priority - ${task.priority.displayName}',
style: const TextStyle(fontSize: 18),
),
],
),
),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
_addRandomTask();
await _taskManager.simulateTaskProcessing();
},
backgroundColor: _color,
child: const Icon(Icons.add),
),
);
}
}