Compare commits

..

No commits in common. "master" and "lab2" have entirely different histories.
master ... lab2

3 changed files with 162 additions and 35 deletions

18
lib/VideoCards.dart Normal file
View File

@ -0,0 +1,18 @@
import 'dart:async';
import 'main.dart';
enum VideoCardsCategory {
Nvidia,
Asus,
Msi,
AMD,
Palit,
}
class VideoCards{
final String videomemory;
final double price;
final VideoCardsCategory category;
VideoCards(this.videomemory, this.price, this.category);
}

View File

@ -0,0 +1,23 @@
import 'VideoCards.dart';
class VideoCardsManager {
final List<VideoCards> _videocards = [];
void addVideoCards(VideoCards videocards) {
_videocards.add(videocards);
}
List<VideoCards> filterVideoCardsByCategory(VideoCardsCategory category) {
return _videocards.where((videocards) => videocards.category == category).toList();
}
double calculateTotalAmount() {
return _videocards.fold(0.0, (sum,videocards) => sum + videocards.price);
}
Future<void> clearVideoCards() async {
await Future.delayed(Duration(seconds: 3));
_videocards.clear();
print('Список чист!');
}
}

View File

@ -1,3 +1,7 @@
import 'dart:math';
import 'dart:async';
import 'VideoCards.dart';
import 'VideoCardsManager.dart';
import 'package:flutter/material.dart';
void main() {
@ -8,63 +12,145 @@ class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Batsylev Vladislav Alexeyevich'),
);
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();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
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;
void _incrementCounter() {
setState(() {
_counter++;
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(
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
backgroundColor: _color,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
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),
),
),
],
),
),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), );
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),
),
],
),
);
}
}
}