【发布时间】:2018-09-13 11:09:36
【问题描述】:
这是我想做的。当 MenuScreen 的 checkboxListTile 被选中时,父屏导航按钮改变状态来切换一些文本。
多选,无导航弹回。
没有异步功能,InheritedWidget 似乎没有任何更新事件。
我从来没有找到全局变量 onChange Listener,也许我应该知道。
import 'package:flutter/material.dart';
class SandBoxScreen extends StatefulWidget {
@override
SandBoxState createState() => SandBoxState();
}
class SandBoxState extends State<SandBoxScreen> with TickerProviderStateMixin {
@override
void initState() {
super.initState();
}
bool isSelected = false;
@override
Widget build(BuildContext context) {
String nextText = isSelected ? 'next' : 'plz select';
return new Scaffold(
appBar: AppBar(),
body: new Container(
child:Column(children: <Widget>[
_MenuSelection(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
RaisedButton(child:Text('prev')),
RaisedButton(child:Text(nextText)),
],
)
],)
)
);
}
}
class _MenuSelection extends StatefulWidget{
@override
_MenuState createState() => _MenuState();
}
class _MenuState extends State<_MenuSelection>{
List<bool> selection = [false,false,false,false];
@override
Widget build(BuildContext context) {
return Container(child:Column(
children: <Widget>[
CheckboxListTile(value: selection[0], onChanged: (a){setState(() { selection[0] = a; });} , title: Text('item1'),),
CheckboxListTile(value: selection[1], onChanged: (a){setState(() { selection[1] = a; });} , title: Text('item2'),),
CheckboxListTile(value: selection[2], onChanged: (a){setState(() { selection[2] = a; });} , title: Text('item3'),),
CheckboxListTile(value: selection[3], onChanged: (a){setState(() { selection[3] = a; });} , title: Text('item4'),),
],
));
}
}
【问题讨论】: