diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart index 06812a6..fb6abee 100644 --- a/lib/presentation/home_page/home_page.dart +++ b/lib/presentation/home_page/home_page.dart @@ -42,34 +42,60 @@ class _MyHomePageState extends State { ); } } - -class Body extends StatelessWidget { +class Body extends StatefulWidget { const Body({super.key}); + @override + State createState() => _BodyState(); +} + +class _BodyState extends State { + final AnimeRepository repos = AnimeRepository(); + final searchController = TextEditingController(); + late Future?> data; + + @override + void initState() { + data = repos.loadData(); + super.initState(); + } + @override Widget build(BuildContext context) { - final data = AnimeRepository().loadData(); return Center( child: FutureBuilder?>( future: data, builder: (context, snapshot) => SingleChildScrollView( child: snapshot.hasData ? Column( - mainAxisAlignment: MainAxisAlignment.center, - children: snapshot.data!.map( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( + padding: const EdgeInsets.all(8), + child: CupertinoSearchTextField( + controller: searchController, + onChanged: (search) { + setState(() { + data = repos.loadData(q : search); + }); + }, + ), + ), + ...snapshot.data!.map( (e) { - return _Card.fromData( - e, - onLike: (String title, bool isLiked) => - _showLiked(context, title, isLiked), - onTap: () => _navToDetails(context, e), - ); - }, - ).toList(), - ) + return _Card.fromData( + e, + onLike: (String title, bool isLiked) => + _showLiked(context, title, isLiked), + onTap: () => _navToDetails(context, e), + ); + }, + ).toList() + ], + ) : const CircularProgressIndicator(), - ), - )); + ), + )); } void _navToDetails(BuildContext context, CardData data) {