gpt4 book ai didi

flutter - Flutter:如何在容器内对齐小部件

转载 作者:行者123 更新时间:2023-12-03 04:11:03 24 4
gpt4 key购买 nike

对齐小部件给了我怪异的对齐方式。因此,我创建了FlatButtons,它们应该在蓝色容器的右下角和右下角对齐。但是他们并没有达到理想的位置。红色代表支架,蓝色代表容器

问题:[/image/Jmo5K.png]

完整代码:

Padding(
padding: EdgeInsets.symmetric(vertical: 5,horizontal: 10),
child: Container(
color: Colors.blue,
height: 1000,
child: SingleChildScrollView(
child: Column(
children: <Widget>[

//Choose feedback type
Align(
alignment: Alignment.topLeft,
child: DropdownButton<String>(
value: dropdownValue,
hint: Text('Feedback type'),
icon: Icon(Icons.arrow_downward),
iconSize: 15,
elevation: 16,
style: TextStyle(color: Colors.blue),
onChanged: (String newvalue){
setState(() {
dropdownValue = newvalue;
});
},
items: <String>['Suggestion','Problem'].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),

SizedBox(height: 20,),

// Input feedback
TextFormField(
maxLines: 13,
maxLength: 700,
textAlign: TextAlign.left,
initialValue: 'Please keep suggestions and problems separate.',
decoration: InputDecoration(
fillColor: Colors.white,
labelText: "Feedback here",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10)
),
),
validator: (val){
if(val.length < 20){
return "Feeback too short";
}else{
return null;
}
},
),
// cancel
Align(
alignment: Alignment.bottomLeft,
child: FlatButton(
onPressed: (){Navigator.of(context).pop();},
child: Text('Cancel')
),
),

// Submit
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: (){Navigator.of(context).pop();},
child: Text('Submit')
),
),

],
),
),
),
),
);
}
}

最佳答案

您应该使用一行来对齐您的按钮,如下所示:

Column(
children: <Widget>[

Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween
children: [
// cancel
Align(
alignment: Alignment.bottomLeft,
child: FlatButton(
onPressed: (){Navigator.of(context).pop();},
child: Text('Cancel')
),
),

// Submit
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: (){Navigator.of(context).pop();},
child: Text('Submit')
),
),
]
)

],
)

关于flutter - Flutter:如何在容器内对齐小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61760706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com