|
|
|
@ -8,6 +8,8 @@ import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
import 'package:test_sa/models/new_models/asset_nd_auto_complete_by_dynamic_codes_model.dart';
|
|
|
|
import 'package:test_sa/models/new_models/asset_nd_auto_complete_by_dynamic_codes_model.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/models/wo_by_asset_id_model.dart';
|
|
|
|
|
|
|
|
import 'package:test_sa/modules/cm_module/cm_detail_provider.dart';
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
import 'package:test_sa/new_views/app_style/app_color.dart';
|
|
|
|
import 'package:test_sa/views/app_style/sizing.dart';
|
|
|
|
import 'package:test_sa/views/app_style/sizing.dart';
|
|
|
|
|
|
|
|
|
|
|
|
@ -17,9 +19,9 @@ import '../../../new_views/app_style/app_text_style.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class WoAutoCompleteField extends StatefulWidget {
|
|
|
|
class WoAutoCompleteField extends StatefulWidget {
|
|
|
|
final String initialValue;
|
|
|
|
final String initialValue;
|
|
|
|
final num? assetId;
|
|
|
|
final int? assetId;
|
|
|
|
final bool clearAfterPick, byName, enabled;
|
|
|
|
final bool clearAfterPick, byName, enabled;
|
|
|
|
final Function(AssetNDAutoCompleteByDynamicCodesModel) onPick;
|
|
|
|
final Function(WoByAssetIdModel) onPick;
|
|
|
|
|
|
|
|
|
|
|
|
const WoAutoCompleteField({Key? key, required this.byName, required this.initialValue, this.assetId, required this.onPick, this.clearAfterPick = true, this.enabled = true}) : super(key: key);
|
|
|
|
const WoAutoCompleteField({Key? key, required this.byName, required this.initialValue, this.assetId, required this.onPick, this.clearAfterPick = true, this.enabled = true}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,7 +30,7 @@ class WoAutoCompleteField extends StatefulWidget {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
late OracleCodeProvider _oracleCodeProvider;
|
|
|
|
late CMDetailProvider _cmDetailProvider;
|
|
|
|
|
|
|
|
|
|
|
|
late TextEditingController _controller;
|
|
|
|
late TextEditingController _controller;
|
|
|
|
|
|
|
|
|
|
|
|
@ -38,7 +40,7 @@ class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
void initState() {
|
|
|
|
void initState() {
|
|
|
|
_controller = TextEditingController(text: widget.initialValue);
|
|
|
|
_controller = TextEditingController(text: widget.initialValue);
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
_oracleCodeProvider = Provider.of<OracleCodeProvider>(context, listen: false);
|
|
|
|
_cmDetailProvider = Provider.of<CMDetailProvider>(context, listen: false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
@ -64,7 +66,7 @@ class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
|
|
|
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
|
|
|
// boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
|
|
|
// boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10)],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Autocomplete<AssetNDAutoCompleteByDynamicCodesModel>(
|
|
|
|
child: Autocomplete<WoByAssetIdModel>(
|
|
|
|
optionsBuilder: (TextEditingValue textEditingValue) async {
|
|
|
|
optionsBuilder: (TextEditingValue textEditingValue) async {
|
|
|
|
if (textEditingValue.text.isEmpty) {
|
|
|
|
if (textEditingValue.text.isEmpty) {
|
|
|
|
if (loading) {
|
|
|
|
if (loading) {
|
|
|
|
@ -72,20 +74,21 @@ class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
loading = false;
|
|
|
|
loading = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return const Iterable<AssetNDAutoCompleteByDynamicCodesModel>.empty();
|
|
|
|
return const Iterable<WoByAssetIdModel>.empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!loading) {
|
|
|
|
if (!loading) {
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
loading = true;
|
|
|
|
loading = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<AssetNDAutoCompleteByDynamicCodesModel> workOrders = (await _oracleCodeProvider.getAssetByOracleCode(textEditingValue.text));
|
|
|
|
List<WoByAssetIdModel> workOrders = (await _cmDetailProvider.getWorkOrderByAssetId(textEditingValue.text, widget.assetId!));
|
|
|
|
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
loading = false;
|
|
|
|
loading = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return workOrders;
|
|
|
|
return workOrders;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
displayStringForOption: (AssetNDAutoCompleteByDynamicCodesModel option) => widget.byName ? option.displayName ?? "" : option.codeValue ?? "",
|
|
|
|
displayStringForOption: (WoByAssetIdModel option) => widget.byName ? option.workOrderNo ?? "" : option.workOrderNo ?? "",
|
|
|
|
fieldViewBuilder: (BuildContext context, TextEditingController fieldTextEditingController, FocusNode fieldFocusNode, VoidCallback onFieldSubmitted) {
|
|
|
|
fieldViewBuilder: (BuildContext context, TextEditingController fieldTextEditingController, FocusNode fieldFocusNode, VoidCallback onFieldSubmitted) {
|
|
|
|
return TextField(
|
|
|
|
return TextField(
|
|
|
|
controller: _controller,
|
|
|
|
controller: _controller,
|
|
|
|
@ -106,7 +109,7 @@ class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
fillColor: AppColor.fieldBgColor(context),
|
|
|
|
fillColor: AppColor.fieldBgColor(context),
|
|
|
|
errorStyle: AppTextStyle.tiny.copyWith(color: context.isDark ? AppColor.red50 : AppColor.red60),
|
|
|
|
errorStyle: AppTextStyle.tiny.copyWith(color: context.isDark ? AppColor.red50 : AppColor.red60),
|
|
|
|
floatingLabelStyle: AppTextStyle.body1.copyWith(fontWeight: FontWeight.w500, color: context.isDark ? null : AppColor.neutral20),
|
|
|
|
floatingLabelStyle: AppTextStyle.body1.copyWith(fontWeight: FontWeight.w500, color: context.isDark ? null : AppColor.neutral20),
|
|
|
|
labelText: "Name/Oracle Code",
|
|
|
|
labelText: "CM Work Order Number",
|
|
|
|
labelStyle: AppTextStyles.tinyFont.copyWith(color: AppColor.textColor(context)),
|
|
|
|
labelStyle: AppTextStyles.tinyFont.copyWith(color: AppColor.textColor(context)),
|
|
|
|
suffixIcon: loading ? const CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 3.0).paddingOnly(end: 8) : null,
|
|
|
|
suffixIcon: loading ? const CircularProgressIndicator(color: AppColor.primary10, strokeWidth: 3.0).paddingOnly(end: 8) : null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -119,11 +122,11 @@ class _WoAutoCompleteFieldState extends State<WoAutoCompleteField> {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onSelected: (AssetNDAutoCompleteByDynamicCodesModel selection) {
|
|
|
|
onSelected: (WoByAssetIdModel selection) {
|
|
|
|
if (widget.clearAfterPick) {
|
|
|
|
if (widget.clearAfterPick) {
|
|
|
|
_controller.clear();
|
|
|
|
_controller.clear();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
_controller.text = widget.byName ? (selection.displayName ?? "") : (selection.codeValue ?? "");
|
|
|
|
_controller.text = widget.byName ? (selection.workOrderNo ?? "") : (selection.workOrderNo ?? "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
widget.onPick(selection);
|
|
|
|
widget.onPick(selection);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|