请帮我实现这个方法,我是 Flutter 的新手。
如何使用 Provider 来实现
(不仅 Provider 是可能的,对我来说最主要的是了解如何在实践中实现和应用)
当您单击“购买”按钮时(在本例中我只有一个),从列表中传输数据,仅“Orange”*(如果“Mandarin”-则数据“Mandarin”)*
同时,如果您单击“下订单”按钮,则会删除第一个屏幕中的数据。
List <String> Name = ['Апельсин', 'Мандарин', 'Помидор'];
List <int> Price = [70,60,80];
class MainApp extends StatelessWidget {
const MainApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Main'),
),
body: ListView.builder(
itemCount: Name.length,
itemBuilder: (BuildContext context, int index) {
return Card(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(left: 10, top: 50, bottom: 50),
child: Text(Name[index].toString()),
),
Row(children: [
Padding(
padding: EdgeInsets.only(left: 100, top: 50, bottom: 50),
child: Text(Price[index].toString()),
),
Padding(
padding: const EdgeInsets.only(left: 100),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(onPressed: (){Navigator.push(context,
CupertinoPageRoute(builder: (context) => const SalePage()));}, child: const
Text('Купить')),
],
),
)
]),
],
),
);
},
),
);
}
}