123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- {
- "index代码片段": {
- "prefix": "tplindex",
- "body": [
- "import 'package:flutter/material.dart';",
- "import 'package:json_annotation/json_annotation.dart';",
- "import 'package:wisdom_cli/wisdom_cli.dart';",
- "import 'store.dart';",
- "import 'view.dart';",
- "part 'index.g.dart';",
- "///路由传递的参数",
- "@JsonSerializable(nullable: false)",
- "class ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArguments {",
- "final String id;",
- "${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArguments({this.id});",
- "",
- "///",
- "///",
- "///",
- "///",
- "///",
- "///",
- "///",
- "//***以下为模板代码谨慎修改***",
- "factory ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArguments.fromJson(Map<String, dynamic> json) {",
- "return _\\$${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArgumentsFromJson(json??{});",
- "}",
- "factory ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArguments.fromRouteArguments(BuildContext context) {",
- "return _\\$${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArgumentsFromJson(",
- "ModalRoute.of(context).settings?.arguments",
- ");",
- "}",
- "Map<String, dynamic> toJson() => _\\$${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArgumentsToJson(this);",
- "}",
- "///",
- "///",
- "///",
- "///",
- "///",
- "//***以下为模板代码谨慎修改***",
- "class ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}Page extends StatelessWidget {",
- "const ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}Page({Key key}) : super(key: key);",
- "@override",
- "Widget build(BuildContext context) {",
- "return MultiProvider(",
- "providers: [",
- "ChangeNotifierProvider(create: (_) => ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageStore(context)),",
- "],",
- "child: ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageView(),",
- ");",
- "}",
- "}",
- ],
- "description": "index.dart代码片段"
- },
- "store.dart代码片段": {
- "prefix": "tplstore",
- "body": [
- "import 'package:flutter/material.dart';",
- "import 'package:mobx/mobx.dart';",
- "import 'index.dart';",
- "part 'store.g.dart';",
- "class ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageStore = _${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageStore with _$${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageStore, ChangeNotifier;",
- "abstract class _${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageStore with Store {",
- "///上下文(请勿修改)",
- "final BuildContext context;",
- "///路由参数(请勿修改)",
- "${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArguments get arguments =>",
- "${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageArguments.fromRouteArguments(context);",
- "",
- "_${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageStore(this.context){",
- "///可在此处理进入页面前的操作,比如响应路由的传参进行赋值。",
- "}",
- "///",
- "//@observable",
- "//int value;",
- "}",
- ],
- "description": "store.dart代码片段"
- },
- "view.dart代码片段": {
- "prefix": "tplview",
- "body": [
- "import 'package:flutter/material.dart';",
- "import 'package:wisdom_cli/wisdom_cli.dart';",
- "import 'store.dart';",
- "//part 'components/list.dart';",
- "",
- "class ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageView extends StatelessWidget {",
- "const ${TM_DIRECTORY/.*pages\\/(.)/${1:/upcase}/}PageView({Key key}) : super(key: key);",
- "@override",
- "Widget build(BuildContext context) {",
- "// final store = Provider.of<${TM_DIRECTORY/.*pages\\/([a-z])(.*)/${1:/upcase}${2}/}PageStore>(context, listen: false) ;",
- "// final style = WTheme.of(context);",
- "// final colorScheme = style.colorScheme;",
- "return Scaffold(",
- "///",
- ");",
- "}",
- "}",
- ],
- "description": "view.dart代码片段"
- },
- "component代码片段": {
- "prefix": "tplcomponent",
- "body": [
- "part of '../view.dart';",
- "",
- "class _${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}Component extends StatelessWidget {",
- "const _${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}Component({Key key}) : super(key: key);",
- "@override",
- "Widget build(BuildContext context) {",
- "// final store = Provider.of<${TM_DIRECTORY/.*pages\\/([a-z])(.*)\\/.*/${1:/upcase}${2}/}PageStore>(context, listen: false) ;",
- "// final style = WTheme.of(context);",
- "// final colorScheme = style.colorScheme;",
- "return Container();",
- "}",
- "}",
- ],
- "description": "component代码片段"
- },
- "globalcomponent代码片段": {
- "prefix": "tplglobalcomponent",
- "body": [
- "import 'package:flutter/material.dart';",
- "class ${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}Component extends StatelessWidget {",
- "const ${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}Component({Key key}) : super(key: key);",
- "@override",
- "Widget build(BuildContext context) {",
- "// final style = WTheme.of(context);",
- "// final colorScheme = theme.colorScheme;",
- "return Container();",
- "}",
- "}",
- ],
- "description": "全局component代码片段"
- },
- "globalstore代码片段": {
- "prefix": "tplglobalstore",
- "body": [
- "import 'package:mobx/mobx.dart';",
- "part '${TM_FILENAME_BASE}.g.dart';",
- "class ${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}GlobalStore = _${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}GlobalStore with _$${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}GlobalStore;",
- "abstract class _${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}GlobalStore with Store {",
- "@observable",
- "int value;",
- "}",
- ],
- "description": "全局store代码片段"
- },
- "model代码片段": {
- "prefix": "tplmodel",
- "body": [
- "import 'package:json_annotation/json_annotation.dart';",
- "part '${TM_FILENAME_BASE}.g.dart';",
- "@JsonSerializable(nullable: false)",
- "class ${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g} {",
- "final String value;",
- "${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}({this.value});",
- "///",
- "///",
- "///",
- "///",
- "///",
- "///",
- "///",
- "//***以下为模板代码谨慎修改***",
- "factory ${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}.fromJson(Map<String, dynamic> json) =>",
- "_$${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}FromJson(json);",
- "Map<String, dynamic> toJson() => _$${TM_FILENAME_BASE/(^.)|_(.{1})/${1:/upcase}${2:/upcase}/g}ToJson(this);",
- "}",
- ],
- "description": "全局store代码片段"
- },
- "api single代码片段": {
- "prefix": "tplapisingle",
- "body": [
- "static Future<ResModel<${3:Type}>> ${1:apiName}(data) async {",
- "var res = await HttpUtil.instance.get(",
- "'$prefix/${2:path}',",
- "queryParameters: data,",
- ");",
- "",
- "return ResModel<${3:Type}>(",
- "json: res.data,",
- "to: (v) => v,",
- "from: (v) => v,",
- ");",
- "}",
- ],
- "description": "data只返回了一个单字段"
- },
- "api map代码片段": {
- "prefix": "tplapimap",
- "body": [
- "static Future<ResModel<${3:DataModel}>> ${1:apiName}(data) async {",
- "var res = await HttpUtil.instance.get(",
- "'$prefix/${2:path}',",
- "queryParameters: data,",
- ");",
- "",
- "return ResModel<${3:DataModel}>(",
- "json: res.data,",
- "to: (v) => v.toJson(),",
- "from: (v) => ${3:DataModel}.fromJson(v),",
- ");",
- "}",
- ],
- "description": "data返回了一个map"
- },
- "api list代码片段": {
- "prefix": "tplapilist",
- "body": [
- "static Future<ResModel<List<${3:ItemModel}>>> ${1:apiName}(data) async {",
- "var res = await HttpUtil.instance.get(",
- "'$prefix/${2:path}',",
- "queryParameters: data,",
- ");",
- "",
- "return ResModel<List<${3:ItemModel}>>(",
- "json: res.data,",
- "to: (v) => (v ?? []).map((f) => f.toJson()).toList(),",
- "from: (v) => (v ?? []).map<${3:ItemModel}>((f) => ${3:ItemModel}.fromJson(f)).toList(),",
- ");",
- "}",
- ],
- "description": "data返回了一个list"
- },
- "api paging代码片段": {
- "prefix": "tplapipaging",
- "body": [
- "static Future<ResModel<PagingModel<${3:ItemModel}>>> ${1:apiName}(data) async {",
- "var res = await HttpUtil.instance.get(",
- "'$prefix/${2:path}',",
- "queryParameters: data,",
- ");",
- "",
- "return ResModel<PagingModel<${3:ItemModel}>>(",
- "json: res.data,",
- "to: (v) => v.toJson(),",
- "from: (v) => PagingModel(",
- "json: v,",
- "to: (v) => v.toJson(),",
- "from: (v) => ${3:ItemModel}.fromJson(v),",
- "),",
- ");",
- "}",
- ],
- "description": "data返回了分页数据"
- },
- "getList代码片段": {
- "prefix": "tplGetList",
- "body": [
- "final scrollViewKey = GlobalKey<WisScrollViewState>();",
- "late Map params = {",
- "'pageNum': 1,",
- " 'pageSize': 20,",
- "};",
- "List<ItemModel> list = [];",
- "Future getList({bool isLoad = true}) async {",
- "if (!isLoad) params['pageNum'] = 1;",
- "var res = await NameApi.getList({",
- "...params,",
- "});",
- "final _data = res?.data;",
- "final _list = _data?.list ?? [];",
- "if ((_data?.total ?? 0) == 0) {",
- "scrollViewKey.currentState.isEmpty();",
- "} else if ((_data?.pages ?? 0) <= (_data?.pageNum ?? 0)) {",
- "scrollViewKey.currentState.isLast();",
- "} else {",
- "params['pageNum']++;",
- "}",
- "isLoad ? list.addAll(_list) : list = _list;",
- "notifyListeners();",
- "}",
- ],
- "description": "getList代码片段"
- },
- }
|