cronet_http library

An Android Flutter plugin that provides access to the Cronet HTTP client.

The platform interface must be initialized before using this plugin e.g. by calling WidgetsFlutterBinding.ensureInitialized or runApp.

CronetClient is an implementation of the package:http Client, which means that it can easily used conditionally based on the current platform.

import 'package:provider/provider.dart';

void main() {
  final Client httpClient;
  if (Platform.isAndroid) {
    // `package:cronet_http` cannot be used until
    // `WidgetsFlutterBinding.ensureInitialized()` or `runApp` is called.
    WidgetsFlutterBinding.ensureInitialized();
    final engine = CronetEngine.build(
        cacheMode: CacheMode.memory,
        cacheMaxSize: 2 * 1024 * 1024,
        userAgent: 'Book Agent');
    httpClient = CronetClient.fromCronetEngine(engine, closeEngine: true);
  } else {
    httpClient = IOClient(HttpClient()..userAgent = 'Book Agent');
  }

  runApp(Provider<Client>(
      create: (_) => httpClient,
      child: const BookSearchApp(),
      dispose: (_, client) => client.close()));
  }
}

Classes

CronetClient
A HTTP Client based on the Cronet network stack.
CronetClientWithProfile
A test-only class that makes the HttpClientRequestProfile data available.
CronetEngine
An environment that can be used to make HTTP requests.
CronetStreamedResponse
An HTTP response from the Cronet network stack.

Enums

CacheMode
The type of caching to use when making HTTP requests.