Flutter 有没有一种方法可以让widget等待在flatter中出现的widget结果
我正试图将ResultMg的值从FutureBuilder小部件传递到文本小部件,但它仍然会给我变量的初始值,有没有办法在之前构建第一个小部件,获取变量更改(即全局变量)并传递它? 或者其他的方法 我张贴我的代码,以显示我所要求的变量Flutter 有没有一种方法可以让widget等待在flatter中出现的widget结果,flutter,widget,Flutter,Widget,我正试图将ResultMg的值从FutureBuilder小部件传递到文本小部件,但它仍然会给我变量的初始值,有没有办法在之前构建第一个小部件,获取变量更改(即全局变量)并传递它? 或者其他的方法 我张贴我的代码,以显示我所要求的变量 child: ListView( shrinkWrap: true, children: <Widget>[ Container( height: 400,
child: ListView(
shrinkWrap: true,
children: <Widget>[
Container(
height: 400,
child: SafeArea(
child: FutureBuilder(
future: _getdeptemp(),
builder: (context, snapshot) {
if (snapshot.hasData) {
int x = (snapshot.data.length);
double xx = double.parse(x.toString());
//some process
resultMsg = ""+Sum ; //*********here is the value I want to assign variable to it**************
return
new charts.LineChart(
seriesList(dataa),
animate: false,
behaviors: [
new charts.ChartTitle('Session number',
behaviorPosition:
charts.BehaviorPosition.bottom,
//titleStyleSpec: charts.TextStyleSpec(fontSize: 14),
titleOutsideJustification: charts
.OutsideJustification.middleDrawArea),
new charts.ChartTitle(
'Right Pose Percentage, %',
behaviorPosition:
charts.BehaviorPosition.start,
//titleStyleSpec: chartsCommon.TextStyleSpec(fontSize: 11),
titleOutsideJustification: charts
.OutsideJustification.middleDrawArea)
],
);
} else {
return Center(child: CircularProgressIndicator());
}
}),
)),
Container(
child: new Text(
resultMsg,//////here is the variable ******
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
)),
],
),
child:ListView(
收缩膜:对,
儿童:[
容器(
身高:400,
儿童:安全区(
孩子:未来建设者(
未来:_getdeptemp(),
生成器:(上下文,快照){
if(snapshot.hasData){
intx=(snapshot.data.length);
double xx=double.parse(x.toString());
//一些过程
resultsg=”“+Sum;//**********这是我要为其分配变量的值**********
返回
新图表。折线图(
系列列表(dataa),
动画:假,
行为:[
新图表。图表标题('会议编号',
行为定位:
charts.BehaviorPosition.bottom,
//titleStyleSpec:charts.TextStyleSpec(字体大小:14),
标题外部对齐:图表
.外部对正.中间抽气区域),
新图表。图表标题(
'右姿势百分比,%',
行为定位:
charts.BehaviorPosition.start,
//titleStyleSpec:chartsCommon.TextStyleSpec(fontSize:11),
标题外部对齐:图表
.外部对正.中间抽油区)
],
);
}否则{
返回中心(子项:CircularProgressIndicator());
}
}),
)),
容器(
儿童:新文本(
resultsg,/////这是变量******
样式:TextStyle(
颜色:颜色,黑色,
尺寸:16,
),
)),
],
),
如果要在其他小部件上使用FutureBuilder的数据值,将该小部件插入FutureBuilder内部怎么样?
在本例中,您需要按列小部件包装折线图和容器小部件
I just suggest but I don't know whether the error is because I don't have all source.
<As-is>
-ListView
--FutureBuilder
---LineChart
--Container
---Text
<To-be>
-ListView
--FutureBuilder
---Column
----LineChart
----Container
-----Text
or
-FutureBuilder
--ListView
---LineChart
---Container
----Text
我只是建议,但我不知道错误是否是因为我没有所有的来源。
-列表视图
--未来建设者
---线条图
--容器
---正文
-列表视图
--未来建设者
---纵队
----线条图
----容器
-----正文
或
-未来建设者
--列表视图
---线条图
---容器
----正文
下面是基于您的代码的建议代码,如“To be”。ListView(
shrinkWrap: true,
children: <Widget>[
Container(
height: 400,
child: SafeArea(
child: FutureBuilder(
future: _getdeptemp(),
builder: (context, snapshot) {
if (snapshot.hasData) {
int x = (snapshot.data.length);
double xx = double.parse(x.toString());
//some process
resultMsg = ""+Sum ; //*********here is the value I want to assign variable to it**************
return Column(
children: [
new charts.LineChart(
seriesList(dataa),
animate: false,
behaviors: [
new charts.ChartTitle('Session number',
behaviorPosition:
charts.BehaviorPosition.bottom,
//titleStyleSpec: charts.TextStyleSpec(fontSize: 14),
titleOutsideJustification: charts
.OutsideJustification.middleDrawArea),
new charts.ChartTitle(
'Right Pose Percentage, %',
behaviorPosition:
charts.BehaviorPosition.start,
//titleStyleSpec: chartsCommon.TextStyleSpec(fontSize: 11),
titleOutsideJustification: charts
.OutsideJustification.middleDrawArea)
],
),
Container(
child: new Text(
resultMsg,//////here is the variable ******
style: TextStyle(
color: Colors.black,
fontSize: 16,
),
),
),
],
);
} else {
return Center(child: CircularProgressIndicator());
}
}),
)),
],
);
ListView(
收缩膜:对,
儿童:[
容器(
身高:400,
儿童:安全区(
孩子:未来建设者(
未来:_getdeptemp(),
生成器:(上下文,快照){
if(snapshot.hasData){
intx=(snapshot.data.length);
double xx=double.parse(x.toString());
//一些过程
resultsg=”“+Sum;//**********这是我要为其分配变量的值**********
返回列(
儿童:[
新图表。折线图(
系列列表(dataa),
动画:假,
行为:[
新图表。图表标题('会议编号',
行为定位:
charts.BehaviorPosition.bottom,
//titleStyleSpec:charts.TextStyleSpec(字体大小:14),
标题外部对齐:图表
.外部对正.中间抽气区域),
新图表。图表标题(
'右姿势百分比,%',
行为定位:
charts.BehaviorPosition.start,
//titleStyleSpec:chartsCommon.TextStyleSpec(fontSize:11),
标题外部对齐:图表
.外部对正.中间抽油区)
],
),
容器(
儿童:新文本(
resultsg,/////这是变量******
样式:TextStyle(
颜色:颜色,黑色,
尺寸:16,
),
),
),
],
);
}否则{
返回中心(子项:CircularProgressIndicator());
}
}),
)),
],
);
将带有文本的容器resultsg
作为FutureBuilder的一部分,这意味着您将仅在从FutureBuilder获得结果时渲染此容器,或者不是这样?