You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.6 KiB
Dart
85 lines
2.6 KiB
Dart
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class ListSelectDialog extends StatefulWidget {
|
|
final List<dynamic> list;
|
|
final String attributeName;
|
|
final String attributeValueId;
|
|
final okText;
|
|
final Function(dynamic) okFunction;
|
|
dynamic selectedValue;
|
|
|
|
ListSelectDialog({@required this.list, @required this.attributeName, @required this.attributeValueId, @required this.okText, @required this.okFunction});
|
|
|
|
@override
|
|
_ListSelectDialogState createState() => _ListSelectDialogState();
|
|
}
|
|
|
|
class _ListSelectDialogState extends State<ListSelectDialog> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
widget.selectedValue = widget.selectedValue ?? widget.list[0];
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return showAlertDialog(context);
|
|
}
|
|
|
|
showAlertDialog(BuildContext context) {
|
|
// set up the buttons
|
|
Widget cancelButton = ElevatedButton(
|
|
child: Text(TranslationBase.of(context).cancel),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
});
|
|
Widget continueButton = ElevatedButton(
|
|
child: Text(this.widget.okText),
|
|
onPressed: () {
|
|
this.widget.okFunction(widget.selectedValue);
|
|
Navigator.of(context).pop();
|
|
});
|
|
// set up the AlertDialog
|
|
AlertDialog alert = AlertDialog(
|
|
// title: Text(widget.title),
|
|
content: createDialogList(),
|
|
actions: [
|
|
cancelButton,
|
|
continueButton,
|
|
],
|
|
);
|
|
return alert;
|
|
}
|
|
|
|
Widget createDialogList() {
|
|
return Container(
|
|
height: MediaQuery.of(context).size.height * 0.5,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
...widget.list
|
|
.map((item) => RadioListTile(
|
|
title: Text("${item[widget.attributeName].toString()}"),
|
|
groupValue: widget.selectedValue[widget.attributeValueId].toString(),
|
|
value: item[widget.attributeValueId].toString(),
|
|
activeColor: Colors.blue.shade700,
|
|
selected: item[widget.attributeValueId].toString() == widget.selectedValue[widget.attributeValueId].toString(),
|
|
onChanged: (val) {
|
|
setState(() {
|
|
widget.selectedValue = item;
|
|
});
|
|
},
|
|
))
|
|
.toList()
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
static closeAlertDialog(BuildContext context) {
|
|
Navigator.of(context).pop();
|
|
}
|
|
}
|