Override Default Headers and Query Parameters

Custom headers and query parameters can be passed into all finders and watchers (findAll, findOne, save, watchOne etc) but sometimes defaults are necessary.

Here is how:

mixin BaseAdapter<T extends DataModel<T>> on RemoteAdapter<T> {
  final _localStorageService = read(localStorageProvider);

  @override
  String get baseUrl => "http://my.remote.url:8080/";

  @override
  FutureOr<Map<String, String>> get defaultHeaders async {
    final token = _localStorageService.getToken();
    return await super.defaultHeaders & {'Authorization': token};
  }

  @override
  FutureOr<Map<String, dynamic>> get defaultParams async {
    return await super.defaultParams & {'v': 1};
  }
}

Need professional help with Flutter?

Describe your project in detail and include your e-mail and budget.