retrofit 0.2.0

  • Installing
  • Versions
  • 87

Retrofit For Dart #

retrofit.dart is an dio client generator using source_gen and inspired by Chopper and Retrofit.

Usage #

Generator #

Add the generator to your dev dependencies



Define and Generate your API #

import 'package:retrofit/http.dart';
import 'package:dio/dio.dart';

part 'demo.retrofit.dart';

@RestApi(baseUrl: "")
abstract class RestClient {
  static final RestClient instance([Dio dio]) = _RestClient(dio);

    "Header-One": " header 1",
  Future<Response<String>> ip(@Query('query1') String query,
      {@QueryMap() Map<String, dynamic> queryies,
      @Header("Header-Two") String header});

  Future<Response<String>> profile(@Path("id") String id,
      {@Query("role") String role = "user",
      @QueryMap() Map<String, dynamic> map = const {},
      @Body() Map<String, dynamic> map2});

    "Accept": "application/json",
  Future<Response<String>> createProfile(@Query('query2') String query,
      {@QueryMap() Map<String, dynamic> queryies,
      @Header("Header-One") String header,
      @Body() Map<String, dynamic> map2,
      @Field() int field,
      @Field("field-g") String ffff});

  Future<Response<String>> updateProfile2(@Query('query3') String query,
      {@QueryMap() Map<String, dynamic> queryies,
      @Header("Header-One") String header,
      @Field() int field,
      @Field("field-g") String ffff});

  Future<Response<String>> updateProfile(@Query('query4') String query,
      {@QueryMap() Map<String, dynamic> queryies,
      @Field() int field,
      @Field("field-g") String ffff});

then run the generator

pub run build_runner build

flutter packages pub run build_runner build

Use it #

import 'package:retrofit_example/demo.dart';
import 'package:dio/dio.dart';

main(List<String> args) {
  final dio = Dio();
  dio.options.headers["Demo-Header"] = "demo header";
  final client = RestClient.instance(dio);

  client.ip("trevor").then((it) => print(it));

Changelog #

0.2.0 #

  • Added @Extra to pass extra options to dio requests, response, transformer and interceptors.

    Example :

      Future<Response<String>>> myMethod();
  • Fixed general dart style and code conventions

  • Automatically null check with ArgumentError.checkNotNull for required parameters

  • Now SuperClasses can use forwarding/redirecting constructors instead of static instance() method

    Example :

      @RestApi(baseUrl: "")
      abstract class RestClient {
          /// Forwarding constructor
          factory RestClient([Dio dio]) = _RestClient;

0.1.0 #

  • fix health issues

0.0.1 #

  • init

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  retrofit: ^0.2.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:retrofit/dio.dart';
import 'package:retrofit/http.dart';
Version Uploaded Documentation Archive
0.2.0 May 27, 2019 Go to the documentation of retrofit 0.2.0 Download retrofit 0.2.0 archive
0.1.2 May 5, 2019 Go to the documentation of retrofit 0.1.2 Download retrofit 0.1.2 archive
0.1.1 Apr 23, 2019 Go to the documentation of retrofit 0.1.1 Download retrofit 0.1.1 archive
0.1.0 Apr 11, 2019 Go to the documentation of retrofit 0.1.0 Download retrofit 0.1.0 archive
0.0.2 Apr 11, 2019 Go to the documentation of retrofit 0.0.2 Download retrofit 0.0.2 archive
0.0.1 Apr 7, 2019 Go to the documentation of retrofit 0.0.1 Download retrofit 0.0.1 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on May 29, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.17


Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Health suggestions

Fix lib/http.dart. (-0.50 points)

Analysis of lib/http.dart reported 1 hint:

line 35 col 18: Don't explicitly initialize variables to null.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and retrofit.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
meta ^1.1.6 1.1.7