Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c42cbed29f | |||
| a28a6c9250 | |||
| d56a0f5ee5 |
174
lib/main.dart
174
lib/main.dart
@@ -13,11 +13,10 @@ class MyApp extends StatelessWidget {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.black),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Козлова Анастасия Александровна'),
|
||||
home: const MyHomePage(title: 'настя'),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -32,46 +31,167 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
final Color _color = Colors.black;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
|
||||
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,
|
||||
required this.icon,
|
||||
this.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
class MyWidget extends StatelessWidget {
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = [
|
||||
_CardData(
|
||||
'bebebe',
|
||||
descriptionText: 'sldmk',
|
||||
icon: Icons.hail,
|
||||
imageUrl: 'https://img.freepik.com/free-photo/smiley-woman-talking-phone-medium-shot_23-2149476757.jpg?t=st=1727894827~exp=1727898427~hmac=a14045ebfb7ed48343615c31db970b30b086a5ddadaa428601b7534e37540b4a&w=996',
|
||||
),
|
||||
_CardData(
|
||||
'sdde',
|
||||
descriptionText: 'ssdmk',
|
||||
icon: Icons.hail,
|
||||
imageUrl: 'https://img.freepik.com/free-photo/medium-shot-women-with-delicious-food_23-2150168102.jpg?t=st=1727895736~exp=1727899336~hmac=3260118fc2bd6fe946f54465e104629fe046384f621e8393e1f9f557392f7dad&w=996',
|
||||
),
|
||||
_CardData(
|
||||
'aaae',
|
||||
descriptionText: 'ssldmk',
|
||||
icon: Icons.hail,
|
||||
imageUrl: 'https://img.freepik.com/free-photo/high-angle-smiley-woman-sitting-table_23-2150168074.jpg?t=st=1727895785~exp=1727899385~hmac=880ec7fcf220143947d4f276490c4338c1828c7920540a1efc2503c4cc791aec&w=360',
|
||||
),
|
||||
];
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const Text(
|
||||
'You have pushed the button this many times:',
|
||||
children: data.map((e) => _Card.fromData(e)).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Card extends StatefulWidget {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
final IconData icon;
|
||||
final String? imageUrl;
|
||||
|
||||
const _Card(this.text, {
|
||||
this.icon = Icons.ac_unit_outlined,
|
||||
required this.descriptionText,
|
||||
this.imageUrl
|
||||
});
|
||||
|
||||
factory _Card.fromData(_CardData data) =>
|
||||
_Card(
|
||||
data.text,
|
||||
descriptionText: data.descriptionText,
|
||||
icon: data.icon,
|
||||
imageUrl: data.imageUrl,
|
||||
);
|
||||
|
||||
@override
|
||||
State<_Card> createState() => _CardState();
|
||||
}
|
||||
|
||||
class _CardState extends State<_Card> {
|
||||
bool isLiked = false;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(20),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white70,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: Colors.blueGrey,
|
||||
),
|
||||
|
||||
),
|
||||
child: IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: SizedBox(
|
||||
height: 140,
|
||||
width: 100,
|
||||
child: Image.network(
|
||||
widget.imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.text,
|
||||
style: Theme.of(context).textTheme.headlineLarge,
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
widget.descriptionText,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 8.0,
|
||||
right: 16,
|
||||
bottom: 16
|
||||
),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
isLiked = !isLiked;
|
||||
});
|
||||
},
|
||||
child: Icon(
|
||||
isLiked ? Icons.favorite : Icons.favorite_border
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
126
lib/main1.dart
Normal file
126
lib/main1.dart
Normal file
@@ -0,0 +1,126 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
void main() {
|
||||
runApp();
|
||||
}
|
||||
|
||||
Future<void> runApp() async {
|
||||
final TaskManager taskManager = TaskManager();
|
||||
|
||||
while (true) {
|
||||
print('\nВыберите действие:');
|
||||
print('1. Добавить задачу');
|
||||
print('2. Показать все задачи');
|
||||
print('3. Удалить задачу');
|
||||
print('4. Выполнить задачу');
|
||||
print('5. Выйти');
|
||||
|
||||
String? choice = stdin.readLineSync();
|
||||
switch (choice) {
|
||||
case '1':
|
||||
print('Введите описание задачи:');
|
||||
String? description = stdin.readLineSync();
|
||||
if (description != null && description.isNotEmpty) {
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
taskManager.addTask(Task(
|
||||
description: description,
|
||||
timestamp: DateTime.now(),
|
||||
));
|
||||
}
|
||||
break;
|
||||
case '2':
|
||||
taskManager.showTasks();
|
||||
break;
|
||||
case '3':
|
||||
print('Введите номер задачи для удаления: ');
|
||||
String? indexInput = stdin.readLineSync();
|
||||
if (indexInput != null) {
|
||||
int index = int.tryParse(indexInput) ?? -1;
|
||||
taskManager.removeTask(index);
|
||||
}
|
||||
break;
|
||||
case '4':
|
||||
print('Введите номер задачи для выполнения:');
|
||||
String? completeIndexInput = stdin.readLineSync();
|
||||
if (completeIndexInput != null) {
|
||||
int index = int.tryParse(completeIndexInput) ?? -1;
|
||||
taskManager.completeTask(index);
|
||||
}
|
||||
break;
|
||||
case '5':
|
||||
print('Выход из программы.');
|
||||
return;
|
||||
default:
|
||||
print('Неверный выбор, попробуйте снова.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum TaskStatus { pending, completed }
|
||||
|
||||
class Task {
|
||||
String description;
|
||||
DateTime timestamp;
|
||||
TaskStatus status;
|
||||
|
||||
Task({
|
||||
required this.description,
|
||||
required this.timestamp,
|
||||
this.status = TaskStatus.pending,
|
||||
});
|
||||
|
||||
String getStatusString() {
|
||||
switch (status) {
|
||||
case TaskStatus.pending:
|
||||
return 'В ожидании';
|
||||
case TaskStatus.completed:
|
||||
return 'Завершена';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TaskManager {
|
||||
final List<Task> _tasks = [];
|
||||
|
||||
void addTask(Task task) {
|
||||
_tasks.add(task);
|
||||
print('Задача добавлена: "${task.description}"');
|
||||
}
|
||||
|
||||
void showTasks() {
|
||||
if (_tasks.isEmpty) {
|
||||
print('Список задач пуст.');
|
||||
return;
|
||||
}
|
||||
|
||||
_tasks.asMap().forEach((i, task) {
|
||||
print('${i + 1}. ${task.description} (${task.getStatusString()}) (${task.timestamp.format()})');
|
||||
});
|
||||
}
|
||||
|
||||
void removeTask(int index) {
|
||||
if (index < 1 || index > _tasks.length) {
|
||||
print('Неверный номер задачи.');
|
||||
return;
|
||||
}
|
||||
String removedTask = _tasks[index - 1].description;
|
||||
_tasks.removeAt(index - 1);
|
||||
print('Задача удалена: "$removedTask"');
|
||||
}
|
||||
|
||||
void completeTask(int index) {
|
||||
if (index < 1 || index > _tasks.length) {
|
||||
print('Неверный номер задачи.');
|
||||
return;
|
||||
}
|
||||
_tasks[index - 1].status = TaskStatus.completed;
|
||||
print('Задача "${_tasks[index - 1].description}" выполнена.');
|
||||
}
|
||||
}
|
||||
|
||||
extension DateTimeFormatter on DateTime {
|
||||
String format() {
|
||||
return '${this.day}-${this.month}-${this.year} ${this.hour}:${this.minute}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user