import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../domain/models/card.dart'; import '../details_page/details_page.dart'; part 'card.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { final Color _color = const Color(0xFF7BA05B); @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: _color, title: Text(widget.title), ), body: const Body(), ); } } class Body extends StatelessWidget { const Body({super.key}); @override Widget build(BuildContext context) { final data = [ CardData( 'Бенто-торт "Сумерки"', descriptionText: 'И давно тебе 17?', imageUrl: 'https://i.pinimg.com/736x/ef/5a/80/ef5a80844de4afb19750d67f1f5be04d.jpg', ), CardData('Бенто-торт "Material Girl"', descriptionText: 'Главное какой fabric, какой material', imageUrl: 'https://i.pinimg.com/736x/f5/88/0c/f5880cc5b09e602c1849d4093d17eb8e.jpg'), CardData( 'Бенто-торт "Шрек"', descriptionText: 'Somebody once told me the world is gonna roll me', imageUrl: 'https://i.pinimg.com/736x/a9/0d/fb/a90dfb9dfe3b4f4e1c5ce3cb99847a1e.jpg', ), CardData( 'Бенто-торт "Дурак"', descriptionText: 'Сам дурак', imageUrl: 'https://i.pinimg.com/564x/11/87/8a/11878a2f6a0c5d26e38ce68cbbe21337.jpg', ), CardData( 'Бенто-торт "Совунья"', descriptionText: 'Я просто смешариков люблю', imageUrl: 'https://i.pinimg.com/564x/85/61/d2/8561d2b601fe9eb72c4e2031bbb6ba24.jpg', ), CardData( 'Бенто-торт "В смысле 28?"', descriptionText: 'Напишем любой возраст (или срок)', imageUrl: 'https://i.pinimg.com/564x/ae/76/0a/ae760af69d9a0c12938753a372112ee4.jpg', ), ]; return Center( child: SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: data.map((data) { return _Card.fromData( data, onLike: (String title, bool isLiked) => _showSnackBar(context, title, isLiked), onTap: () => _navToDetails(context, data), ); }).toList(), ), )); } void _navToDetails(BuildContext context, CardData data){ Navigator.push( context, CupertinoPageRoute(builder: (context) => DetailsPage(data)), ); } void _showSnackBar(BuildContext context, String title, bool isLiked) { WidgetsBinding.instance.addPostFrameCallback((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( 'Вы ${isLiked ? 'добавили в избранное' : 'убрали из избраных'} $title', style: Theme.of(context).textTheme.bodyLarge, ), backgroundColor: Color(0xFF7BA05B), duration: const Duration(seconds: 1), )); }); } }