【发布时间】:2021-02-02 20:28:33
【问题描述】:
我有这个看法。在 ModalBottomSheet 视图中的颤振应用程序中。
输入字段构建器
Expanded(
flex: 6,
child: ListView.builder(
itemCount: 5,
itemBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.symmetric(vertical: 4.0, horizontal: 4.0),
width: MediaQuery.of(context).size.width * 0.95,
// height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(
10.0,
)),
color: Color(0xFF01816B),
shape: BoxShape.rectangle),
//
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4.0, vertical: 4.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: Text(
"Category",
style: kSubContentStyleWhiteLight,
),
),
Expanded(
flex: 1,
child: Text(
"Food Type",
style: kSubContentStyleWhiteLight,
),
),
Expanded(
flex: 1,
child: Text(
"Quantity",
style: kSubContentStyleWhiteLight,
),
),
],
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 4.0, vertical: 4.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: Container(
height: 48.0,
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(
10.0,
)),
color: Color(0xFF03B898),
shape: BoxShape.rectangle),
child: DropdownButton<String>(
value: _categorySelected,
// icon: Icon(Icons.arrow_downward),
hint: Text(
'Category',
style: kMainContentStyleWhite,
),
iconSize: 24,
elevation: 16,
style: kMainContentStyleLightBlack,
onChanged: (String newValue) {
setState(() {
_categorySelected = newValue;
});
},
items: _categoryList
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
SizedBox(
width: 8.0,
),
Expanded(
flex: 1,
child: Container(
height: 48.0,
padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(
10.0,
)),
color: Color(0xFF03B898),
shape: BoxShape.rectangle),
child: DropdownButton<String>(
value: _foodTypeSelected,
hint: Text(
'FoodType',
style: kMainContentStyleWhite,
),
iconSize: 24,
elevation: 2,
style: kMainContentStyleLightBlack,
onChanged: (String newValue) {
setState(() {
_foodTypeSelected = newValue;
});
},
items: _foodTypeList
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
),
SizedBox(
width: 8.0,
),
Expanded(
flex: 1,
child: Container(
height: 48.0,
// color: Colors.grey[100],
// padding: EdgeInsets.all(2.0),
decoration: BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(
10.0,
)),
color: Color(0xFF03B898),
shape: BoxShape.rectangle),
alignment: Alignment.center,
child: TextFormField(
// controller: _mealPlanQtyController,
inputFormatters: [
new LengthLimitingTextInputFormatter(
3),
],
// decoration: InputDecoration(
// border: OutlineInputBorder(),
// ),
keyboardType: TextInputType.number,
autofocus: false,
validator: validateNumberDecimal,
onSaved: (String value) {
// _petWeight = value; //double.parse(value);
},
// initialValue: 'alucard@gmail.com',
style: kMainContentStyleWhite,
),
),
),
],
),
),
],
),
);
},
),
),
在这里,我需要分别获取每个项目的每个值。(值来自两个下拉菜单和一个 TextInputField)。 我需要使用 API 以以下格式传递每个输入字段(有五个输入字段列表项)
{
"user_email": "email@m.com",
"user_token": "thisistoken",
"feeding_plan_detail": {
"quantity": "float",
"food_id": "id",
"feeding_plan_id": "id"
}
}
我如何在颤振中做到这一点?
【问题讨论】: