|
|
|
|
@ -14,9 +14,13 @@ import '../loaders/loading_manager.dart';
|
|
|
|
|
import '../loaders/no_item_found.dart';
|
|
|
|
|
import '../qr/scan_qr.dart';
|
|
|
|
|
import 'device_item.dart';
|
|
|
|
|
|
|
|
|
|
class SingleDevicePicker extends StatefulWidget {
|
|
|
|
|
static final String id = "/single-device-Picker";
|
|
|
|
|
static const String id = "/single-device-Picker";
|
|
|
|
|
final bool sandraChoice = true;
|
|
|
|
|
|
|
|
|
|
const SingleDevicePicker({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_SingleDevicePickerState createState() => _SingleDevicePickerState();
|
|
|
|
|
}
|
|
|
|
|
@ -25,28 +29,23 @@ class _SingleDevicePickerState extends State<SingleDevicePicker> {
|
|
|
|
|
DevicesProvider? _devicesProvider;
|
|
|
|
|
UserProvider? _userProvider;
|
|
|
|
|
SettingProvider? _settingProvider;
|
|
|
|
|
List<Device> _searchableList = [];
|
|
|
|
|
final List<Device> _searchableList = [];
|
|
|
|
|
bool _firstTime = true;
|
|
|
|
|
Subtitle? _subtitle;
|
|
|
|
|
|
|
|
|
|
_getDevice(String result) async {
|
|
|
|
|
if(result == null) return;
|
|
|
|
|
_getDevice(String? result) async {
|
|
|
|
|
if (result == null) return;
|
|
|
|
|
showDialog(
|
|
|
|
|
barrierDismissible: false,
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (dialogContext){
|
|
|
|
|
builder: (dialogContext) {
|
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
List<Device> devices = await _devicesProvider!.getDevicesListBySN(
|
|
|
|
|
host: _settingProvider?.host??"",
|
|
|
|
|
user: _userProvider?.user??User(),
|
|
|
|
|
hospitalId: _userProvider?.user?.hospital?.id??"",
|
|
|
|
|
sn: result
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
List<Device> devices =
|
|
|
|
|
await _devicesProvider!.getDevicesListBySN(host: _settingProvider?.host ?? "", user: _userProvider?.user ?? User(), hospitalId: _userProvider?.user?.hospital?.id ?? "", sn: result);
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
if(devices.isEmpty){
|
|
|
|
|
Fluttertoast.showToast(msg: _subtitle?.noDeviceFound??"");
|
|
|
|
|
if (devices.isEmpty) {
|
|
|
|
|
Fluttertoast.showToast(msg: _subtitle?.noDeviceFound ?? "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Navigator.of(context).pop(devices.first);
|
|
|
|
|
@ -68,58 +67,48 @@ class _SingleDevicePickerState extends State<SingleDevicePicker> {
|
|
|
|
|
_userProvider = Provider.of<UserProvider>(context);
|
|
|
|
|
_settingProvider = Provider.of<SettingProvider>(context);
|
|
|
|
|
|
|
|
|
|
if(_firstTime && _devicesProvider?.devices != null){
|
|
|
|
|
_searchableList.addAll(_devicesProvider?.devices??[]);
|
|
|
|
|
_firstTime = false;
|
|
|
|
|
}
|
|
|
|
|
_subtitle = AppLocalization.of(context)?.subtitle;
|
|
|
|
|
return Scaffold(
|
|
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
|
body: LoadingManager(
|
|
|
|
|
isLoading: _devicesProvider?.isLoading??false,
|
|
|
|
|
stateCode: _devicesProvider?.stateCode??0,
|
|
|
|
|
isLoading: _devicesProvider?.isLoading,
|
|
|
|
|
stateCode: _devicesProvider?.stateCode,
|
|
|
|
|
isFailedLoading: _devicesProvider?.devices == null,
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
_devicesProvider?.reset();
|
|
|
|
|
await _devicesProvider?.getEquipment(
|
|
|
|
|
user: _userProvider?.user??User(),
|
|
|
|
|
host: _settingProvider?.host??"",
|
|
|
|
|
hospitalId: _userProvider?.user?.hospital?.id??""
|
|
|
|
|
);
|
|
|
|
|
await _devicesProvider?.getEquipment(user: _userProvider?.user ?? User(), host: _settingProvider?.host ?? "", hospitalId: _userProvider?.user?.hospital?.id ?? "");
|
|
|
|
|
if (_firstTime) {
|
|
|
|
|
_searchableList.addAll(_devicesProvider?.devices ?? []);
|
|
|
|
|
_firstTime = false;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
const SizedBox(height: 48),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 16),
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
ATextFormField(
|
|
|
|
|
hintText: _subtitle?.searchBySn??"",
|
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
|
hintText: _subtitle?.searchBySn ?? "",
|
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
|
suffixIcon: const Icon(Icons.search_rounded),
|
|
|
|
|
onChange: (value){
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
_searchableList.clear();
|
|
|
|
|
_searchableList.addAll(_devicesProvider!.devices!.where(
|
|
|
|
|
(element) => element.serialNumber!.toLowerCase().contains(
|
|
|
|
|
value.toLowerCase()
|
|
|
|
|
)
|
|
|
|
|
).toList());
|
|
|
|
|
_searchableList.addAll(_devicesProvider!.devices!.where((element) => element.serialNumber!.toLowerCase().contains(value.toLowerCase())).toList());
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8,),
|
|
|
|
|
const SizedBox(
|
|
|
|
|
height: 8,
|
|
|
|
|
),
|
|
|
|
|
ATextFormField(
|
|
|
|
|
hintText: "Search by Number",
|
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
|
style: Theme.of(context).textTheme.subtitle1,
|
|
|
|
|
suffixIcon: const Icon(Icons.search_rounded),
|
|
|
|
|
onChange: (value){
|
|
|
|
|
onChange: (value) {
|
|
|
|
|
_searchableList.clear();
|
|
|
|
|
_searchableList.addAll(_devicesProvider!.devices!.where(
|
|
|
|
|
(element) => element.number!.toLowerCase().contains(
|
|
|
|
|
value.toLowerCase()
|
|
|
|
|
)
|
|
|
|
|
).toList());
|
|
|
|
|
_searchableList.addAll(_devicesProvider!.devices!.where((element) => element.number!.toLowerCase().contains(value.toLowerCase())).toList());
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
@ -127,21 +116,23 @@ class _SingleDevicePickerState extends State<SingleDevicePicker> {
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: _searchableList.isEmpty ?
|
|
|
|
|
NoItemFound(message: _subtitle?.noDeviceFound??"",):
|
|
|
|
|
ListView.builder(
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: _searchableList.length,
|
|
|
|
|
itemBuilder: (listContext,itemIndex){
|
|
|
|
|
return DeviceItem(
|
|
|
|
|
device: _searchableList[itemIndex],
|
|
|
|
|
onPressed: (device){
|
|
|
|
|
Navigator.of(context).pop(device);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
child: _searchableList.isEmpty
|
|
|
|
|
? NoItemFound(
|
|
|
|
|
message: _subtitle?.noDeviceFound ?? "",
|
|
|
|
|
)
|
|
|
|
|
: ListView.builder(
|
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemCount: _searchableList.length,
|
|
|
|
|
itemBuilder: (listContext, itemIndex) {
|
|
|
|
|
return DeviceItem(
|
|
|
|
|
device: _searchableList[itemIndex],
|
|
|
|
|
onPressed: (device) {
|
|
|
|
|
Navigator.of(context).pop(device);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -151,7 +142,7 @@ class _SingleDevicePickerState extends State<SingleDevicePicker> {
|
|
|
|
|
child: const Icon(Icons.qr_code_scanner),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
String result = await Navigator.of(context).push(
|
|
|
|
|
MaterialPageRoute(builder: (_)=> ScanQr()),
|
|
|
|
|
MaterialPageRoute(builder: (_) => ScanQr()),
|
|
|
|
|
) as String;
|
|
|
|
|
_getDevice(result);
|
|
|
|
|
},
|
|
|
|
|
|