0 purchases
xanno
Language: English | 中文简体 #
Packages: xanno
xanno #
Use annotations to simplify development @GApi @GAssets @GColor @GEntity @GFormatter @GHttp @GIconFont @GProject @GRoute @GSize
Getting Started #
1:auto create project, using annotation @GProject(),
import 'package:xanno/xanno.dart';
@GProject()
void main() {}
copied to clipboard
dev_dependencies:
source_gen: ^1.2.7
build_runner: ^2.3.3
intl_utils: ^2.8.2
xanno: ^0.0.9+8
run: flutter pub get && flutter packages pub run build_runner clean && flutter packages pub run build_runner build && flutter pub get
command ==》make #
2: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 #
@GEntity(json: '''
{
"name": "name1",
"age": 30,
"wife": {
"name": "name2",
"age": 28,
"beautiful": true
},
"childList": [
{
"name": "child1",
"age": 1,
"sex": "男"
},
{
"name": "child2",
"age": 2,
"sex": "女"
}
]
}
''', auto: true)
class JsonEntity {}
copied to clipboard
3: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();
}
}
copied to clipboard
4: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: 'https://api.muxiaoguo.cn/api/')
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")
@Extra({'isLoading': true})
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(int, int)? sendProgress,
@ReceiveProgress() Function(int, int)? receiveProgress,
});
@GET(url: "")
Future<String> testCustomOptions(@DioOptions() Options options);
///***************************使用样例***************************
}
copied to clipboard
5: 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 #
6: Automatic formatting and detection of code over 300 lines @GFormatter (maxLine: 300), lib file plus all Dart source code formatting and detection #
7: Auto register @GIconfont (url: '// ') to generate widget/icon_font.iconfont #
8: Automated generation of @GApi () lib/ API network related resources #
9: Auto Generate @GColor() Auto Collect all places using Color Uniform Management common/color_constant.color.dart #
10: AutoGenerate @GSize () AutoCollect all places that use Size uniformly manage common/size_constant.size.dart #
11: Automatically generate @GJenkinsfile () automatically generate Jenkinsfile file continuous integration #
Annotations use examples #
@GApi()
@GColor()
@GSize()
@GAssets(path: 'assets')
@GFormatter()
@GIconfont(url: '//at.alicdn.com/t/font_xxxx_g48kd9v3h54.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),
);
}
}
copied to clipboard
related reference libraries and projects #
observable_builder (lightweight Flutter state management library with support for local refreshes and state caching.)
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.