net_retrofit_kit 0.2.15
net_retrofit_kit: ^0.2.15 copied to clipboard
[DISCONTINUED] Declarative HTTP client built on Dio: define APIs with annotations and generate implementations with build_runner. Supports multiple clients, custom parsing, and unified error handling. [...]
中文 | English
net_retrofit_kit #
Declarative HTTP client for Flutter: annotations + codegen, based on Dio. GitHub
Package status: discontinued #
This package is discontinued on pub.dev. Existing versions stay installable for current dependents, but no further releases or maintenance are planned from this line.
What you can do:
- Stay on a pinned version if it already works for your app.
- Fork the repository and publish or depend via
git:/ path if you need changes. - Migrate to alternatives such as Dio with retrofit, chopper, or a custom
build_runnersetup.
If you publish a successor package, you can set replaced_by in pubspec.yaml on a future publish (or in the pub.dev admin UI) to point users to it.
Quick start #
1. Dependencies
dependencies:
net_retrofit_kit: ^0.2.15
dio: ">=5.0.0"
dev_dependencies:
build_runner: ^2.4.0
2. Config (once, e.g. in main())
NetRequest.options = const NetOptions(
baseUrl: 'https://api.example.com',
connectTimeout: Duration(seconds: 30),
receiveTimeout: Duration(seconds: 30),
);
3. Define API
@NetApi()
abstract class UserApi {
static UserApi get instance => UserApiImpl();
@Get('/user/info')
Future<UserModel?> getUserInfo();
@Post('/login')
Future<AuthModel?> login(@Body() LoginRequest body);
}
4. Generate
dart run build_runner build --delete-conflicting-outputs
5. Use
await UserApi.instance.getUserInfo();
Quick reference (annotations) #
| Annotation | Use |
|---|---|
@NetApi() |
On abstract class. Optional client: 'upload' for named client; else uses NetRequest.defaultKey. |
@Get(path) @Post(path) @Put(path) @Delete(path) |
HTTP method + path. |
@Body() |
Request body. Accepts Map<String, dynamic> or a class model; for non-Map types the generator emits body.toJson(), so the model must implement toJson. |
@Query() |
Full query map. @QueryKey('name') = single query param. |
@Path('id') |
Path param for :id in path. |
@Header('Authorization') |
Request header. |
@DataPath('key') |
Parse from response.data['key']. |
@Part('file') |
Multipart part (with ContentType.formData). |
@StreamResponse() |
Return stream (SSE / line stream). |
[CallOptions? options] |
Optional positional per-call options (cancelToken, clientKey). Use {CallOptions? options} when the method has other named params. See Annotations. |
Future<List<T>> + T.fromJson |
Generator auto maps JSON arrays into models instead of direct as List<T> cast. |
More: Annotations · Configuration · Multiple clients · Example
Run example #
cd example && flutter pub get && dart run build_runner build --delete-conflicting-outputs && flutter run