[英]Future builder not firing
我似乎無法讓我未來的建設者更新。 api 響應工作正常,我可以在日志中看到它。 ( model.getSuburbs
)。 但我在 FutureBuilder suburbs
的未來似乎沒有做任何事情。我是否遺漏了一些明顯的東西(當我輸入最后一個數字並觸發 api 時觸發了onSubmit
)
class PostcodePage extends StatefulWidget {
static Route<dynamic> route() {
return MaterialPageRoute(
builder: (BuildContext context) => PostcodePage(),
);
}
@override
_PostcodeScreenState createState() => _PostcodeScreenState();
}
class _PostcodeScreenState extends State<PostcodePage> {
PostcodeViewmodel model = serviceLocator<PostcodeViewmodel>();
Future<List<Suburb>> suburbs;
String postCode;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.all(32),
child: Column(children: [
SizedBox(height: 200),
PinEntryField(
onSubmit: (input) => getSub(pc: input),
),
FutureBuilder<List<Suburb>>(
future: suburbs,
builder: (context, snapshot) {
if (snapshot.connectionState==ConnectionState.active) {
return Text('Would Like something here...');
} else
return Text('But always end up here...');
},
),
// (postCode != null) Text(postCode),
SizedBox(
height: 300,
),
SizedBox(
width: double.maxFinite,
child: OnBoardingButton(
text: 'Begin',
onPressed: () {},
color: Color(0xff00E6B9),
),
),
]),
),
);
}
getSub({String pc}) {
setState(() {
suburbs = model.getSuburbs(country: 'au', postcode: pc);
});
}
}
嘗試在構建器中更改您的條件。
這段代碼snapshot.connectionState==ConnectionState.active
可能真的很短,具體取決於郊區的未來。
請在構建器中嘗試此操作。
if (snapshot.hasData) {
return Text('Would Like something here...');
} else {
return Text('But always end up here...');
}
你找到解決方案了嗎? 我面臨同樣的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.