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.
77 lines
2.6 KiB
Dart
77 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../../../controllers/providers/api/devices_provider.dart';
|
|
import '../../../models/device/device.dart';
|
|
import '../../app_style/colors.dart';
|
|
import '../../app_style/sizing.dart';
|
|
|
|
class AutoCompleteDeviceField extends StatefulWidget {
|
|
final Device initialValue;
|
|
final String? hospitalId;
|
|
final Function(String)? onPick;
|
|
|
|
const AutoCompleteDeviceField({Key? key, required this.initialValue, this.onPick, this.hospitalId}) : super(key: key);
|
|
|
|
@override
|
|
AutoCompleteDeviceFieldState createState() => AutoCompleteDeviceFieldState();
|
|
}
|
|
|
|
class AutoCompleteDeviceFieldState extends State<AutoCompleteDeviceField> {
|
|
DevicesProvider? _devicesProvider;
|
|
TextEditingController? _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
_controller = TextEditingController(text: widget.initialValue.serialNumber);
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller?.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_devicesProvider = Provider.of<DevicesProvider>(context);
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
border: Border.all(color: AColors.black),
|
|
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
|
boxShadow: const [AppStyle.boxShadow]),
|
|
child: TypeAheadField<Device>(
|
|
textFieldConfiguration: TextFieldConfiguration(
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
controller: _controller,
|
|
textAlign: TextAlign.center,
|
|
decoration: const InputDecoration(
|
|
border: InputBorder.none,
|
|
disabledBorder: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
enabledBorder: InputBorder.none,
|
|
),
|
|
textInputAction: TextInputAction.search,
|
|
),
|
|
suggestionsCallback: (value) async {
|
|
return await _devicesProvider!.getDevicesList(hospitalId: widget.hospitalId, serialNumber: value);
|
|
},
|
|
itemBuilder: (context, device) {
|
|
return ListTile(
|
|
title: Text(device.serialNumber ?? ""),
|
|
subtitle: Text("${device.model ?? ""}/${device.brand ?? ""}"),
|
|
);
|
|
},
|
|
onSuggestionSelected: (device) {
|
|
_controller?.text = device.serialNumber ?? "";
|
|
widget.onPick!(device.id ?? "");
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|