2024-11-13 04:43:37 +04:00
|
|
|
import 'dart:math';
|
|
|
|
import 'dart:async';
|
|
|
|
import 'VideoCards.dart';
|
|
|
|
import 'VideoCardsManager.dart';
|
2024-11-12 23:23:42 +04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(const MyApp());
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
const MyApp({super.key});
|
|
|
|
|
|
|
|
@override
|
2024-11-13 04:43:37 +04:00
|
|
|
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: 'Бацылев Владислав Алексеевич'),
|
|
|
|
);
|
|
|
|
}
|
2024-11-12 23:23:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({super.key, required this.title});
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
2024-11-13 04:43:37 +04:00
|
|
|
extension VideoCardsExtensions on VideoCards {
|
|
|
|
String get formattedPrice => '${price.toStringAsFixed(2)}';
|
|
|
|
}
|
|
|
|
|
2024-11-12 23:23:42 +04:00
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2024-11-13 04:43:37 +04:00
|
|
|
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;
|
2024-11-12 23:23:42 +04:00
|
|
|
|
|
|
|
setState(() {
|
2024-11-13 04:43:37 +04:00
|
|
|
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;
|
|
|
|
}
|
2024-11-12 23:23:42 +04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-13 04:43:37 +04:00
|
|
|
return Scaffold(
|
2024-11-12 23:23:42 +04:00
|
|
|
appBar: AppBar(
|
2024-11-13 04:43:37 +04:00
|
|
|
backgroundColor: _color,
|
|
|
|
title: Text(widget.title),
|
2024-11-12 23:23:42 +04:00
|
|
|
),
|
|
|
|
body: Center(
|
2024-11-13 04:43:37 +04:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
2024-11-12 23:23:42 +04:00
|
|
|
),
|
2024-11-13 04:43:37 +04:00
|
|
|
],
|
2024-11-12 23:23:42 +04:00
|
|
|
),
|
|
|
|
),
|
2024-11-13 04:43:37 +04:00
|
|
|
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),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2024-11-12 23:23:42 +04:00
|
|
|
}
|
2024-11-13 04:43:37 +04:00
|
|
|
}
|