xanno 0.0.4+1
xanno: ^0.0.4+1 copied to clipboard
Use annotations to simplify development @GApi @GAssets @GColor @GEntity @GFormatter @GHttp @GIconFont @GProject @GRoute @GSize
xanno version 0.0.4+1 #
Use annotations to simplify development @GApi @GAssets @GColor @GEntity @GFormatter @GHttp @GIconFont @GProject @GRoute @GSize
Getting Started #
command ==》./build.sh #
1:Network data entity object, using annotation @GEntity(json: "", auto: true), Generate the JSON to DART conversion and generate the API/Entity_Factory.entity. dart for internal use in network requests
@GEntity Example use of annotations
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:For pages that need to jump, page widgets annotate @groute ('/other', 'other home '), Generate the route/main.route.dart method
@GRoute Example use of annotations
@GRoute(url: '/', title: 'main')
class MainPage extends StatefulWidget {
final String title;
MainPage({Key key, this.title}) : super(key: key);
_MainPageState createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
return Container();
}
}
3:API/API_INTERface. dart APIInterface defines methods for network requests, The API/Api_Factory.Interface. dart ApiFactory class is automatically generated
@apiInterface/@GET/@POST Example use of annotations
@Interface(host: 'http://yj.xxxx.cn/')
abstract class ApiInterface {
///***************************使用样例***************************
@GET(url: "/tags")
@Extra({'extraKey': 1, 'extraKey2': '2'})
Future<List<dynamic>> getTags(@CancelRequest() CancelToken cancelReq);
@GET(url: "/tags")
Stream<List<String>> getTagsAsStream();
@GET(url: "/tasks")
Future<List<dynamic>> getTasks();
@GET(url: "/tasks/{id}")
Future<dynamic> getTask(@Path("id") String id);
@PATCH(url: "/tasks/{id}")
Future<dynamic> updateTaskPart(
@Path() String id, @Body() Map<String, dynamic> map);
@PUT(url: "/tasks/{id}")
Future<dynamic> updateTask(@Path() String id, @Body() dynamic task);
@DELETE(url: "/tasks/{id}")
Future<void> deleteTask(@Path() String id);
@POST(url: "/tasks")
Future<dynamic> createTask(@Body() dynamic task);
@POST(url: "/tasks")
Future<List<dynamic>> createTasks(@Body() List<dynamic> tasks);
@POST(url: "/tasks")
Future<List<String>> createTaskNames(@Body() List<String> tasks);
@POST(host: "http://httpbin.org/post")
Future<void> createNewTaskFromFile(@Part() File file);
@Headers({"accept": "image/jpeg"})
@GET(host: "http://httpbin.org/image/jpeg")
@DioResponseType(ResponseType.bytes)
Future<List<int>> getFile();
@POST(host: "http://httpbin.org/post")
@FormUrlEncoded()
Future<String> postUrlEncodedFormData(
@Field() String hello, {
@Field() String gg,
});
@HEAD(url: '/')
Future<String> headRequest();
@HEAD(url: '/')
Future headRquest2();
@HEAD(url: '/')
Future<HttpResponse> headRquest3();
@GET(url: "/task/group")
Future<List<dynamic>> grouppedTaskByDate();
@GET(url: "/task")
Future<HttpResponse<List<dynamic>>> getTasksWithReponse();
@DELETE(url: "/tasks/{id}")
Future<HttpResponse<void>> deleteTaskWithResponse(@Path() String id);
@POST(url: "/post")
Future<String> postFormData(@Part() dynamic task, {@Part() File file});
@POST(url: "/post")
Future<String> postFormData2(
@Part() List<Map<String, dynamic>> task,
@Part() List<String> tags,
@Part(contentType: 'application/json') File file);
@POST(url: "/post")
Future<String> postFormData3(
{@Part(value: "customfiles", contentType: 'application/json')
List<File> files,
@Part()
File file});
@POST(url: "/post")
Future<String> postFormData6(
{@Part(value: "customfiles") List<List<int>> files,
@Part() List<int> file});
@POST(url: "/post")
Future<String> postFormData4(@Part() List<dynamic> tasks, @Part() File file);
@POST(url: "/post")
Future<String> postFormData5(
@Part() List<dynamic> tasks,
@Part() Map<String, dynamic> map,
@Part() int a, {
@Part() bool b,
@Part() double c,
@Part() String d,
});
@GET(url: '/demo')
Future<String> queries(@Queries() Map<String, dynamic> queries);
@GET(url: '/enums')
Future<String> queryByEnum(@Query('tasks') dynamic query);
@GET(url: "/get")
Future<String> namedExample(@Query("apikey") String apiKey,
@Query("scope") String scope, @Query("type") String type,
{@Query("from") int from});
@POST(url: "/postfile")
@Headers({
"Content-Type": "application/octet-stream",
"Ocp-Apim-Subscription-Key": "abc"
})
Future<String> postFile({
@Body() File file,
@SendProgress() Function sendProgress,
@ReceiveProgress() Function receiveProgress,
});
@GET(url: "")
Future<String> testCustomOptions(@DioOptions() Options options);
///***************************使用样例***************************
}
4: Automatic registration of @GAssets ('assets') resources, no need to manually add resources to YAML (currently only supports assets:), automatic mapping to common/assets_constant.assets.dart
5: Automatic formatting and detection of code over 300 lines @GFormatter (auto: true, maxLine: 300), lib file plus all Dart source code formatting and detection.
6: Auto register @GIconfont (prefix: '', networkUrl: '// ') to generate widget/icon_font.iconfont
7: Automated generation of @GApi (init: true) lib/ API network related resources
8: Auto Generate @GColor(init: true) Auto Collect all places using Color Uniform Management common/color_constant.color.dart
9: AutoGenerate @GSize (init: true) AutoCollect all places that use Size uniformly manage common/size_constant.size.dart
10: Automatically generate @GProject (init: true) base project code
Annotations use examples
@GApi(init: true)
@GColor(init: true)
@GSize(init: true)
@GAssets(assetsPath: 'assets')
@GFormatter(auto: true)
@GIconfont(prefix: '', url: '//at.alicdn.com/t/font_2276902_tfhdmqlk7gd.js')
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),
);
}
}