From 40206d942bc168fbd87a2ed73ad7e3ec394b06df Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 23 Oct 2024 17:29:32 +0400 Subject: [PATCH] feat(lab3): do lab3 --- lib/main.dart | 167 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 141 insertions(+), 26 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index d1d727e..ad919fb 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -30,40 +30,155 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - _counter++; - }); - } + final Color _color = Colors.redAccent; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, + backgroundColor: _color, title: Text(widget.title), ), - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), + body: const Center( + child: MyWidget() ), ); } } + +class MyWidget extends StatelessWidget { + const MyWidget({super.key}); + + @override + Widget build(BuildContext context) { + final data = [ + _CardData( + 'Oh?', + description: 'pain', + icon: Icons.add_box, + imageUrl: 'https://www.thespruceeats.com/thmb/QjCQ4RTjmnhrovGkuJWzZCXYFX8=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/GettyImages-90053856-588b7aff5f9b5874ee534b04.jpg', + ), + _CardData( + 'Freeze?', + description: 'suffering', + icon: Icons.ac_unit_sharp, + imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTwgAMeszx47tsBuUK20XIByglQcnAZCOEQJw&s', + ), + _CardData( + 'Hi?', + description: 'horror', + icon: Icons.access_alarms, + imageUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRsya6wSRjwvxaWlZEKn0U7gW6F2PWI54D6hw&s', + ), + ]; + return Center( + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: data.map((_CardData x) => _Card.fromData(x)).toList(), + ), + ), + ), + ); + } +} + +class _CardData { + final String text; + final String description; + final IconData icon; + final String? imageUrl; + + _CardData(this.text, { + required this.description, + this.icon = Icons.icecream, + this.imageUrl, + }); +} + +class _Card extends StatelessWidget { + final String text; + final String description; + final IconData icon; + final String? imageUrl; + + const _Card(this.text, { + required this.description, + this.icon = Icons.icecream, + this.imageUrl, + }); + + factory _Card.fromData(_CardData data) => _Card( + data.text, + description: data.description, + icon: data.icon, + imageUrl: data.imageUrl, + ); + + @override + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.only(top: 16), + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.orangeAccent, + borderRadius: BorderRadius.circular(20), + border: Border.all( + color: Colors.redAccent, + width: 4, + ), + boxShadow: [ + BoxShadow( + color: Colors.redAccent.withOpacity(.6), + spreadRadius: 4, + offset: const Offset(0, 5), + blurRadius: 8, + ), + ], + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(20), + child: SizedBox( + height: 140, + width: 100, + child: Image.network( + fit: BoxFit.cover, + imageUrl ?? '', + errorBuilder: (_, __, ___) => const Placeholder(), + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + style: Theme.of(context).textTheme.headlineLarge, + ), + Text( + description, + style: Theme.of(context).textTheme.bodyLarge, + ), + ], + ), + ), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Icon(icon), + ), + ], + ), + ); + } +} +