diff --git a/lib/main.dart b/lib/main.dart index 2b19b3c..c18748f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -47,116 +47,139 @@ class _MyHomePageState extends State { } } + +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}); + const MyWidget({super.key}); // ключи @override Widget build(BuildContext context) { final data = [ - _CartData( - 'FarCry 1', - descriptionText: 'Читать описание', - imageUrl: - 'https://avatars.mds.yandex.net/i?id=e8dbfc281bbeac76d49d5f83b9b872d9_l-5246113-images-thumbs&n=13', + _CardData( + 'Hello', + descriptionText: 'hshhshs', + imageUrl: 'https://images.stopgame.ru/games/logos/8351/c1536x856/VdQJNv5ECykaiteg212k5g/far_cry_2-square_1.jpg' + ), // создаётся объект ранее созданного контейнера + _CardData( + 'Ivan', + descriptionText: 'hshhshs', + imageUrl: 'https://images.stopgame.ru/games/logos/8351/c1536x856/VdQJNv5ECykaiteg212k5g/far_cry_2-square_1.jpg' + + ), + _CardData( + 'Stepan', + descriptionText: 'hshhshs', + imageUrl: 'https://images.stopgame.ru/games/logos/8351/c1536x856/VdQJNv5ECykaiteg212k5g/far_cry_2-square_1.jpg' + ), - _CartData( - 'FarCry 2', - descriptionText: 'Читать описание', - imageUrl: - 'https://avatars.mds.yandex.net/get-entity_search/2102351/931749212/S600xU_2x'), - _CartData( - 'FarCry 3', - descriptionText: 'Читать описание', - imageUrl: 'https://i.pinimg.com/736x/ab/32/cc/ab32cc12f75b5c304ec88af78c5c0dc3.jpg' - ) ]; return Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: data.map((e) => _Card.fromData(e)).toList(), - ), - ); - } -} - -class _CartData { - final String text; - final String descriptionText; - - final String? imageUrl; - - _CartData( - this.text, { - required this.descriptionText, - this.imageUrl, - }); -} - -class _Card extends StatelessWidget { - final String text; - final String descriptionText; - - final String? imageUrl; - - const _Card( - this.text, { - required this.descriptionText, - this.imageUrl, - }); - - factory _Card.fromData(_CartData data) => _Card( - data.text, - descriptionText: data.descriptionText, - 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: [ - ClipRRect( - borderRadius: BorderRadius.circular(20), - child: SizedBox( - height: 150, - width: 150, - child: Image.network( - imageUrl ?? '', - fit: BoxFit.cover, - errorBuilder: (_, __, ___) => const Placeholder(), - ), - ), - ), - 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, - ) - ], - ), - ), - ), - ], + 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> { + @override + Widget build(BuildContext context) { + return Container( + margin: const EdgeInsets.only(top: 15), + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.orangeAccent, + borderRadius: BorderRadius.circular(20), + border: Border.all( + color: Colors.grey, + width: 2, + ) + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Flexible( + child: ClipRRect( + borderRadius: BorderRadius.circular(20), + child: SizedBox( + height: 140, + width: 100, + child: Image.network( + widget.imageUrl ?? '', + fit: BoxFit.cover, + errorBuilder: (_, __, ___) => const Placeholder(), + ), + ), + )), + Flexible( + child: Padding( + padding: const EdgeInsets.all(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.bodyLarge, + ), + ], + ), + ), + ), + const Spacer(), + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: Icon(widget.icon), + ), + ], + ), + ); + } +} + diff --git a/pubspec.lock b/pubspec.lock index 07514d0..f660c27 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,6 +9,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + bloc: + dependency: "direct main" + description: + name: bloc + sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e" + url: "https://pub.dev" + source: hosted + version: "8.1.4" boolean_selector: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 82726fa..c082266 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -30,6 +30,7 @@ environment: dependencies: flutter: sdk: flutter + bloc: ^8.1.4 # The following adds the Cupertino Icons font to your application.