From 0cb17c812b74e15a154cec2109a57e600c58844c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=AF=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=B2?= Date: Tue, 1 Oct 2024 00:21:59 +0400 Subject: [PATCH] lab 3 complete --- lib/main.dart | 151 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 34 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index bd23f56..4ecc3ec 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flutter/material.dart'; void main() { @@ -9,11 +7,13 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - @override + @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', - theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange), + debugShowCheckedModeBanner: false, + theme: ThemeData( + colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange), useMaterial3: true, ), home: const MyHomePage(title: 'Яковлев Максим Григорьевич'), @@ -24,8 +24,6 @@ class MyApp extends StatelessWidget { class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); - - final String title; @override @@ -33,15 +31,7 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - Color _color = Colors.orange; - - void _incrementCounter() { - setState(() { - _counter += 10; - _color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0); - }); - } + final Color _color = Colors.orangeAccent; @override Widget build(BuildContext context) { @@ -50,29 +40,122 @@ class _MyHomePageState extends State { backgroundColor: _color, title: Text(widget.title), ), - body: Center( - child: Column(mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', + body: const MyWidget(), + ); + } +} + +class MyWidget extends StatelessWidget { + const MyWidget({super.key}); + + @override + Widget build(BuildContext context) { + final data = [ + _CartData( + 'Warhammer 40000:Space Marine 2', + descriptionText: 'Читать новость', + imageUrl: + 'https://news.xbox.com/en-us/wp-content/uploads/sites/2/2021/12/SpaceMarine2_TemporaryArtwork_4K_logo.jpg', + ), + _CartData('Risk of rain 2', + descriptionText: 'Читать новость', + imageUrl: + 'https://digiseller.mycdn.ink/preview/990130/p1_3675944_49000546.jpg'), + _CartData( + 'Linage 2', + descriptionText: 'Читать новость', + imageUrl: 'https://avatars.mds.yandex.net/i?id=67f86892afc08862da2521e5b4cf4439_l-9569150-images-thumbs&n=13' + ) + ]; + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: data.map((e) => _Card.fromData(e)).toList(), + ), + ); + } +} + +class _CartData { + final String text; + final String descriptionText; + + //final IconData icon; + final String? imageUrl; + + _CartData( + this.text, { + required this.descriptionText, + //required this.icon, + this.imageUrl, + }); +} + +class _Card extends StatelessWidget { + final String text; + final String descriptionText; + + //final IconData icon; + final String? imageUrl; + + const _Card( + this.text, { + //required this.icon, + required this.descriptionText, + this.imageUrl, + }); + + factory _Card.fromData(_CartData data) => _Card( + data.text, + descriptionText: data.descriptionText, + //icon: data.icon, + imageUrl: data.imageUrl, + ); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Container( + margin: const EdgeInsets.only(top: 16), + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: Colors.orangeAccent, + borderRadius: BorderRadius.circular(20), + border: Border.all(color: Colors.grey, width: 2)), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 140, + width: 150, + child: Image.network( + imageUrl ?? '', + fit: BoxFit.cover, + errorBuilder: (_, __, ___) => const Placeholder(), + ), ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, + Expanded( + child: Padding( + padding: const EdgeInsets.all(10.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + style: Theme.of(context).textTheme.titleLarge, + ), + Text( + descriptionText, + style: Theme.of(context).textTheme.bodyLarge, + ) + ], + ), + ), ), - if (_counter > 200) - Text( - 'Stop clicking!', - style: Theme.of(context).textTheme.headlineMedium, - ) ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - backgroundColor: _color, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), ); + ); } }