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.
156 lines
4.6 KiB
Dart
156 lines
4.6 KiB
Dart
import 'package:doctor_app_flutter/utils/utils.dart';
|
|
import 'package:doctor_app_flutter/utils/translations_delegate_base.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../config/config.dart';
|
|
|
|
class ListSelectDialog extends StatefulWidget {
|
|
final List<dynamic> list;
|
|
final String attributeName;
|
|
final String attributeValueId;
|
|
final okText;
|
|
final Function(dynamic) okFunction;
|
|
dynamic selectedValue;
|
|
final Widget searchWidget;
|
|
final bool usingSearch;
|
|
final String hintSearchText;
|
|
|
|
ListSelectDialog({
|
|
@required this.list,
|
|
@required this.attributeName,
|
|
@required this.attributeValueId,
|
|
@required this.okText,
|
|
@required this.okFunction,
|
|
this.searchWidget,
|
|
this.usingSearch = false,
|
|
this.hintSearchText,
|
|
});
|
|
|
|
@override
|
|
_ListSelectDialogState createState() => _ListSelectDialogState();
|
|
}
|
|
|
|
class _ListSelectDialogState extends State<ListSelectDialog> {
|
|
List<dynamic> items = List();
|
|
|
|
@override
|
|
void initState() {
|
|
widget.selectedValue = widget.selectedValue ?? widget.list[0];
|
|
items.addAll(widget.list);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return showAlertDialog(context);
|
|
}
|
|
|
|
showAlertDialog(BuildContext context) {
|
|
Widget cancelButton = FlatButton(
|
|
child: Text(TranslationBase.of(context).cancel),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
});
|
|
Widget continueButton = FlatButton(
|
|
child: Text(this.widget.okText),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
this.widget.okFunction(widget.selectedValue);
|
|
});
|
|
AlertDialog alert = AlertDialog(
|
|
content: createDialogList(),
|
|
actions: [
|
|
cancelButton,
|
|
continueButton,
|
|
],
|
|
);
|
|
return alert;
|
|
}
|
|
|
|
Widget createDialogList() {
|
|
return Container(
|
|
height: MediaQuery.of(context).size.height * 0.5,
|
|
child: Column(
|
|
children: [
|
|
if (widget.searchWidget != null) widget.searchWidget,
|
|
if (widget.usingSearch)
|
|
Container(
|
|
height: MediaQuery.of(context).size.height * 0.070,
|
|
child: TextField(
|
|
decoration: TabUtil.textFieldSelectorDecoration(
|
|
widget.hintSearchText ??
|
|
TranslationBase.of(context).search,
|
|
null,
|
|
false,
|
|
suffixIcon: Icon(
|
|
Icons.search,
|
|
)),
|
|
enabled: true,
|
|
keyboardType: TextInputType.text,
|
|
onChanged: (value) {
|
|
filterSearchResults(value);
|
|
},
|
|
)),
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
...items
|
|
.map((item) => RadioListTile(
|
|
title: Text(
|
|
"${item[widget.attributeName].toString()}"),
|
|
groupValue: widget
|
|
.selectedValue[widget.attributeValueId]
|
|
.toString(),
|
|
value: item[widget.attributeValueId].toString(),
|
|
activeColor: AppGlobal.appRedColor,
|
|
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();
|
|
}
|
|
|
|
void filterSearchResults(String query) {
|
|
List<dynamic> dummySearchList = List();
|
|
dummySearchList.addAll(widget.list);
|
|
if (query.isNotEmpty) {
|
|
List<dynamic> dummyListData = List();
|
|
dummySearchList.forEach((item) {
|
|
if ("${item[widget.attributeName].toString()}"
|
|
.toLowerCase()
|
|
.contains(query.toLowerCase())) {
|
|
dummyListData.add(item);
|
|
}
|
|
});
|
|
setState(() {
|
|
items.clear();
|
|
items.addAll(dummyListData);
|
|
});
|
|
return;
|
|
} else {
|
|
setState(() {
|
|
items.clear();
|
|
items.addAll(widget.list);
|
|
});
|
|
}
|
|
}
|
|
}
|