getSearchTermWithFallback method
- {required AppModel appModel,
- required CreatorModel creatorModel,
- required List<
Field> fallbackSearchTerms}
Fetches the search term to use from the CreatorModel. If the field controller is empty, use a fallback and inform the user that a fallback has been used.
Implementation
String? getSearchTermWithFallback({
required AppModel appModel,
required CreatorModel creatorModel,
required List<Field> fallbackSearchTerms,
}) {
String searchTerm = creatorModel.getFieldController(this).text.trim();
if (searchTerm.isNotEmpty) {
return searchTerm;
} else {
for (Field fallbackField in fallbackSearchTerms) {
String fallbackTerm =
creatorModel.getFieldController(fallbackField).text.trim();
if (fallbackTerm.isNotEmpty) {
Fluttertoast.showToast(
msg: t.field_fallback_used(
field: getLocalisedLabel(appModel),
secondField: fallbackField.getLocalisedLabel(appModel),
),
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
return fallbackTerm;
}
}
}
Fluttertoast.showToast(
msg: t.no_text_to_search,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
);
return null;
}