我不能同时让TabBarView和BottomNavigationBar控制在我的脚手架主体上显示的内容。使用此代码,TabBarView 或BottomNavigationBar 具有控制权。
我希望能够在所有四个页面之间横向滚动以及选择主页和收藏夹来控制屏幕上显示的内容。
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Traveler"),
bottom: new TabBar(controller: controller, tabs: <Tab>[
new Tab(text: "NEW"),
new Tab(text: "HOTELS"),
new Tab(text: "FOOD"),
new Tab(text: "FUN"),
]),
),
body: new Stack(
children: <Widget>[
new Offstage(
offstage: index != 0,
child: new TickerMode(
enabled: index == 0,
child: new Material(child: new NewPage()),
),
),
new Offstage(
offstage: index != 1,
child: new TickerMode(
enabled: index == 1, …Run Code Online (Sandbox Code Playgroud) 当表单滚动到屏幕外时,如何保存每个表单字段的状态?当我向上滚动并且字段不在屏幕上时,我丢失了在TextFormFields 中输入的值。
我听说过将它保存在控制器中然后分配给 TextFormField 的初始值的建议,如代码所示,但它对我不起作用。我错过了什么?
TextEditingController _controller = new TextEditingController();
@override
Widget build(BuildContext context) {
return new Scaffold(
key: scaffoldKey,
appBar: new AppBar(
title: new Text('Enter Vehicle'),
),
body: new Padding(
padding: const EdgeInsets.all(16.0),
child: new Form(
key: formKey,
child: new ListView(children: <Widget>[
new TextFormField(
decoration: new InputDecoration(labelText: 'Vehicle Number'),
controller: _controller,
initialValue: _controller.text,
),
new TextFormField(
decoration: new InputDecoration(labelText: 'Tag'),
),
new TextFormField(
decoration: new InputDecoration(labelText: 'Make'),
),
new TextFormField(
decoration: new InputDecoration(labelText: 'Model'), …Run Code Online (Sandbox Code Playgroud) flutter ×2