Watch 1 Star 1 Fork 0

请叫我code哥 / HW-CheckerDartApache-2.0

Join us
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
flutter工程:自动生成route注册, entity JSON转Dart, http Retrofit风格请求,assets资源自动注册和映射到Dart spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

hw_checker

A new Flutter project.

Getting Started

命令 ==》./build.sh

1:网络数据实体对象,使用注解 @GEntity(json: "", auto: true), 生成json to dart的转换,并生成api/entity_factory.entity.dart,网络请求内部使用

@GEntity注解使用示例
import 'package:xanno/anno/entity/entity.dart';

@GEntity(json: '''
{
    "name": "爸爸",
    "age": 30,
    "wife": {
        "name": "妈妈",
        "age": 28,
        "beautiful": true
    },
    "childList": [
        {
            "name": "孩子1",
            "age": 1,
            "sex": "男"
        },
        {
            "name": "孩子2",
            "age": 2,
            "sex": "女"
        }
    ]
}
''', auto: true)
class JsonEntity {}

2:需要跳转的页面,页面widget用注解 @GRoute('/other', '其它主页'), 生成route/main.route.dart相关方法

@GRoute注解使用示例
@GRoute('/debug', 'debug-route')
class DebugMainPage extends StatefulWidget {
  final String title;

  DebugMainPage({Key key, this.title}) : super(key: key);

  _DebugMainPageState createState() => _DebugMainPageState();
}

class _DebugMainPageState extends State<DebugMainPage> {

  @override
  Widget build(BuildContext context) {
      return Container();
  }
}

///无Context跳转
RouteNavigator.pushNamed(RouteConstant.DetectionDecibelPage);

3:自动注册@GAssets('assets')资源,不用人为去yaml里面添加资源(目前只支持 assets:), 自动映射到common/assets_constant.assets.dart

@GAssets注解使用示例
@GAssets('assets')
class App extends StatefulWidget {
  App({Key key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        routes: routes(context),
    );
  }
}

4:网络请求在api/api_interface.dart ApiInterface定义方法, 会自动生成api/api_factory.interface.dart APIFactory类

@apiInterface/@GET/@POST注解使用示例
@apiInterface
abstract class ApiInterface {
  ///目前支持注解 @GET | @POST
  ///注解包含host,url,headers,contentType(也可配置在headers里headers:{"content-type": "application/json; charset=utf-8"),...}
  ///如果为动态url,则在注解中不要传,直接在方法参数中传递url
  ///如果为静态url,则在参数中不要传,直接在注解参数中传递url
  ///所有可配置参数{url, params, body, headers, loading, succ, fail}
  ///需要showLoading,则在参数传loading,不需要则不传
  ///实现类会生成在factory/api_factory.interface.dart
  ///记得在项目根目录下执行 ./build.sh 生成代码

  const ApiInterface();

  @GET(
    url: "getJoke?page=1&count=2&type=video",
    contentType: 'application/json; charset=utf-8',
    headers: {
      // "content-type": "application/json; charset=utf-8", //contentType 也可配置在此处
      "os": "iOS",
      "appVersion": "1.0.0"
    },
  )
  Future<List<TestEntity>> getJoke({params, loading, succ, fail});

  @GET(host: 'https://www.i4.cn/firmware_list.html')
  Future<List<OhterIPSWModel>> getIpsw({url, params, loading, succ, fail});

  ///===============================test示例===============================
  ///参数变化,所有可配置参数{url, params, body, headers, loading, succ, fail}
  @GET(url: "getJoke?page=1&count=2&type=video")
  Future<List<TestEntity>> test1();

  @POST(url: "getJoke?page=1&count=2&type=video")
  Future<List<TestEntity>> test2({params, body});

  @GET(url: "getJoke?page=1&count=2&type=video")
  Future<List<TestEntity>> test3({params, loading});

  @POST(url: "getJoke?page=1&count=2&type=video")
  Future<List<TestEntity>> test4({params, loading, succ});

  @GET(url: "getJoke?page=1&count=2&type=video")
  Future<List<TestEntity>> test5({params, loading, succ, fail});

  ///注解变化,url只能是动态或者静态2种
  ///动态url
  @POST(host: 'https://www.baidu1.com/')
  Future<List<TestEntity>> test6(
      {String url,
      Map params,
      Map body,
      Map headers,
      bool loading,
      Function(List<TestEntity>) succ,
      Function(ErrorEntity) fail});

  ///静态url
  @GET(host: 'https://www.baidu2.com/', url: 'get_appversion')
  Future<List<TestEntity>> test7({params, loading, succ, fail});

  ///静态headers
  @GET(
    host: 'https://www.baidu2.com/',
    url: 'get_appversion',
    headers: {"os": "iOS", "appVersion": "1.0.0"},
  )
  Future<List<TestEntity>> test8({params, loading, succ, fail});

  ///动态headers
  @GET(
    host: 'https://www.baidu2.com/',
    url: 'get_appversion',
  )
  Future<List<TestEntity>> test9({headers, params, loading, succ, fail});

  ///===============================test示例===============================
}

5:自动格式化和检测最大行数超过300代码@GFormatter(auto: true, maxLine: 300),lib文件加下所有dart源码格式化和检测。

@GFormatter注解使用示例
@GFormatter(auto: true, maxLine: 300)
class App extends StatefulWidget {
  App({Key key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        routes: routes(context),
    );
  }
}

6:自动生成文档@GDoc(auto: true),目前直接开放lib路径访问,之后优化成自定义网页可看文件内容。

@GDoc注解使用示例
@GDoc(auto: true)
class App extends StatefulWidget {
  App({Key key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        routes: routes(context),
    );
  }
}

7:自动注册@GIconfont('assets/iconfont/')资源,不用人为去yaml里面添加资源(目前只支持 fonts:), 自动映射到common/iconfont_constant.iconfont.dart

@GIconfont注解使用示例
@GIconfont('assets/iconfont/')
class App extends StatefulWidget {
  App({Key key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        routes: routes(context),
    );
  }
}

8:自动生成@GApi(init: true) lib/api 下网络相关资源

@GApi注解使用示例
@GApi(init: true)
class App extends StatefulWidget {
  App({Key key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        routes: routes(context),
    );
  }
}

Comments ( 0 )

Sign in for post a comment

Dart
1
https://gitee.com/337317439/HW-Checker.git
git@gitee.com:337317439/HW-Checker.git
337317439
HW-Checker
HW-Checker
master

Help Search

205735 778617b6 1899542 205747 347fc4a1 1899542