Flutter 当小部件不可见时,选项卡正在移动
我是新来的,所以也许我的问题对某些人来说是基本的 问题是,在我的应用程序中,当复选框未选中时,我想隐藏文本字段。文本字段旁边是一个按钮,它应该是静态的。我的问题是,当我想隐藏这个文本字段时,按钮会移到左侧。我认为最好的选择是展示给你看 之前: 之后: 这是我正在使用的代码:Flutter 当小部件不可见时,选项卡正在移动,flutter,widget,show-hide,shift,Flutter,Widget,Show Hide,Shift,我是新来的,所以也许我的问题对某些人来说是基本的 问题是,在我的应用程序中,当复选框未选中时,我想隐藏文本字段。文本字段旁边是一个按钮,它应该是静态的。我的问题是,当我想隐藏这个文本字段时,按钮会移到左侧。我认为最好的选择是展示给你看 之前: 之后: 这是我正在使用的代码: bool secondLayer = false; void _secondLayer(bool value) => setState(() => secondLayer = value); @overri
bool secondLayer = false;
void _secondLayer(bool value) => setState(() => secondLayer = value);
@override
Widget build(BuildContext context) {
return new Scaffold(
/*appBar: new AppBar(
title: new Text('Name Here'),
),*/
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(
child: new Container(
padding: new EdgeInsets.all(32.0),
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
child: new Row(
children: <Widget>[
Expanded(
child: Column(
children: <Widget>[
new TextField(
decoration: InputDecoration(
labelText: 'First Hidden Layer',
hintText: '25',
),
autocorrect: true,
autofocus: true,
keyboardType: TextInputType.number,
),
],
),
),
Expanded(
child: Column(
children: <Widget>[
new SizedBox(
width: 100,
child: new RaisedButton(onPressed: null, child: new Text('ADD DATA'),)
)
],
),
)
],
),
),
Container(
child: new CheckboxListTile(
value: secondLayer,
onChanged: _secondLayer,
title: new Text(
'Use Second Hidden Layer',
style: new TextStyle(
fontSize: 12
),
),
controlAffinity: ListTileControlAffinity.leading,
),
),
Container(
child: new Row(
children: <Widget>[
Visibility(
visible: secondLayer,
child: new Expanded(
child: Column(
children: <Widget>[
new TextField(
decoration: InputDecoration(
labelText: 'Second Hidden Layer',
hintText: '25',
),
autocorrect: true,
autofocus: true,
keyboardType: TextInputType.number,
),
],
),
),
),
Expanded(
child: Column(
children: <Widget>[
new SizedBox(
width: 100,
child: new RaisedButton(onPressed: null, child: new Text('OPTIONS'),)
)
],
),
)
],
),
),
Container(
child: new TextField(
decoration: InputDecoration(
labelText: 'Epochs',
hintText: '5000',
),
autocorrect: true,
autofocus: true,
keyboardType: TextInputType.number,
),
),
Container(
child: new TextField(
decoration: InputDecoration(
labelText: 'Learning Rate',
hintText: '0.00333',
),
autocorrect: true,
autofocus: true,
keyboardType: TextInputType.number,
),
),
Container(
padding: EdgeInsets.only(top: 20),
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width/3,
height: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: Border.all(color: Color.fromRGBO(0, 0, 0, 100)),
),
child: new Text('data')
),
Container(
width: MediaQuery.of(context).size.width/3,
height: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: Border.all(color: Color.fromRGBO(0, 0, 0, 100)),
),
child: new Text('data')
)
],
)
)
],
),
)
)
)
);
boolsecondlayer=false;
void _secondLayer(bool值)=>setState(()=>secondLayer=value);
@凌驾
小部件构建(构建上下文){
归还新脚手架(
/*appBar:新的appBar(
标题:新文本(“此处的名称”),
),*/
resizeToAvoidBottomInset:false,
正文:SingleChildScrollView(
子容器:新容器(
填充:新边缘设置。全部(32.0),
孩子:新中心(
子:新列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
容器(
孩子:新的一排(
儿童:[
扩大(
子:列(
儿童:[
新文本字段(
装饰:输入装饰(
labelText:“第一个隐藏层”,
hintText:'25',
),
自动更正:正确,
自动对焦:对,
键盘类型:TextInputType.number,
),
],
),
),
扩大(
子:列(
儿童:[
新尺寸盒子(
宽度:100,
子项:新建RaisedButton(按下时:null,子项:新建文本(‘添加数据’),)
)
],
),
)
],
),
),
容器(
子项:新CheckboxListTile(
值:第二层,
一旦更改:_第二层,
标题:新文本(
“使用第二个隐藏层”,
样式:新文本样式(
字体大小:12
),
),
controlAffinity:ListTileControlAffinity.leading,
),
),
容器(
孩子:新的一排(
儿童:[
可见度(
可见:第二层,
儿童:新扩大(
子:列(
儿童:[
新文本字段(
装饰:输入装饰(
labelText:“第二个隐藏层”,
hintText:'25',
),
自动更正:正确,
自动对焦:对,
键盘类型:TextInputType.number,
),
],
),
),
),
扩大(
子:列(
儿童:[
新尺寸盒子(
宽度:100,
子项:新建RaisedButton(按下时:null,子项:新建文本('OPTIONS'),)
)
],
),
)
],
),
),
容器(
孩子:新文本字段(
装饰:输入装饰(
labelText:“时代”,
hintText:'5000',
),
自动更正:正确,
自动对焦:对,
键盘类型:TextInputType.number,
),
),
容器(
孩子:新文本字段(
装饰:输入装饰(
labelText:“学习率”,
hintText:'0.00333',
),
自动更正:正确,
自动对焦:对,
键盘类型:TextInputType.number,
),
),
容器(
填充:仅限边缘设置(顶部:20),
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
容器(
宽度:MediaQuery.of(context).size.width/3,
高度:MediaQuery.of(context).size.width,
装饰:盒子装饰(
边框:border.all(颜色:color.fromRGBO(0,0,0,100)),
),
子项:新文本(“数据”)
),
容器(
宽度:MediaQuery.of(context).size.width/3,
高度:MediaQuery.of(context).size.width,
装饰:盒子装饰(
边境:博尔德
Visibility(
visible: secondLayer,
child: yourChildWidget
),
Visibility(
visible: secondLayer,
maintainSize: true,
maintainAnimation: true,
maintainState: true,
child: yourChildWidget
),