diff --git a/lib/VideoCards.dart b/lib/VideoCards.dart new file mode 100644 index 0000000..53bb90a --- /dev/null +++ b/lib/VideoCards.dart @@ -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); +} \ No newline at end of file diff --git a/lib/VideoCardsManager.dart b/lib/VideoCardsManager.dart new file mode 100644 index 0000000..3ce7b39 --- /dev/null +++ b/lib/VideoCardsManager.dart @@ -0,0 +1,23 @@ +import 'VideoCards.dart'; + +class VideoCardsManager { + final List _videocards = []; + + void addVideoCards(VideoCards videocards) { + _videocards.add(videocards); + } + + List filterVideoCardsByCategory(VideoCardsCategory category) { + return _videocards.where((videocards) => videocards.category == category).toList(); + } + + double calculateTotalAmount() { + return _videocards.fold(0.0, (sum,videocards) => sum + videocards.price); + } + + Future clearVideoCards() async { + await Future.delayed(Duration(seconds: 3)); + _videocards.clear(); + print('Список чист!'); + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 54d9c2b..a374f26 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 createState() => _MyHomePageState(); } -class _MyHomePageState extends State { - int _counter = 0; +extension VideoCardsExtensions on VideoCards { + String get formattedPrice => '${price.toStringAsFixed(2)}'; +} + +class _MyHomePageState extends State { + 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: [ - const Text( - 'You have pushed the button this many times:', + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'Характеристики Видеокарт', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + SizedBox (height: 20), + Expanded( + child: SingleChildScrollView( + child: Column( + children: [ + 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), + ), + ], + ), + ); } -} +} \ No newline at end of file