Search From 5 (2)

This commit is contained in:
Serxiolog 2024-11-18 16:34:42 +04:00
parent e52ab22a31
commit 3b20f98ff3

View File

@ -42,13 +42,26 @@ class _MyHomePageState extends State<MyHomePage> {
);
}
}
class Body extends StatelessWidget {
class Body extends StatefulWidget {
const Body({super.key});
@override
State<Body> createState() => _BodyState();
}
class _BodyState extends State<Body> {
final AnimeRepository repos = AnimeRepository();
final searchController = TextEditingController();
late Future<List<CardData>?> data;
@override
void initState() {
data = repos.loadData();
super.initState();
}
@override
Widget build(BuildContext context) {
final data = AnimeRepository().loadData();
return Center(
child: FutureBuilder<List<CardData>?>(
future: data,
@ -56,7 +69,19 @@ class Body extends StatelessWidget {
child: snapshot.hasData
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: snapshot.data!.map(
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,
@ -65,7 +90,8 @@ class Body extends StatelessWidget {
onTap: () => _navToDetails(context, e),
);
},
).toList(),
).toList()
],
)
: const CircularProgressIndicator(),
),