net_retrofit_kit 0.2.8 copy "net_retrofit_kit: ^0.2.8" to clipboard
net_retrofit_kit: ^0.2.8 copied to clipboard

discontinuedreplaced by: net_retrofit_dio

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. @Body() accept [...]

中文 | English

pub License

net_retrofit_kit #

Declarative HTTP client for Flutter: annotations + codegen, based on Dio. GitHub


Quick start #

1. Dependencies

dependencies:
  net_retrofit_kit: ^0.2.8
  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).

More: Annotations · Configuration · Multiple clients · Example


Run example #

cd example && flutter pub get && dart run build_runner build --delete-conflicting-outputs && flutter run

Example project

1
likes
0
points
19
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

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. @Body() accepts Map<String, dynamic> or a class model; for non-Map types the generator emits body.toJson(), so models must implement toJson.

Repository (GitHub)
View/report issues

Topics

#flutter #networking #retrofit #code-generation #dio

License

unknown (license)

Dependencies

analyzer, build, dio, flutter, source_gen

More

Packages that depend on net_retrofit_kit