retrofit_generator 1.0.1+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 87

See retrofit.dart

Changelog #

1.0.1 #

  • Add dio response type support

1.0.0 #

  • Support dio 3.0

0.6.3+1 #

  • Fix #53, Pin version of dio to 2.1.16

0.6.3 #

  • [BREAKING CHANGE] Requires retrofit: ^0.6.3
  • Respect user option autoCastResponse (this will skip .fromJson)
  • Allow custom classes without .toJson method (generator will throw warning)

0.6.2 #

  • fix: fix bad cast exception (#47)
  • add CancelToken, SendProgress, and ReceiveProgress (#46)

0.6.1 #

  • Fixed inner type parsing #44

0.6.0 #

  • [BREAKING CHANGE] only works dart 2.2.2 and above
  • Added support to multiple clients with different base urls.

0.5.0 #

0.4.3 #

  • Minor fix

0.4.2 #

  • Added support to generate strong mode compatible source code

0.4.1 #

  • Added generic auto casting for Map<String, List<Model>> or Map<String, Model>

0.4.0 #

Added bean class support for @Body() annotation.

Here's the example.

    Future<String> createUser(@Body() User user);
    class User {
        Map<String, dynamic> toJson() => {};
    }

please notice that: You have to provide a toJson() method to the bean classes to return a Map<String, dynamic>.

0.3.0 #

Added support for generic serialization.

Please note:

It doesn't support nested generics.

0.2.3 #

  • Added support for File form fields. See example in retrofit.dart readme.

0.2.2 #

  • bump to 0.2.2

0.2.1 #

  • Fixed pub upload issue

0.2.0 #

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

    Example :

    @http.POST('/path/')
    @dio.Extra({'my_key':'my_value'})
    Future<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: "https://httpbin.org/")
    abstract class RestClient {
        /// Forwarding constructor
        factory RestClient([Dio dio]) = _RestClient;
    }
    

0.1.0 #

  • fix health issues

0.0.1 #

  • init

example/lib/example.dart

import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart' hide Headers;
import 'dart:io';

part 'example.g.dart';

@RestApi(baseUrl: "https://5d42a6e2bc64f90014a56ca0.mockapi.io/api/v1/")
abstract class RestClient {
  factory RestClient(Dio dio) = _RestClient;

  @GET("/tasks")
  Future<List<Task>> getTasks();

  @GET("/tasks/{id}")
  Future<Task> getTask(@Path("id") String id);

  @PATCH("/tasks/{id}")
  Future<Task> updateTaskPart(
      @Path() String id, @Body() Map<String, dynamic> map);

  @PUT("/tasks/{id}")
  Future<Task> updateTask(@Path() String id, @Body() Task task);

  @DELETE("/tasks/{id}")
  Future<void> deleteTask(@Path() String id);

  @POST("/tasks")
  Future<Task> createTask(@Body() Task task);

  @POST("http://httpbin.org/post")
  Future<void> createNewTaskFromFile(@Field() File file);

  @Headers(<String, String>{"accept": "image/jpeg"})
  @GET("http://httpbin.org/image/jpeg")
  @DioResponseType(ResponseType.bytes)
  Future<List<int>> getFile();

  @POST('/')
  @FormUrlEncoded()
  Future<String> postFormData();
}

@JsonSerializable()
class Task {
  String id;
  String name;
  String avatar;
  String createdAt;

  Task({this.id, this.name, this.avatar, this.createdAt});

  factory Task.fromJson(Map<String, dynamic> json) => _$TaskFromJson(json);
  Map<String, dynamic> toJson() => _$TaskToJson(this);
}

Use this package as a library

1. Depend on it

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


dependencies:
  retrofit_generator: ^1.0.1+2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support 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_generator/builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
87
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: other

Platform components identified in package: build, io, mirrors.

Health issues and suggestions

Document public APIs. (-1 points)

2 out of 2 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/generator.dart. (-1.49 points)

Analysis of lib/src/generator.dart reported 3 hints:

line 320 col 7: DO use curly braces for all flow control structures.

line 324 col 7: DO use curly braces for all flow control structures.

line 328 col 7: DO use curly braces for all flow control structures.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
built_collection ^4.2.0 4.2.2
code_builder ^3.2.0 3.2.0
dio ^3.0.1 3.0.3
retrofit ^1.0.1 1.0.1
source_gen ^0.9.4+2 0.9.4+5
tuple ^1.0.2 1.0.3
Transitive dependencies
analyzer 0.38.5
args 1.5.2
async 2.4.0
build 1.2.0
built_value 6.7.1
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.3.1
fixnum 0.10.9
front_end 0.1.27
glob 1.2.0
html 0.14.0+3
http_parser 3.1.3
js 0.6.1+1
kernel 0.3.27
logging 0.11.3+2
matcher 0.12.5
meta 1.1.7
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
path 1.6.4
pedantic 1.8.0+1
pub_semver 1.4.2
quiver 2.0.5
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.2.0
Dev dependencies
source_gen_test any
test any