register method
This method can be used to register a search widget with a unique id
.
It returns the instance of the SearchController class. The following example registers a widget with the second param as a Map.
final searchBase = SearchBase(
'gitxplore-app',
'https://@appbase-demo-ansible-abxiydt-arc.searchbase.io',
'a03a1cb71321:75b6603d-9456-4a5a-af6b-a487b309eb61'
);
searchBase.register('search-widget', {
dataField: ['title', 'description'],
value: ''
});
The following example registers a SearchController with second param as an instance of SearchController class.
final searchBase = SearchBase(
'gitxplore-app',
'https://@appbase-demo-ansible-abxiydt-arc.searchbase.io',
'a03a1cb71321:75b6603d-9456-4a5a-af6b-a487b309eb61'
);
final searchController = SearchController(
'gitxplore-app',
'https://@appbase-demo-ansible-abxiydt-arc.searchbase.io',
'a03a1cb71321:75b6603d-9456-4a5a-af6b-a487b309eb61',
'search-widget',
dataField: ['title', 'description'],
value: ''
);
searchBase.register('search-widget', searchController);
Additionally, you can override the global configurations by defining it for a particular widget. For example, to register a widget with a different index
name.
Implementation
SearchController register(String widgetId, dynamic searchController) {
if (widgetId == "") {
throw (ErrorMessages[InvalidIndex]);
}
if (this._searchWidgets.containsKey(widgetId)) {
// return existing instance
return this._searchWidgets[widgetId]!;
}
SearchController? componentInstance;
if (searchController != null && searchController is Map) {
// create instance from object with all the options
componentInstance = SearchController(
searchController["index"] != null
? searchController["index"]
: this.index,
searchController["url"] != null ? searchController["url"] : this.url,
searchController["credentials"] != null
? searchController["credentials"]
: this.credentials,
widgetId,
headers: searchController["headers"] is Map<String, String>
? searchController["headers"]
: this.headers,
transformRequest:
searchController["transformRequest"] is TransformRequest
? searchController["transformRequest"]
: this.transformRequest,
transformResponse:
searchController["transformResponse"] is TransformResponse
? searchController["transformResponse"]
: this.transformResponse,
appbaseConfig: searchController["appbaseConfig"] is AppbaseSettings
? searchController["appbaseConfig"]
: this.appbaseConfig,
type: searchController["type"],
dataField: searchController["dataField"],
react: searchController["react"],
queryFormat: searchController[" queryFormat"],
categoryField: searchController["categoryField"],
categoryValue: searchController["categoryValue"],
nestedField: searchController["nestedField"],
from: searchController["from"],
size: searchController["size"],
sortBy: searchController["sortBy"],
aggregationField: searchController["aggregationField"],
aggregationSize: searchController["aggregationSize"],
after: searchController["after"],
includeNullValues: searchController["includeNullValues"],
includeFields: searchController["includeFields"],
excludeFields: searchController["excludeFields"],
fuzziness: searchController["fuzziness"],
searchOperators: searchController["searchOperators"],
highlight: searchController["highlight"],
highlightField: searchController["highlightField"],
customHighlight: searchController["customHighlight"],
interval: searchController["interval"],
aggregations: searchController["aggregations"],
missingLabel: searchController["missingLabel"],
showMissing: searchController["showMissing"],
enableSynonyms: searchController["enableSynonyms"],
selectAllLabel: searchController["selectAllLabel"],
pagination: searchController["pagination"],
queryString: searchController["queryString"],
defaultQuery: searchController["defaultQuery"],
customQuery: searchController["customQuery"],
beforeValueChange: searchController["beforeValueChange"],
onValueChange: searchController["onValueChange"],
onResults: searchController["onResults"],
onAggregationData: searchController["onAggregationData"],
onError: searchController["onError"],
onRequestStatusChange: searchController["onRequestStatusChange"],
onQueryChange: searchController["onQueryChange"],
enablePopularSuggestions: searchController["enablePopularSuggestions"],
maxPopularSuggestions: searchController["maxPopularSuggestions"],
showDistinctSuggestions: searchController["showDistinctSuggestions"],
preserveResults: searchController["preserveResults"],
clearOnQueryChange: searchController["clearOnQueryChange"],
value: searchController["value"],
distinctField: searchController["distinctField"],
distinctFieldConfig: searchController["distinctFieldConfig"],
);
} else if (searchController is SearchController) {
componentInstance = searchController;
// set the id property on instance
componentInstance.id = widgetId;
}
// register component
this._searchWidgets[widgetId] = componentInstance!;
// set the search base instance as parent
componentInstance.setParent(this);
return componentInstance;
}