One UI in flutter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.4 KiB

2 years ago
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../model/ac_company_response_model.dart';
import '../provider/dio_provider.dart';
import '../repository/mitra_repository.dart';
import '../screen/md_lab_mitra/selectedCompanyProvider.dart';
import 'fx_data_mitra.dart';
// ignore: must_be_immutable
class FxAcCompany extends HookConsumerWidget {
FxAcCompany({Key? key}) : super(key: key);
CancelToken? cancelToken;
@override
Widget build(BuildContext context, WidgetRef ref) {
final errorMessage = useState("");
final ctrl = useTextEditingController(text: "");
cancelToken = CancelToken();
final fc = FocusNode();
final selectedCompany = ref.read(selectdAcCompanyProvider);
if (selectedCompany != null) {
ctrl.text = selectedCompany.mCompanyName;
}
return RawAutocomplete<AcCompanyModel>(
textEditingController: ctrl,
displayStringForOption: (model) => model.mCompanyName,
focusNode: fc,
fieldViewBuilder: (context, ctrl, fc, onChange) {
return TextField(
controller: ctrl,
focusNode: fc,
);
},
optionsBuilder: (tv) async {
try {
final dio = ref.read(dioProvider);
await Future.delayed(const Duration(milliseconds: 300));
final resp = await MitraRepository(dio: dio)
.lookupCompany(query: ctrl.text, cancelToken: cancelToken);
return resp;
} catch (e) {
errorMessage.value = e.toString();
}
return [];
},
optionsViewBuilder: (context, onSelect, listModel) {
return Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 400,
child: Material(
child: ListView.builder(
itemCount: listModel.length,
itemBuilder: (context, idx) {
final model = listModel.elementAt(idx);
return InkWell(
onTap: () {
ref.read(selectdAcCompanyProvider.notifier).state =
model;
onSelect(model);
},
child: Container(
color: (idx % 2 == 1)
? Colors.blue.shade100.withOpacity(0.2)
: null,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
FxNormalBlueText(
title: model.mCompanyName,
isBold: true,
),
const SizedBox(height: 5),
FxNormalBlueText(
title: model.mCompanyAddress),
],
),
),
));
}),
),
),
);
});
}
}