add search in SOAP
parent
806682b921
commit
93bece09d7
@ -0,0 +1,149 @@
|
||||
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
|
||||
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
|
||||
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/TextFields.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/app_buttons_widget.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/divider_with_spaces_around.dart';
|
||||
import 'package:doctor_app_flutter/widgets/shared/network_base_view.dart';
|
||||
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MasterKeyCheckboxSearchWidget extends StatefulWidget {
|
||||
final SOAPViewModel model;
|
||||
final Function addSelectedHistories;
|
||||
final Function(MasterKeyModel) removeHistory;
|
||||
final Function(MasterKeyModel) addHistory;
|
||||
final bool Function(MasterKeyModel) isServiceSelected;
|
||||
final List<MasterKeyModel> masterList;
|
||||
|
||||
MasterKeyCheckboxSearchWidget(
|
||||
{Key key,
|
||||
this.model,
|
||||
this.addSelectedHistories,
|
||||
this.removeHistory,
|
||||
this.masterList,
|
||||
this.addHistory,
|
||||
this.isServiceSelected})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
_MasterKeyCheckboxSearchWidgetState createState() => _MasterKeyCheckboxSearchWidgetState();
|
||||
}
|
||||
|
||||
class _MasterKeyCheckboxSearchWidgetState extends State<MasterKeyCheckboxSearchWidget> {
|
||||
List<MasterKeyModel> items = List();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
items.addAll(widget.masterList);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
child: Column(
|
||||
children: [
|
||||
NetworkBaseView(
|
||||
baseViewModel: widget.model,
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height * 0.5,
|
||||
child: Center(
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: Colors.white),
|
||||
child: ListView(
|
||||
children: [
|
||||
TextFields(
|
||||
hintText: 'Search history',
|
||||
suffixIcon: EvaIcons.search,
|
||||
onChanged: (value) {
|
||||
filterSearchResults(value);
|
||||
},
|
||||
),
|
||||
SizedBox(height: 15,),
|
||||
Column(
|
||||
children: items.map((historyInfo) {
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value:
|
||||
widget.isServiceSelected(historyInfo),
|
||||
activeColor: Colors.red[800],
|
||||
onChanged: (bool newValue) {
|
||||
setState(() {
|
||||
if (widget
|
||||
.isServiceSelected(historyInfo)) {
|
||||
widget.removeHistory(historyInfo);
|
||||
} else {
|
||||
widget.addHistory(historyInfo);
|
||||
}
|
||||
});
|
||||
}),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10, vertical: 0),
|
||||
child: Texts(historyInfo.nameEn,
|
||||
variant: "bodyText",
|
||||
bold: true,
|
||||
color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
DividerWithSpacesAround(),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
if (widget.model.state == ViewState.Idle)
|
||||
AppButton(
|
||||
title: "Add SELECTED HISTORIES".toUpperCase(),
|
||||
onPressed: () {
|
||||
widget.addSelectedHistories();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void filterSearchResults(String query) {
|
||||
List<MasterKeyModel> dummySearchList = List();
|
||||
dummySearchList.addAll(widget.masterList);
|
||||
if (query.isNotEmpty) {
|
||||
List<MasterKeyModel> dummyListData = List();
|
||||
dummySearchList.forEach((item) {
|
||||
if (item.nameAr.toLowerCase().contains(query.toLowerCase()) ||
|
||||
item.nameEn.toLowerCase().contains(query.toLowerCase())) {
|
||||
dummyListData.add(item);
|
||||
}
|
||||
});
|
||||
setState(() {
|
||||
items.clear();
|
||||
items.addAll(dummyListData);
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
setState(() {
|
||||
items.clear();
|
||||
items.addAll(widget.masterList);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue