我正在使用BLoC调用API。成功响应后,我需要调用名为
的小部件_moveToHomeScreen()
。 以下是我的代码
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
//body: UserDetail(),
body: new Container(
padding: EdgeInsets.all(16.0),
child:StreamBuilder(
stream: bloc.validateUser,
builder: (BuildContext context, snapshot) {
if(snapshot.hasData){
_moveToHomeScreen();
}
return Column(
children: <Widget>[
_createInputFields(),
_createRegisterButton(),
],
);
}
),
);
}
AND
Widget _moveToHomeScreen () {
print('inside move to home screen');
return Center(
child: Opacity(
opacity: 0.5,
child: Text(
"Save a person to see them here!",
key: Key("Placeholder"),
),
),
);
}
控件进入Widget,但是我无法从Widget中看到所需的输出。
答案 0 :(得分:1)
您的Streambuilder永远不会返回_moveToHomeScreen();
override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
//body: UserDetail(),
body: new Container(
padding: EdgeInsets.all(16.0),
child:StreamBuilder(
stream: bloc.validateUser,
builder: (BuildContext context, snapshot) {
if(snapshot.hasData){
return _moveToHomeScreen();
}
return Column(
children: <Widget>[
_createInputFields(),
_createRegisterButton(),
],
);
}
),
);
}
只需在_moveToHomeScreen();