diff --git a/lib/main.dart b/lib/main.dart index b6621c1..7609c2e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,10 +13,10 @@ class MyApp extends StatelessWidget { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple.shade300), useMaterial3: true, ), - home: const MyHomePage(title: 'Долгова Дарья Николаевна'), + home: const MyHomePage(title: 'Энциклопедия кошек'), ); } } @@ -31,42 +31,145 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - _counter++; - }); - } + final Color _color = Colors.deepPurple.shade300; @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 MyWidget(), ); } } + +class _CardData { + final String text; + final String descriptionText; + final IconData icon; + final String? imageUrl; + + _CardData( + this.text, { + required this.descriptionText, + this.icon = Icons.ac_unit_outlined, + this.imageUrl, + }); +} + +class MyWidget extends StatelessWidget { + const MyWidget({super.key}); // ключи + +@override + Widget build(BuildContext context) { + final data = [ + _CardData( + 'Абиссинская', + descriptionText: 'Эфиопия', + imageUrl: 'https://ajo-pet.ru/u/ckupload/files/abissinskaya-koshka-sorrel.jpg' + ), + _CardData( + 'Британская', + descriptionText: 'Великобритания', + imageUrl: 'https://zoopt.ru/upload/iblock/ce2/britan.png', + ), + _CardData( + 'Невская Маскарадная', + descriptionText: 'СССР', + imageUrl: 'https://wikipet.ru/wp-content/uploads/2018-10/1539243031_1491312430_nev_mask_info.jpg', + ), + ]; + + return Center( + child: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: data.map((e) => _Card.fromData(e)).toList(), + ), + ), + ); +} +} + +class _Card extends StatelessWidget { + 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 + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.only(top: 16), + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.white70, + borderRadius: BorderRadius.circular(20), + border: Border.all(color: Colors.grey), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(.5), + spreadRadius: 4, + offset: const Offset(0, 5), + blurRadius: 8, + ), + ], + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(20), + child: SizedBox( + height: 140, + width: 140, + child: Image.network( + imageUrl ?? '', + fit: BoxFit.cover, + errorBuilder: (_, __, ___) => const Placeholder(), + ), + ), + ), + Expanded( + child: Padding( + padding: const EdgeInsets.only(left: 8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + style: TextStyle(fontSize: 25), + ), + Text( + descriptionText, + style: TextStyle(fontSize: 19), + ), + ], + ), + ), + ), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: Icon(icon), + ), + ], + ), + ); + } +} \ No newline at end of file