PMU_BTSYLEV_V.A_PIbd-32/lib/main.dart
2024-11-13 04:43:37 +04:00

156 lines
4.7 KiB
Dart

import 'dart:math';
import 'dart:async';
import 'VideoCards.dart';
import 'VideoCardsManager.dart';
import 'package:flutter/material.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.teal),
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();
}
extension VideoCardsExtensions on VideoCards {
String get formattedPrice => '${price.toStringAsFixed(2)}';
}
class _MyHomePageState extends State<MyHomePage> {
Color _color = Colors.grey;
final VideoCardsManager _videoCardsManager = VideoCardsManager();
bool _isClearing = false;
int counter = 2;
void _addRandomVideocards() {
final random = Random();
final videomemory = '$counter Gb';
final price = random.nextDouble() * 15000;
final category = VideoCardsCategory.values[random.nextInt(
VideoCardsCategory.values.length)];
final videocards = VideoCards(videomemory, price, category);
_videoCardsManager.addVideoCards(videocards);
counter = counter + 2;
setState(() {
switch (category) {
case VideoCardsCategory.Nvidia:
_color = Colors.green;
case VideoCardsCategory.Asus:
_color = Colors.blue;
case VideoCardsCategory.Msi:
_color = Colors.red;
case VideoCardsCategory.AMD:
_color = Colors.redAccent;
case VideoCardsCategory.Palit:
_color = Colors.brown;
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: _color,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Характеристики Видеокарт',
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
SizedBox (height: 20),
Expanded(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
for (var category in VideoCardsCategory.values)
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Видеокарты: ${category.name}',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
for (var videocards in _videoCardsManager.filterVideoCardsByCategory(category))
Text(
'${videocards.videomemory} - Цена: ${videocards.formattedPrice} рублей.',
style: const TextStyle(fontSize: 18),
),
SizedBox(height: 10),
],
),
if (_isClearing)
const Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Очищение списка...',
style: TextStyle(fontSize: 18, color: Colors.blueGrey),
),
),
],
),
),
),
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FloatingActionButton(
onPressed: () async {
_addRandomVideocards();
},
backgroundColor: _color,
child: const Icon(Icons.add),
),
SizedBox(width: 10),
FloatingActionButton(
onPressed: () async {
setState(() {
_isClearing = true;
});
await _videoCardsManager.clearVideoCards();
setState(() {
_isClearing = false;
});
},
backgroundColor: Colors.red,
child: const Icon(Icons.clear),
),
],
),
);
}
}