я навалила смешнявок надеюсь лабу можно считать сделанной

This commit is contained in:
Полина Чубыкина 2024-10-02 12:55:38 +04:00
parent f551dc58a9
commit 101ad9e727
3 changed files with 155 additions and 87 deletions

View File

@ -1,7 +1,4 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'task.dart';
import 'taskManager.dart';
void main() {
runApp(const MyApp());
@ -33,40 +30,8 @@ class MyHomePage extends StatefulWidget {
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();
Task _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);
});
return newTask;
}
final Color _color = Colors.teal.shade200;
@override
Widget build(BuildContext context) {
@ -75,34 +40,164 @@ class _MyHomePageState extends State<MyHomePage> {
backgroundColor: _color,
title: Text(widget.title),
),
body: Center(
body: const MyWidget(),
);
}
}
class _CardData {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
_CardData(
this.text, {
required this.descriptionText,
this.icon = Icons.abc,
this.imageUrl,
});
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(
'кот',
descriptionText: 'глупенький',
imageUrl:
'https://i.pinimg.com/564x/98/74/75/98747559040c03402a6d9ad4e47152c6.jpg',
),
_CardData(
'сырный кот',
descriptionText: 'он не виноват',
icon: Icons.access_time_filled_outlined,
imageUrl:
'https://i.pinimg.com/564x/e7/c5/59/e7c559e449cd0bb5370d7740b57daa1f.jpg',
),
_CardData(
'злой кот',
descriptionText: 'я бы ему не верила',
icon: Icons.add_alarm_sharp,
imageUrl:
'https://i.pinimg.com/736x/27/cf/5e/27cf5e3abe1795ce04095941902c61ca.jpg',
),
_CardData(
'умный кот',
descriptionText: 'он только делает вид что умный',
icon: Icons.add_alarm_sharp,
imageUrl:
'https://i.pinimg.com/736x/e9/24/80/e924801430b813eee2635b40fe6e11d6.jpg',
),
_CardData(
'кот с мандаринами',
descriptionText: '我喜欢橘子!',
icon: Icons.add_alarm_sharp,
imageUrl:
'https://i.pinimg.com/564x/3e/ed/11/3eed1103c548ed7c46a1e37a2695f53a.jpg',
),
_CardData(
'котенок',
descriptionText: 'я его очень понимаю',
icon: Icons.add_alarm_sharp,
imageUrl:
'https://i.pinimg.com/736x/38/9f/e6/389fe61133f036fc980a6b2e7abb2557.jpg',
),
];
return Center(
child: SingleChildScrollView(
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),
),
],
),
),
),
],
children: data.map((e) => _Card.fromData(e)).toList(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
Task task = _addRandomTask();
await _taskManager.simulateTaskProcessing(task);
},
backgroundColor: _color,
child: const Icon(Icons.add),
),
);
}
}
class _Card extends StatelessWidget {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
const _Card(
this.text, {
this.icon = Icons.abc,
required this.descriptionText,
this.imageUrl,
});
factory _Card.fromData(_CardData data) => _Card(
data.text,
descriptionText: data.descriptionText,
icon: data.icon,
imageUrl: data.imageUrl,
);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
//color: Colors.teal.shade100,
border: Border.all(color: Colors.grey.shade200),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(.5),
spreadRadius: 4,
offset: const Offset(0, 5),
blurRadius: 8,
),
],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 140,
width: 160,
child: Image.network(
imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
text,
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
descriptionText,
style: Theme.of(context).textTheme.bodyLarge,
),
],
),
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(icon),
),
],
),
);
}
}

View File

@ -1,8 +0,0 @@
import 'main.dart';
class Task {
final String title;
final TaskPriority priority;
Task(this.title, this.priority);
}

View File

@ -1,19 +0,0 @@
import 'task.dart';
class TaskManager {
final List<Task> _tasks = [];
void addTask(Task task) {
_tasks.add(task);
}
List<Task> getTasks() {
return _tasks;
}
Future<void> simulateTaskProcessing(Task task) async {
await Future.delayed(const Duration(seconds: 2));
print('Задание ${task.title} выполнено');
}
}