flutterannotations_generator 1.0.2

FlutterAnnotations #

Description #

Fast Flutter Development. Easy maintenance.

Usage #

Create your REST API interface #

The Rest API works with a @Rest annotated interface. It's the entry point.

  1. Rest

       @Rest(rootUrl: "https://api.biminds.cn/")
       abstract class RestClient {
    
       }
    
  2. Annotate your own RestClient class with @Get

        @Rest(rootUrl: "https://api.biminds.cn/")
        abstract class RestClient {
    
         // OK
         @Get(path: "queryTeachers")
         List getData(@Param() String name,@Param() int id);
    
         // OK
         @Get(path: "queryTeachers/{name}")
         List getData(@Path() String name,@Param() int id);
    
         // OK
         @Get(path: "queryTeachers?name={name}")
         List getData(@Path() String name,@Param() int id);
    
         // OK
         @Get(path: "queryTeachers?name={name}&id={id}")
         Map getData(@Path() String name,@Param() int id);
    
         // OK
         @Get(path: "queryTeachers/{name}/{id}")
         dynamic getData(@Path() String name,@Param() int id); 
    
         // WRONG
         @Get(path: "queryTeachers")
         getData(@Body() String name);// Wrong, `@Body` can't be defined in `@Get`.
    
         // WRONG
         @Get(path: "queryTeachers/{name}/{id}")
         getData(@Path() String name); // Wrong, "id" must be defined with `@Path`.
    
         // WRONG
         @Get(path: "queryTeachers/{name}/{id}")
         getData(@Path() String name,@Param() int id); // Wrong, "id" must be defined with `@Path`.
    
         // WRONG
         @Get(path: "queryTeachers/{name}/{id}")
         Map getData(@Param() String name,@Param() int id); // Wrong, "name"  and "id" must be defined with `@Path`.
    
         // WRONG
         @Get(path: "queryTeachers")
         List<HomeBannerModel> getData<L>(@Param() String name,@Param() int id); // Wrong, method return must be HomeBannerModel
    
         // OK
         @Get(path: "queryTeachers")
         HomeBannerModel getData<L>(@Param() String name,@Param() int id); // OK, method return must be HomeBannerModel
    
         // WRONG
         @Get(path: "queryTeachers")
         Map<HomeBannerModel> getData<M>(@Param() String name,@Param() int id); // Wrong, method return must be HomeBannerModel
    
         // OK
         @Get(path: "queryTeachers")
         HomeBannerModel getData<M>(@Param() String name,@Param() int id); // OK, method return must be HomeBannerModel        
    
       }
    
  3. Annotate your own RestClient class with Post

       @Rest(rootUrl: "https://api.biminds.cn/")
       abstract class RestClient {
    
         // OK
         @Post(path: "updateTeacherInfo")
         Map postData(@Body() Map map);      
       }
    
  4. Annotate your own RestClient class with Delete

       @Rest(rootUrl: "https://api.biminds.cn/")
       abstract class RestClient {
    
         // OK
         @Delete(path: "deleteTeacherById")
         deleteDate(@Param() String name,@Param() int id);
    
         // OK
         @Delete(path: "deleteTeacherById/{name}")
         deleteDate(@Path() String name,@Param() int id);
    
         // OK
         @Delete(path: "deleteTeacherById?name={name}")
         deleteDate(@Path() String name,@Param() int id);
    
         // OK
         @Delete(path: "deleteTeacherById?name={name}&id={id}")
         deleteDate(@Path() String name,@Param() int id);
    
         // OK
         @Delete(path: "deleteTeacherById/{name}/{id}")
         deleteDate(@Path() String name,@Param() int id);
    
         // WRONG
         @Delete(path: "deleteTeacherById")
         deleteDate(@Body() String name);// Wrong, `@Body` can't be defined in `@Delete`.
    
         // WRONG
         @Delete(path: "deleteTeacherById/{name}/{id}")
         deleteDate(@Path() String name); // Wrong, "id" must be defined with `@Path`.
    
         // WRONG
         @Delete(path: "deleteTeacherById/{name}/{id}")
         deleteDate(@Path() String name,@Param() int id); // Wrong, "id" must be defined with `@Path`.
    
         // WRONG
         @Delete(path: "deleteTeacherById/{name}/{id}")
         deleteDate(@Param() String name,@Param() int id); // Wrong, "name"  and "id" must be defined with `@Path`.
    
       }
    
  5. Annotate your own RestClient class with Put

       @Rest(rootUrl: "https://api.biminds.cn/")
       abstract class RestClient {
    
         ///更新数据
         /// comment
         @Put(path: "updateTeacher")
         updateTeacher(@Body() Map map);
    
  }
6. run the command below in your workspace  
   build:

flutter packages pub run build_runner build --delete-conflicting-outputs

   suggest you running the clean command before build:  
    clean:

flutter packages pub run build_runner clean

Installation #

install from packages #

add packages to dev_dependencies in your pubspec.yaml
example:

dev_dependencies:
  flutterannotations_generator: ^1.0.2

install from source code #

clone the code, then put it into your workspace, announce it in your pubspec.yaml example:

dev_dependencies:
  flutterannotations_generator:
    path: flutterannotations_generator

1.0.2 #

  • fix the parameter of 'failCallback'
  • fix the ' DioError [DioErrorType.RESPONSE]: data parsing exception...' bug

1.0.1 #

  • add interceptors in 'Rest' annotation
  • add the field 'name' which the annotations of method parameters
  • add the parameters of the 'Rest', resultData,resultMessage,resultCode
  • add header in 'Get'、'Post'、'Put'、'Delete' annotation
  • add @Header annotation as parameters
  • fix bugs

1.0.0 #

  • add return
  • fix bugs

0.0.1 #

  • TODO: Describe initial release.

example/lib/example.dart

//export 'package:flutterannotations_generator_example/src/rest_client.dart';

Use this package as a library

1. Depend on it

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


dependencies:
  flutterannotations_generator: ^1.0.2

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:flutterannotations_generator/flutterannotations_generator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:flutterannotations_generator/flutterannotations_generator.dart.

Health issues and suggestions

Document public APIs. (-1 points)

1 out of 1 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.

Maintenance issues and suggestions

Support latest dependencies. (-30 points)

The version constraint in pubspec.yaml does not support the latest published versions for 3 dependencies (analyzer, build_config, mustache4dart).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
analyzer ^0.36.0 0.36.4 0.37.0
build ^1.1.3 1.1.5
build_config ^0.3.1+4 0.3.2 0.4.1
flutterannotations ^1.0.2 1.0.2
mustache4dart ^3.0.0-dev.0.0 3.0.0-dev.0.0 3.0.0-dev.1.0
source_gen ^0.9.4+2 0.9.4+2
Transitive dependencies
args 1.5.2
async 2.2.0
charcode 1.1.2
collection 1.14.11
convert 2.1.1
cookie_jar 1.0.1
crypto 2.0.6
csslib 0.16.1
dart_style 1.2.9
dio 2.1.13
front_end 0.1.19 0.1.20
glob 1.1.7
html 0.14.0+2
json_annotation 2.4.0
kernel 0.3.19 0.3.20
logging 0.11.3+2
meta 1.1.7
package_config 1.0.5
path 1.6.2
pedantic 1.8.0+1
pub_semver 1.4.2
pubspec_parse 0.1.4
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
yaml 2.1.16
Dev dependencies
build_runner ^1.3.1
test any

Admin