在库中的地图扑面而出执行提供商
我将我的提供商与FutureBuilder组件分离为库映射,以便可以将其用作动态和可重复使用的内容。这是看起来的简短版本:
page.dart(library)
library myproj;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '--path/to/my/provider'
Map<String, dynamic> firstPage = {
'text': 'This is the first page',
'action': <Map<String, dynamic>>[
{
'text': 'Next Page',
'page': 2,
'provider': (BuildContext context) =>
Provider.of<Pages>(context, listen: false).checkNextPageCondition()
}
]
};
component.dart(使用库的组件)
{
...,
FutureBuilder(
future: isolate-function(),
initialData: {...},
builder:(BuildContext context, AsyncSnapshot snapshot){
return Column(
children:[
for(var el in snapshot.data['action']) TextButton(
onPressed:(){
el['provider'];
},
child: Text(el['text'])
)
]
)
}
)
}
这是大量编辑的代码,但是我是什么我正在尝试在这里实现,是将provider。我在提供商中定义的功能。但是,当我单击按钮时,什么也不会发生,并且在调试控制台中没有显示任何错误。
I am separating my Provider from FutureBuilder components into library Map so that I can use it as dynamic and reusable content. Here is the short version of how it look:
page.dart (library)
library myproj;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '--path/to/my/provider'
Map<String, dynamic> firstPage = {
'text': 'This is the first page',
'action': <Map<String, dynamic>>[
{
'text': 'Next Page',
'page': 2,
'provider': (BuildContext context) =>
Provider.of<Pages>(context, listen: false).checkNextPageCondition()
}
]
};
component.dart(component that use the library)
{
...,
FutureBuilder(
future: isolate-function(),
initialData: {...},
builder:(BuildContext context, AsyncSnapshot snapshot){
return Column(
children:[
for(var el in snapshot.data['action']) TextButton(
onPressed:(){
el['provider'];
},
child: Text(el['text'])
)
]
)
}
)
}
This has been heavily redacted code, but what I am trying to achieve here, is to pass the Provider.of<Pages>(context, listen: false).checkNextPageCondition()
to the TextButton onPressed
so it can trigger the function that I have defined in my Provider. But when I click the button, nothing happened, and there isn't a single error showing up in the debug console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试一下
Try this