showDispatchDialog(List<Technician> techList) async {
var alertDialogs = await showDialog(
context: context,
builder: (context) {
int _techIndex = 0;
return AlertDialog(
title: Text("請選擇"),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return SingleChildScrollView(
child: ListBody(
children: techList.asMap().keys.map((index) =>
Padding(
padding:EdgeInsets.all(5),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Radio(
value: index,
groupValue: _techIndex,
onChanged: (v) {
setState(() {
this.technician = techList[v];
_techIndex = v;
});
},
),
Text(techList[index].name),
],
)
)
).toList(),
),
);
}),
actions: <Widget>[
FlatButton(
child: Text("取消"),
onPressed: () {
Navigator.pop(context, "cancel");} ),
FlatButton(
child: Text("確定"),
onPressed: (){
Navigator.pop(context, "confirm");
}),
],
);
});
}
頁面中實現單選框
///默認選中的單選框的值
int groupValue = 0;
///單選框的成組使用
Row buildRadioGroupRowWidget() {
return Row(
children: [
Row(
///包裹子布局
mainAxisSize: MainAxisSize.min,
children: [
Radio(
///此單選框綁定的值 必選參數
value: 0,
///當前組中這選定的值 必選參數
groupValue: groupValue,
///點擊狀態改變時的回調 必選參數
onChanged: (v) {
setState(() {
this.groupValue = v;
});
},
),
Text("語文")
],
),
Row(
///包裹子布局
mainAxisSize: MainAxisSize.min,
children: [
Radio(
///此單選框綁定的值 必選參數
value: 1,
///當前組中這選定的值 必選參數
groupValue: groupValue,
///點擊狀態改變時的回調 必選參數
onChanged: (v) {
setState(() {
this.groupValue = v;
});
},
),
Text("數學")
],
),
Row(
///包裹子布局
mainAxisSize: MainAxisSize.min,
children: [
Radio(
///此單選框綁定的值 必選參數
value: 2,
///當前組中這選定的值 必選參數
groupValue: groupValue,
///點擊狀態改變時的回調 必選參數
onChanged: (v) {
setState(() {
this.groupValue = v;
});
},
),
Text("英語")
],
),
],
);
}