import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:pmd_labs/data/repositories/album_repository.dart'; import 'package:pmd_labs/details_page/detail_page.dart'; import 'package:pmd_labs/card_data.dart'; import '../data/dto/album_dto.dart'; part 'card.dart'; class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked "final". final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( backgroundColor: const Color(0xFF231a24), // Цвет фона AppBar title: Text( widget.title, style: Theme.of(context) .textTheme .headlineLarge ?.copyWith(color: Colors.orange), // Цвет текста заголовка ), ), body: Container( color: const Color(0xFF403042), child: const Body(), // Ваш виджет Body ), ); } } class Body extends StatefulWidget { const Body({super.key}); @override State createState() => _BodyState(); } class _BodyState extends State { final AlbumRepository repo = AlbumRepository(); var data = AlbumRepository().loadData(); void _showSnackbar(BuildContext context, String title, bool isLiked) { WidgetsBinding.instance.addPostFrameCallback((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( 'Лайк на $title ${isLiked ? 'поставлен' : 'убран'}', style: Theme .of(context) .textTheme .bodyLarge, ), backgroundColor: Colors.orangeAccent, duration: const Duration(seconds: 1), )); }); } void _navToDetails(BuildContext context, CardData data) { Navigator.push( context, CupertinoPageRoute(builder: (context) => DetailsPage(data))); } @override Widget build(BuildContext context) { return Padding( padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), child: Column( children: [ Padding( padding: const EdgeInsets.all(12), child: CupertinoSearchTextField( onChanged: (search) { setState(() { data = repo.loadData(albumName:search); }); }, style: TextStyle(color: Colors.orange, fontFamily: 'Correction_Tape'), ), ), Expanded(child: Center( child: FutureBuilder?>( future: data, builder: (context, snapshot) => SingleChildScrollView( child: snapshot.hasData ? Column( mainAxisAlignment: MainAxisAlignment.center, children: snapshot.data!.map((data) { return _Card.fromData(data, onLike: (String title, bool isLiked) => _showSnackbar(context, title, isLiked), onTap: () => _navToDetails(context, data),); }).toList() ?? [], ) : const CircularProgressIndicator(), ), ), ), ) ], )); }}