KeystoneNetwork class
Main KeystoneNetwork configuration class
This is OPTIONAL - developers can still use Dio directly. KeystoneNetwork provides a convenient way to configure and manage Dio instances.
Features:
- Simple initialization
- Pre-configured defaults
- Interceptor management
- Multiple instance support
- DioProvider integration for interceptors
Example:
// Initialize once in main()
KeystoneNetwork.initialize(
baseUrl: 'https://api.example.com',
interceptors: [
AuthInterceptor(
tokenManager: myTokenManager,
dioProvider: KeystoneNetwork.dioProvider,
),
LoggingInterceptor(),
],
);
// Use anywhere in your app
final response = await KeystoneNetwork.dio.get('/users');
// Or with ApiExecutor
final result = await ApiExecutor.execute<User, dynamic>(
request: () => KeystoneNetwork.dio.get('/user/me'),
parser: (json) => User.fromJson(json),
);
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- dio → Dio
-
Get the configured Dio instance
no setter
- dioProvider → DioProvider
-
Get the DioProvider for use with interceptors
no setter
Static Methods
-
createDioProvider(
Dio dio) → DioProvider - Create a DioProvider for a custom Dio instance
-
createInstance(
{required String baseUrl, Duration connectTimeout = const Duration(seconds: 30), Duration receiveTimeout = const Duration(seconds: 30), Duration sendTimeout = const Duration(seconds: 30), Map< String, dynamic> ? headers, List<Interceptor> interceptors = const [], ResponseType responseType = ResponseType.json, bool validateStatus(int?)?}) → Dio - Create a new Dio instance for multiple API endpoints
-
initialize(
{String? baseUrl, Duration connectTimeout = const Duration(seconds: 30), Duration receiveTimeout = const Duration(seconds: 30), Duration sendTimeout = const Duration(seconds: 30), Map< String, dynamic> ? headers, List<Interceptor> interceptors = const [], ResponseType responseType = ResponseType.json, bool validateStatus(int?)?}) → void - Initialize KeystoneNetwork with configuration
-
reset(
) → void - Reset KeystoneNetwork (for testing purposes only)