|
|
|
|
@ -17,8 +17,8 @@ class SingleItemDropDownMenu<T extends Base, X extends LoadingListNotifier> exte
|
|
|
|
|
final List<T> staticData;
|
|
|
|
|
final TranslationKeys title;
|
|
|
|
|
|
|
|
|
|
/// If you want to use a static data (without calling API)
|
|
|
|
|
/// just use [NullableLoadingProvider] as generic data type and fill the [staticData]
|
|
|
|
|
/// To use a static data (without calling API)
|
|
|
|
|
/// just send [NullableLoadingProvider] as generic data type and fill the [staticData]
|
|
|
|
|
const SingleItemDropDownMenu({
|
|
|
|
|
Key key,
|
|
|
|
|
@required this.context,
|
|
|
|
|
@ -39,19 +39,18 @@ class _SingleItemDropDownMenuState<T extends Base, X extends LoadingListNotifier
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
if (widget.staticData != null) {
|
|
|
|
|
if (X != NullableLoadingProvider) {
|
|
|
|
|
provider = Provider.of<X>(widget.context);
|
|
|
|
|
}
|
|
|
|
|
if (widget.initialValue != null) {
|
|
|
|
|
final result = (widget.staticData ?? provider?.items)?.where((element) {
|
|
|
|
|
final result = (X == NullableLoadingProvider ? widget.staticData : provider.items)?.where((element) {
|
|
|
|
|
return element == widget.initialValue;
|
|
|
|
|
});
|
|
|
|
|
if (result.isNotEmpty) _selectedItem = result.first;
|
|
|
|
|
if (widget.initialValue?.identifier ?? "" != _selectedItem?.identifier ?? "") {
|
|
|
|
|
if ((widget.initialValue?.identifier ?? "") != (_selectedItem?.identifier ?? "")) {
|
|
|
|
|
widget.onSelect(_selectedItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -63,7 +62,7 @@ class _SingleItemDropDownMenuState<T extends Base, X extends LoadingListNotifier
|
|
|
|
|
@override
|
|
|
|
|
void didUpdateWidget(covariant SingleItemDropDownMenu<T, X> oldWidget) {
|
|
|
|
|
if (widget.initialValue != null) {
|
|
|
|
|
final result = (widget.staticData ?? provider?.items)?.where((element) {
|
|
|
|
|
final result = (X == NullableLoadingProvider ? widget.staticData : provider.items)?.where((element) {
|
|
|
|
|
return element == widget.initialValue;
|
|
|
|
|
});
|
|
|
|
|
if (result.isNotEmpty) {
|
|
|
|
|
@ -71,7 +70,7 @@ class _SingleItemDropDownMenuState<T extends Base, X extends LoadingListNotifier
|
|
|
|
|
} else {
|
|
|
|
|
_selectedItem = null;
|
|
|
|
|
}
|
|
|
|
|
if (widget.initialValue?.identifier ?? "" != _selectedItem?.identifier ?? "") {
|
|
|
|
|
if ((widget.initialValue?.identifier ?? "") != (_selectedItem?.identifier ?? "")) {
|
|
|
|
|
widget.onSelect(_selectedItem);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
@ -83,12 +82,14 @@ class _SingleItemDropDownMenuState<T extends Base, X extends LoadingListNotifier
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return AppLoadingManager(
|
|
|
|
|
isLoading: provider?.loading ?? false,
|
|
|
|
|
isFailedLoading: provider?.items == null && widget.staticData == null,
|
|
|
|
|
stateCode: widget.staticData == null ? provider?.stateCode : 200,
|
|
|
|
|
isLoading: (X == NullableLoadingProvider) ? false : provider.loading,
|
|
|
|
|
isFailedLoading: (X == NullableLoadingProvider) ? false : provider.items == null,
|
|
|
|
|
stateCode: (X == NullableLoadingProvider) ? 200 : provider.stateCode,
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
if (X != NullableLoadingProvider) {
|
|
|
|
|
provider?.reset();
|
|
|
|
|
await provider?.getDate();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 60.toScreenHeight,
|
|
|
|
|
@ -131,7 +132,7 @@ class _SingleItemDropDownMenuState<T extends Base, X extends LoadingListNotifier
|
|
|
|
|
});
|
|
|
|
|
widget.onSelect(newValue);
|
|
|
|
|
},
|
|
|
|
|
items: (widget.staticData ?? provider?.items)?.map<DropdownMenuItem<T>>((value) {
|
|
|
|
|
items: ((X == NullableLoadingProvider) ? widget.staticData : provider.items)?.map<DropdownMenuItem<T>>((value) {
|
|
|
|
|
return DropdownMenuItem<T>(
|
|
|
|
|
value: value,
|
|
|
|
|
child: Text(
|
|
|
|
|
|