我可以在MultiProvider中使用Future Provider吗?但它可以从API中解决这两个问题



我正在尝试使用flutter提供程序包,我有一个API,我想在其中获取传输类型和路由标题的数据(它是Marshes类(。如果我想使用mu,我决定使用Future Providerans;提示我需要在widhet树顶部的主故障中使用MultiProvider。我做了与文档中描述的相同的操作,但现在我有一个错误:";生成Home时引发了以下ProviderNotFoundException(脏(:错误:找不到正确的提供程序<列表>在这个家庭小部件之上";

所以问题是:我可以在多提供者中使用未来提供者吗正如我在下面的代码中所做的那样。

我真的不明白我的错误在哪里

主文件:

Widget build(BuildContext context) {
return MultiProvider(
providers: [
FutureProvider(
create: (context) => transportService.fetchTranspot(),
initialData: [],
catchError: (context, error) {
print(error.toString());
},
),
FutureProvider(
create: (context) => transportService.fetchMarshes(),
catchError: (context, error) {
print(error.toString());
},
initialData: [],
),
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
),

另一种用于运输类型:

List<TransportType> transport = Provider.of<List<TransportType>>(context);
return Scaffold(
appBar: AppBar(title: Text('Employees'),
),
body: (transport == null)
? Center(child: CircularProgressIndicator(),)
: ListView.builder(
itemCount: transport.length,
itemBuilder: (context,index){
return ListTile(
title: Text(transport[index].ttTitle),

沼泽地也是如此。我想把它作为列表

final int ttId;
final TransportService transportService = TransportService();
EmployeePage({@required this.ttId});
@override
Widget build(BuildContext context) {
List<Marshes> marsh = Provider.of<List<Marshes>>(context);
return Scaffold(
appBar: AppBar(title: Text('Employees'),
),
body: (marsh == null)
? Center(child: CircularProgressIndicator(),)
: ListView.builder(
itemCount: marsh.length,
itemBuilder: (context,index){
return ListTile(
title: Text(marsh[index].mrTitle),

您没有指定FutureBuilder的类型,例如:

providers: [
FutureProvider(

应该是:

providers: [
FutureProvider<List<TransportType>>(

最新更新