рабочая 5 лаба.3

This commit is contained in:
salih 2024-12-12 11:39:02 +04:00
parent a97454f8bb
commit af324833e6

View File

@ -29,53 +29,55 @@ class _MyHomePageState extends State<MyHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Scaffold(
padding: EdgeInsets.only(top: MediaQuery body: Padding(
.of(context) padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
.padding child: Column(
.top), children: [
child: Column(children: [ Padding(
Padding( padding: const EdgeInsets.all(12),
padding: const EdgeInsets.all(12), child: CupertinoSearchTextField(
child: CupertinoSearchTextField( controller: searchController,
controller: searchController, style: const TextStyle(color: Colors.white),
style: const TextStyle(color: Colors.white), onSubmitted: (search) {
onSubmitted: (search) { setState(() {
setState(() { data = repo.loadData(q: search);
data = repo.loadData(q: search); });
}); },
},
),
),
Expanded(
child: Center(
child: FutureBuilder<List<MarketData>?>(
future: data,
builder: (context, snapshot) =>
SingleChildScrollView(
child: snapshot.hasData
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: snapshot.data?.map((data) {
return _MarketCard.fromData(
data,
onLike: (String title, bool isLiked) =>
_showSnackBar(context, title, isLiked),
onTap: () => _navToDetails(context, data),
);
}).toList() ??
[],
)
: const CircularProgressIndicator(),
),
), ),
), ),
), Expanded(
])); child: Center(
child: FutureBuilder<List<MarketData>?>(
future: data,
builder: (context, snapshot) => SingleChildScrollView(
child: snapshot.hasData
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: snapshot.data?.map((data) {
return _MarketCard.fromData(
data,
onLike: (String title, bool isLiked) =>
_showSnackBar(context, title, isLiked),
onTap: () => _navToDetails(context, data),
);
}).toList() ??
[],
)
: const CircularProgressIndicator(),
),
),
),
),
],
),
),
);
} }
void _showSnackBar(BuildContext context, String title, bool isLiked) {
void _showSnackBar(BuildContext context, String title, bool isLiked) {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text( content: Text(