Search From 5 (2)
This commit is contained in:
parent
e52ab22a31
commit
3b20f98ff3
@ -42,34 +42,60 @@ 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,
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user