From c42cbed29fbac2c10e864e2b00be189ae6063e82 Mon Sep 17 00:00:00 2001 From: Nastya_Kozlova Date: Sun, 6 Oct 2024 21:18:07 +0400 Subject: [PATCH] =?UTF-8?q?=D1=82=D1=80=D0=B5=D1=82=D1=8C=D1=8F=20labs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.dart | 188 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 153 insertions(+), 35 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 1f8a54f..4b26c94 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,8 +13,7 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( - - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + colorScheme: ColorScheme.fromSeed(seedColor: Colors.black), useMaterial3: true, ), home: const MyHomePage(title: 'настя'), @@ -32,48 +31,167 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - - _counter++; - }); - } + final Color _color = Colors.black; @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), - ), // This trailing comma makes auto-formatting nicer for build methods. + body: const MyWidget(), ); } } +class _CardData { + final String text; + final String descriptionText; + final IconData icon; + final String? imageUrl; + _CardData( + this.text, { + required this.descriptionText, + required this.icon, + this.imageUrl, + }); +} + +class MyWidget extends StatelessWidget { + const MyWidget({super.key}); + + @override + Widget build(BuildContext context) { + final data = [ + _CardData( + 'bebebe', + descriptionText: 'sldmk', + icon: Icons.hail, + imageUrl: 'https://img.freepik.com/free-photo/smiley-woman-talking-phone-medium-shot_23-2149476757.jpg?t=st=1727894827~exp=1727898427~hmac=a14045ebfb7ed48343615c31db970b30b086a5ddadaa428601b7534e37540b4a&w=996', + ), + _CardData( + 'sdde', + descriptionText: 'ssdmk', + icon: Icons.hail, + imageUrl: 'https://img.freepik.com/free-photo/medium-shot-women-with-delicious-food_23-2150168102.jpg?t=st=1727895736~exp=1727899336~hmac=3260118fc2bd6fe946f54465e104629fe046384f621e8393e1f9f557392f7dad&w=996', + ), + _CardData( + 'aaae', + descriptionText: 'ssldmk', + icon: Icons.hail, + imageUrl: 'https://img.freepik.com/free-photo/high-angle-smiley-woman-sitting-table_23-2150168074.jpg?t=st=1727895785~exp=1727899385~hmac=880ec7fcf220143947d4f276490c4338c1828c7920540a1efc2503c4cc791aec&w=360', + ), + ]; + return Center( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: data.map((e) => _Card.fromData(e)).toList(), + ), + ), + ); + } +} + +class _Card extends StatefulWidget { + final String text; + final String descriptionText; + final IconData icon; + final String? imageUrl; + + const _Card(this.text, { + this.icon = Icons.ac_unit_outlined, + required this.descriptionText, + this.imageUrl + }); + + factory _Card.fromData(_CardData data) => + _Card( + data.text, + descriptionText: data.descriptionText, + icon: data.icon, + imageUrl: data.imageUrl, + ); + + @override + State<_Card> createState() => _CardState(); +} + +class _CardState extends State<_Card> { + bool isLiked = false; + @override + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.all(20), + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: Colors.white70, + borderRadius: BorderRadius.circular(20), + border: Border.all( + color: Colors.blueGrey, + ), + + ), + child: IntrinsicHeight( + child: Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(20), + child: SizedBox( + height: 140, + width: 100, + child: Image.network( + widget.imageUrl ?? '', + fit: BoxFit.cover, + errorBuilder: (_, __, ___) => const Placeholder(), + ), + ), + ), + + Expanded( + child: Padding( + padding: const EdgeInsets.only(left: 8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + widget.text, + style: Theme.of(context).textTheme.headlineLarge, + ), + Text( + widget.descriptionText, + style: Theme.of(context).textTheme.headlineSmall, + ), + ], + ), + ), + ), + Align( + alignment: Alignment.bottomRight, + child: Padding( + padding: const EdgeInsets.only( + left: 8.0, + right: 16, + bottom: 16 + ), + child: GestureDetector( + onTap: () { + setState(() { + isLiked = !isLiked; + }); + }, + child: Icon( + isLiked ? Icons.favorite : Icons.favorite_border + ), + ), + ), + ) + ], + ), + ), + ); + } +}