我正在寻找从链接到bottomNavigationBar的主体更新脚手架中的Text小部件的方法。
“文本”窗口小部件包含状态消息(“今天天气很好。” bottomNavigationBar有3个项目。其中只有一个具有RefreshIndicator,该指示器可获取最新的天气信息,该信息应用于更新状态消息。无法完成此操作,因为我不知道如何从bottomNavigationBar的子页面更新“文本”小部件中的消息。
这是我的文件,其中包含“文本”小部件和bottomNavigationBar:
...
final List<BottomNavigationBarItem> bottomTabs = [
new BottomNavigationBarItem(
icon: new Icon(CupertinoIcons.home), title: new Text('Home')),
new BottomNavigationBarItem(
icon: new Icon(CupertinoIcons.book), title: new Text('Contact')),
new BottomNavigationBarItem(
icon: new Icon(CupertinoIcons.settings), title: new Text('Settings'))
];
...
int _currentIndex = 0;
final List<Widget> _children = [
new HomeRoute(),
new ContactRoute(),
new SettingsRoute()
];
...
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () {},
)
],
expandedHeight: 200.0,
elevation: 0.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("Weather Status",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(_overallBusStatus,
style:
TextStyle(color: Colors.white, fontSize: 16.0)),
],
)),
),
];
},
body: _children[_currentIndex], // new
),
bottomNavigationBar: BottomNavigationBar(
onTap: onTabTapped, // new
currentIndex: _currentIndex, // new
items: bottomTabs,
type: BottomNavigationBarType.fixed,
),
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
以及HomeRoute的内容:
...
@override
Widget build(BuildContext context) {
return new Container(
child: new RefreshIndicator(
child: new ListView(
children: _getCards(),
padding: EdgeInsets.all(0.0),
),
onRefresh: _refreshHome,
),
);
}
...
Future<void> _refreshHome() async {
print('Refreshing...');
Future future = getWeather();
future.then((result) => updateWeatherStatus(result));
}
谢谢你, 约瑟夫