x_flutter_core 1.0.2 copy "x_flutter_core: ^1.0.2" to clipboard
x_flutter_core: ^1.0.2 copied to clipboard

A robust networking, storage, and infrastructure layer for scalable Flutter applications. Built on Dio with Clean Architecture patterns.

x_flutter_core #

A robust networking, storage, and infrastructure layer for scalable Flutter applications. Built on Dio with Clean Architecture patterns.

pub.dev

Features #

  • Dio-based HTTP client with caching, retry, and proxy support
  • Clean architecture request/error processor pipeline
  • Secure and shared preferences storage with lazy initialisation
  • Connectivity checker (mobile + always-connected stubs)
  • Sealed DataResponse<T> type for safe result handling

Installation #

dependencies:
  x_flutter_core: ^1.0.0

Usage #

Create an API client #

final dioClientModule = _DioClientModule();
final apiClient = dioClientModule.makeApiClient(
  ApiClientParams(
    baseUrl: 'https://api.example.com/',
    defaultConnectTimeout: 5000,
    defaultReceiveTimeout: 5000,
    interceptors: [MyLogInterceptor()],
    headers: {},
  ),
);

Create a custom error parser #

class CustomErrorParser {
  const CustomErrorParser._();

  static Object parse(int statusCode, dynamic response) {
    if (response is! Map<String, dynamic>) {
      return MyApiError(message: response?.toString());
    }
    return MyApiError.fromJson(response);
  }
}

Create a request processor #

final processor = dioClientModule.createInternalDioRequestProcessor(
  customErrorParser: CustomErrorParser.parse,
);

Make a request #

final response = await processor.processRequest(
  onRequest: () => apiClient.client.get('/users'),
  onParse: (response) => UserModelList.fromJson(response.data),
);

Handle the result #

if (response.isSuccess()) {
  final data = response.data;
} else {
  // handle error via ServerErrorMapper
}

Custom HTTP client #

  1. Extend RequestProcessor and implement processRequest.
  2. Extend ErrorProcessor and implement processError.

See InternalDioRequestProcessor and InternalDioErrorProcessor for reference implementations.

License #

MIT

1
likes
160
points
30
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A robust networking, storage, and infrastructure layer for scalable Flutter applications. Built on Dio with Clean Architecture patterns.

Repository (GitHub)
View/report issues

Topics

#networking #dio #storage #architecture #core

License

Apache-2.0 (license)

Dependencies

connectivity_plus, dio, dio_cache_interceptor, flutter, flutter_secure_storage, internet_connection_checker_plus, pretty_dio_logger, retry, shared_preferences, x_flutter_core_models

More

Packages that depend on x_flutter_core