diff --git a/lib/base/base_state_widget.dart b/lib/base/base_state_widget.dart index accef8a..d40eb66 100644 --- a/lib/base/base_state_widget.dart +++ b/lib/base/base_state_widget.dart @@ -1,6 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:qinglong_app/base/common_dialog.dart'; +import 'package:qinglong_app/utils/extension.dart'; import 'base_viewmodel.dart'; class BaseStateWidget extends ConsumerStatefulWidget { @@ -21,7 +21,8 @@ class BaseStateWidget extends ConsumerStatefulWidget { _BaseStateWidgetState createState() => _BaseStateWidgetState(); } -class _BaseStateWidgetState extends ConsumerState> { +class _BaseStateWidgetState + extends ConsumerState> { @override void initState() { super.initState(); @@ -39,7 +40,7 @@ class _BaseStateWidgetState extends ConsumerState(widget.model); if (viewModel.failedToast != null) { WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { - failDialog(context, viewModel.failedToast!); + (viewModel.failedToast ?? "").toast(); viewModel.clearToast(); }); } diff --git a/lib/base/common_dialog.dart b/lib/base/common_dialog.dart deleted file mode 100644 index 6294661..0000000 --- a/lib/base/common_dialog.dart +++ /dev/null @@ -1,222 +0,0 @@ -import 'dart:async'; - -import 'package:back_button_interceptor/back_button_interceptor.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -/// @author newtab on 2021/7/16 -///常用loading,fail,success对话框 -class CommonDialog extends StatelessWidget { - final String? text; - final CommonDialogState? commonDialogState; - - const CommonDialog({Key? key, this.text, this.commonDialogState}) : super(key: key); - - @override - Widget build(BuildContext context) { - Widget loading; - - if (commonDialogState == CommonDialogState.FAILED) { - loading = const Icon( - CupertinoIcons.clear_circled, - size: 50, - ); - } else if (commonDialogState == CommonDialogState.SUCCESS) { - loading = const Icon( - CupertinoIcons.checkmark_alt, - size: 50, - ); - } else { - loading = LoadingIcon(); - } - - Widget result = Material( - color: Colors.transparent, - child: Align( - alignment: Alignment.center, - child: Container( - decoration: BoxDecoration(color: Color.fromRGBO(17, 17, 17, 0.7), borderRadius: BorderRadius.circular(5)), - constraints: BoxConstraints( - maxWidth: MediaQuery.of(context).size.width / 2, - minWidth: 122, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - margin: const EdgeInsets.only(top: 15.0), - constraints: BoxConstraints( - minHeight: 40, - ), - child: IconTheme( - data: const IconThemeData( - color: Colors.white, - size: 40.0, - ), - child: loading), - ), - const SizedBox( - height: 15, - ), - if (text != null) - Padding( - padding: const EdgeInsets.only( - left: 15, - right: 15, - bottom: 15, - ), - child: DefaultTextStyle( - textAlign: TextAlign.center, - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: const TextStyle(color: Colors.white, fontSize: 14), - child: Text(text!), - ), - ), - ], - ), - ), - ), - ); - - return result; - } -} - -class LoadingIcon extends StatefulWidget { - final double size; - - LoadingIcon({this.size = 50.0}); - - @override - State createState() => LoadingIconState(); -} - -class LoadingIconState extends State with SingleTickerProviderStateMixin { - AnimationController? _controller; - Animation? _doubleAnimation; - - @override - void initState() { - super.initState(); - _controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 1000))..repeat(); - _doubleAnimation = Tween(begin: 0.0, end: 360.0).animate(_controller!) - ..addListener(() { - setState(() {}); - }); - } - - @override - void dispose() { - _controller?.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Transform.rotate( - angle: _doubleAnimation!.value ~/ 30 * 30.0 * 0.0174533, child: Image.asset("assets/images/loading.png", width: widget.size, height: widget.size)); - } -} - -enum CommonDialogState { - LOADING, - SUCCESS, - FAILED, -} - -typedef HideCallback = Future Function(); - -int backButtonIndex = 2; - -OverlayEntry? overlay; - -HideCallback showCommonDialog( - BuildContext context, { - String? text, - bool backButtonClose = false, - CommonDialogState commonDialogState = CommonDialogState.LOADING, -}) { - Completer result = Completer(); - var backButtonName = 'QL_Toast$backButtonIndex'; - BackButtonInterceptor.add((stopDefaultButtonEvent, _) { - if (backButtonClose) { - result.future.then((hide) { - hide(); - }); - } - return true; - }, zIndex: backButtonIndex, name: backButtonName); - backButtonIndex++; - - if (overlay != null && overlay!.mounted) { - overlay?.remove(); - overlay = null; - } - overlay = OverlayEntry( - maintainState: true, - builder: (_) => WillPopScope( - onWillPop: () async { - var hide = await result.future; - hide(); - return false; - }, - child: CommonDialog( - text: text, - commonDialogState: commonDialogState, - ), - ), - ); - result.complete(() { - overlay?.remove(); - overlay = null; - BackButtonInterceptor.removeByName(backButtonName); - }); - if (overlay != null) { - Overlay.of(context)?.insert(overlay!); - } - - return () async { - var hide = await result.future; - hide(); - }; -} - -Future successDialog(BuildContext context, String text) { - HideCallback hideCallback = showCommonDialog( - context, - text: text, - commonDialogState: CommonDialogState.SUCCESS, - backButtonClose: true, - ); - return Future.delayed( - Duration( - milliseconds: 1000, - ), () { - hideCallback(); - }); -} - -Future failDialog(BuildContext context, String text) { - HideCallback hideCallback = showCommonDialog( - context, - text: text, - commonDialogState: CommonDialogState.FAILED, - backButtonClose: true, - ); - return Future.delayed( - Duration( - milliseconds: 1000, - ), () { - hideCallback(); - }); -} - -HideCallback loadingDialog(BuildContext context, {String? text}) { - return showCommonDialog( - context, - text: text, - commonDialogState: CommonDialogState.LOADING, - backButtonClose: true, - ); -} diff --git a/lib/base/http/api.dart b/lib/base/http/api.dart index b0cc8c6..12fcdcf 100644 --- a/lib/base/http/api.dart +++ b/lib/base/http/api.dart @@ -10,9 +10,10 @@ import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart'; import 'url.dart'; class Api { - static Future> login(String userName, String passWord) async { + static Future> login( + String userName, String passWord) async { return await Http.post( - Url.LOGIN, + Url.login, { "username": userName, "password": passWord, @@ -21,90 +22,104 @@ class Api { } static Future>> crons() async { - return await Http.get>(Url.TASKS, {"searchValue": ""}); + return await Http.get>(Url.tasks, {"searchValue": ""}); } - static Future> startTasks(List crons) async { - return await Http.put(Url.RUN_TASKS, crons); + static Future> startTasks( + List crons) async { + return await Http.put(Url.runTasks, crons); } - static Future> stopTasks(List crons) async { - return await Http.put(Url.RUN_TASKS, crons); + static Future> stopTasks( + List crons) async { + return await Http.put(Url.runTasks, crons); } static Future> inTimeLog(String cron) async { - return await Http.get(Url.INTIME_LOG(cron), null); + return await Http.get(Url.intimeLog(cron), null); } static Future> taskDetail(String cron) async { - return await Http.get(Url.TASK_DETAIL + cron, null); + return await Http.get(Url.taskDetail + cron, null); } - static Future> addTask(String name, String command, String cron, {String? id}) async { + static Future> addTask( + String name, String command, String cron, + {String? id}) async { var data = {"name": name, "command": command, "schedule": cron}; if (id != null) { data["_id"] = id; - return await Http.put(Url.ADD_TASK, data); + return await Http.put(Url.addTask, data); } - return await Http.post(Url.ADD_TASK, data); + return await Http.post(Url.addTask, data); } static Future> delTask(String cron) async { - return await Http.delete(Url.ADD_TASK, [cron]); + return await Http.delete(Url.addTask, [cron]); } static Future> pinTask(String cron) async { - return await Http.put(Url.PIN_TASK, [cron]); + return await Http.put(Url.pinTask, [cron]); } static Future> unpinTask(String cron) async { - return await Http.put(Url.UNPIN_TASK, [cron]); + return await Http.put(Url.unpinTask, [cron]); } static Future> enableTask(String cron) async { - return await Http.put(Url.ENABLE_TASK, [cron]); + return await Http.put(Url.enableTask, [cron]); } static Future> disableTask(String cron) async { - return await Http.put(Url.DISABLE_TASK, [cron]); + return await Http.put(Url.disableTask, [cron]); } static Future>> files() async { - return await Http.get>(Url.FILES, null); + return await Http.get>(Url.files, null); } static Future> content(String name) async { - return await Http.get(Url.CONFIG_CONTENT + name, null); + return await Http.get(Url.configContent + name, null); } - static Future> saveFile(String name, String content) async { - return await Http.post(Url.SAVE_FILE, {"content": content, "name": name}); + static Future> saveFile( + String name, String content) async { + return await Http.post( + Url.saveFile, {"content": content, "name": name}); } static Future>> envs(String search) async { - return await Http.get>(Url.ENVS, {"searchValue": search}); + return await Http.get>(Url.envs, {"searchValue": search}); } static Future> enableEnv(String id) async { - return await Http.put(Url.ENABLE_ENVS, [id]); + return await Http.put(Url.enableEnvs, [id]); } static Future> disableEnv(String id) async { - return await Http.put(Url.DISABLE_ENVS, [id]); + return await Http.put(Url.disableEnvs, [id]); } static Future> delEnv(String id) async { - return await Http.delete(Url.DEL_ENV, [id]); + return await Http.delete(Url.delEnv, [id]); } - static Future> addEnv(String name, String value, String remarks, {String? id}) async { + static Future> addEnv( + String name, String value, String remarks, + {String? id}) async { var data = {"value": value, "remarks": remarks, "name": name}; if (id != null) { data["_id"] = id; - return await Http.put(Url.ADD_ENV, data); + return await Http.put(Url.addEnv, data); } - return await Http.post(Url.ADD_ENV, [data]); + return await Http.post(Url.addEnv, [data]); + } + + static Future> moveEnv( + String id, int fromIndex, int toIndex) async { + return await Http.put( + Url.envMove(id), {"fromIndex": fromIndex, "toIndex": toIndex}); } } diff --git a/lib/base/http/http.dart b/lib/base/http/http.dart index fc7ad88..0af6ad0 100644 --- a/lib/base/http/http.dart +++ b/lib/base/http/http.dart @@ -38,7 +38,8 @@ class Http { } } - static Future> get(String uri, Map? json, {bool compute = true}) async { + static Future> get(String uri, Map? json, + {bool compute = true}) async { try { _init(); var response = await _dio!.get(uri, queryParameters: json); @@ -48,11 +49,15 @@ class Http { if (e.response?.statusCode == 401) { exitLogin(); } - return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0); + return HttpResponse( + success: false, + message: e.response?.statusMessage ?? e.message, + code: 0); } } - static Future> post(String uri, dynamic json, {bool compute = true}) async { + static Future> post(String uri, dynamic json, + {bool compute = true}) async { try { _init(); var response = await _dio!.post(uri, data: json); @@ -62,11 +67,15 @@ class Http { if (e.response?.statusCode == 401) { exitLogin(); } - return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0); + return HttpResponse( + success: false, + message: e.response?.statusMessage ?? e.message, + code: 0); } } - static Future> delete(String uri, dynamic json, {bool compute = true}) async { + static Future> delete(String uri, dynamic json, + {bool compute = true}) async { try { _init(); var response = await _dio!.delete(uri, data: json); @@ -76,11 +85,15 @@ class Http { if (e.response?.statusCode == 401) { exitLogin(); } - return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0); + return HttpResponse( + success: false, + message: e.response?.statusMessage ?? e.message, + code: 0); } } - static Future> put(String uri, dynamic json, {bool compute = true}) async { + static Future> put(String uri, dynamic json, + {bool compute = true}) async { try { _init(); var response = await _dio!.put(uri, data: json); @@ -89,7 +102,10 @@ class Http { if (e.response?.statusCode == 401) { exitLogin(); } - return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0); + return HttpResponse( + success: false, + message: e.response?.statusMessage ?? e.message, + code: 0); } } @@ -98,7 +114,7 @@ class Http { static void exitLogin() { if (!pushedLoginPage) { pushedLoginPage = true; - navigatorState.currentState?.pushReplacementNamed(Routes.route_LOGIN); + navigatorState.currentState?.pushReplacementNamed(Routes.routeLogin); } } @@ -182,7 +198,8 @@ class HttpResponse { late int code; T? bean; - HttpResponse({required this.success, this.message, required this.code, this.bean}); + HttpResponse( + {required this.success, this.message, required this.code, this.bean}); } class DeserializeAction { diff --git a/lib/base/http/token_interceptor.dart b/lib/base/http/token_interceptor.dart index e42da6c..33dfc2b 100644 --- a/lib/base/http/token_interceptor.dart +++ b/lib/base/http/token_interceptor.dart @@ -6,13 +6,17 @@ import '../userinfo_viewmodel.dart'; class TokenInterceptor extends Interceptor { @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { - if (getIt().token != null && getIt().token!.isNotEmpty) { - options.headers["Authorization"] = "Bearer " + getIt().token!; + if (getIt().token != null && + getIt().token!.isNotEmpty) { + options.headers["Authorization"] = + "Bearer " + getIt().token!; } - options.headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"; + options.headers["User-Agent"] = + "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"; options.headers["Content-Type"] = "application/json;charset=UTF-8"; - options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch~/1000).toString(); + options.queryParameters["t"] = + (DateTime.now().millisecondsSinceEpoch ~/ 1000).toString(); return handler.next(options); } } diff --git a/lib/base/http/url.dart b/lib/base/http/url.dart index b41966f..448136b 100644 --- a/lib/base/http/url.dart +++ b/lib/base/http/url.dart @@ -1,24 +1,28 @@ class Url { - static const LOGIN = "/api/user/login"; - static const TASKS = "/api/crons"; - static const RUN_TASKS = "/api/crons/run"; - static const STOP_TASKS = "/api/crons/stop"; - static const TASK_DETAIL = "/api/crons/"; - static const ADD_TASK = "/api/crons"; - static const PIN_TASK = "/api/crons/pin"; - static const UNPIN_TASK = "/api/crons/unpin"; - static const ENABLE_TASK = "/api/crons/enable"; - static const DISABLE_TASK = "/api/crons/disable"; - static const FILES = "/api/configs/files"; - static const CONFIG_CONTENT = "/api/configs/"; - static const SAVE_FILE = "/api/configs/save"; - static const ENVS = "/api/envs"; - static const ADD_ENV = "/api/envs"; - static const DEL_ENV = "/api/envs"; - static const DISABLE_ENVS = "/api/envs/disable"; - static const ENABLE_ENVS = "/api/envs/enable"; + static const login = "/api/user/login"; + static const tasks = "/api/crons"; + static const runTasks = "/api/crons/run"; + static const stopTasks = "/api/crons/stop"; + static const taskDetail = "/api/crons/"; + static const addTask = "/api/crons"; + static const pinTask = "/api/crons/pin"; + static const unpinTask = "/api/crons/unpin"; + static const enableTask = "/api/crons/enable"; + static const disableTask = "/api/crons/disable"; + static const files = "/api/configs/files"; + static const configContent = "/api/configs/"; + static const saveFile = "/api/configs/save"; + static const envs = "/api/envs"; + static const addEnv = "/api/envs"; + static const delEnv = "/api/envs"; + static const disableEnvs = "/api/envs/disable"; + static const enableEnvs = "/api/envs/enable"; - static INTIME_LOG(String cronId) { + static intimeLog(String cronId) { return "/api/crons/$cronId/log"; } + + static envMove(String envId) { + return "/api/envs/$envId/move"; + } } diff --git a/lib/base/routes.dart b/lib/base/routes.dart index 1c2895e..474b8a5 100644 --- a/lib/base/routes.dart +++ b/lib/base/routes.dart @@ -9,19 +9,19 @@ import 'package:qinglong_app/module/task/add_task_page.dart'; import 'package:qinglong_app/module/task/task_bean.dart'; class Routes { - static const String route_HomePage = "/home/homepage"; - static const String route_LOGIN = "/login"; - static const String route_AddTask = "/task/add"; - static const String route_AddEnv = "/env/add"; - static const String route_ConfigEdit = "/config/edit"; + static const String routeHomePage = "/home/homepage"; + static const String routeLogin = "/login"; + static const String routeAddTask = "/task/add"; + static const String routeAddEnv = "/env/add"; + static const String routeConfigEdit = "/config/edit"; static Route? generateRoute(RouteSettings settings) { switch (settings.name) { - case route_HomePage: + case routeHomePage: return MaterialPageRoute(builder: (context) => const HomePage()); - case route_LOGIN: + case routeLogin: return MaterialPageRoute(builder: (context) => const LoginPage()); - case route_AddTask: + case routeAddTask: if (settings.arguments != null) { return CupertinoPageRoute( builder: (context) => AddTaskPage( @@ -30,7 +30,7 @@ class Routes { } else { return CupertinoPageRoute(builder: (context) => const AddTaskPage()); } - case route_AddEnv: + case routeAddEnv: if (settings.arguments != null) { return CupertinoPageRoute( builder: (context) => AddEnvPage( @@ -39,7 +39,7 @@ class Routes { } else { return CupertinoPageRoute(builder: (context) => const AddEnvPage()); } - case route_ConfigEdit: + case routeConfigEdit: return CupertinoPageRoute( builder: (context) => ConfigEditPage( (settings.arguments as Map)["title"], diff --git a/lib/base/sp_const.dart b/lib/base/sp_const.dart index 322510d..c924c19 100644 --- a/lib/base/sp_const.dart +++ b/lib/base/sp_const.dart @@ -1,3 +1,3 @@ String sp_UserINfo = "userinfo"; String sp_Host = "host"; -String sp_Theme = "dart_mode"; \ No newline at end of file +String sp_Theme = "dart_mode"; diff --git a/lib/base/ui/abs_underline_tabindicator.dart b/lib/base/ui/abs_underline_tabindicator.dart index e3139ee..7b258b0 100644 --- a/lib/base/ui/abs_underline_tabindicator.dart +++ b/lib/base/ui/abs_underline_tabindicator.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; - ///tabbar样式下方横条固定宽度 class AbsUnderlineTabIndicator extends Decoration { const AbsUnderlineTabIndicator({ @@ -44,7 +43,8 @@ class AbsUnderlineTabIndicator extends Decoration { } class _UnderlinePainter extends BoxPainter { - _UnderlinePainter(this.decoration, VoidCallback? onChanged) : super(onChanged); + _UnderlinePainter(this.decoration, VoidCallback? onChanged) + : super(onChanged); final AbsUnderlineTabIndicator decoration; @@ -56,7 +56,11 @@ class _UnderlinePainter extends BoxPainter { final Rect indicator = insets!.resolve(textDirection).deflateRect(rect); //取中间坐标 double cw = (indicator.left + indicator.right) / 2; - return Rect.fromLTWH(cw - decoration.wantWidth! / 2, indicator.bottom - borderSide!.width, decoration.wantWidth!, borderSide!.width); + return Rect.fromLTWH( + cw - decoration.wantWidth! / 2, + indicator.bottom - borderSide!.width, + decoration.wantWidth!, + borderSide!.width); } @override @@ -64,8 +68,9 @@ class _UnderlinePainter extends BoxPainter { assert(configuration.size != null); final Rect rect = offset & configuration.size!; final TextDirection textDirection = configuration.textDirection!; - final Rect indicator = _indicatorRectFor(rect, textDirection).deflate(borderSide!.width / 2.0); + final Rect indicator = + _indicatorRectFor(rect, textDirection).deflate(borderSide!.width / 2.0); final Paint paint = borderSide!.toPaint()..strokeCap = StrokeCap.round; canvas.drawLine(indicator.bottomLeft, indicator.bottomRight, paint); } -} \ No newline at end of file +} diff --git a/lib/base/ui/empty_widget.dart b/lib/base/ui/empty_widget.dart index 00990b6..daf9125 100644 --- a/lib/base/ui/empty_widget.dart +++ b/lib/base/ui/empty_widget.dart @@ -7,7 +7,7 @@ class EmptyWidget extends ConsumerWidget { const EmptyWidget({Key? key}) : super(key: key); @override - Widget build(BuildContext context,WidgetRef ref) { + Widget build(BuildContext context, WidgetRef ref) { return Center( child: Column( mainAxisSize: MainAxisSize.min, @@ -16,7 +16,7 @@ class EmptyWidget extends ConsumerWidget { "暂无数据", style: TextStyle( fontSize: 14, - color:ref.watch(themeProvider).themeColor.descColor(), + color: ref.watch(themeProvider).themeColor.descColor(), ), ), ], diff --git a/lib/base/ui/menu.dart b/lib/base/ui/menu.dart index 5932e69..4c03878 100644 --- a/lib/base/ui/menu.dart +++ b/lib/base/ui/menu.dart @@ -19,7 +19,7 @@ class QLCupertinoContextMenuAction extends StatefulWidget { this.isDestructiveAction = false, this.onPressed, this.trailingIcon, - }) : assert(child != null), + }) : assert(child != null), assert(isDefaultAction != null), assert(isDestructiveAction != null), super(key: key); @@ -45,10 +45,12 @@ class QLCupertinoContextMenuAction extends StatefulWidget { final IconData? trailingIcon; @override - State createState() => _QLCupertinoContextMenuActionState(); + State createState() => + _QLCupertinoContextMenuActionState(); } -class _QLCupertinoContextMenuActionState extends State { +class _QLCupertinoContextMenuActionState + extends State { static const Color _kBackgroundColor = Color(0xFFEEEEEE); static const Color _kBackgroundColorPressed = Color(0xFFDDDDDD); static const double _kButtonHeight = 30.0; @@ -96,7 +98,6 @@ class _QLCupertinoContextMenuActionState extends State(dynamic json) { + static M fromJson(dynamic json) { if (json is List) { return _getListChildType(json); } else { @@ -18,53 +16,57 @@ class JsonConversion$Json { } static M _fromJsonSingle(dynamic json) { - String type = M.toString(); - if(type == (ConfigBean).toString()){ - return ConfigBean.jsonConversion(json) as M; + if (type == (ConfigBean).toString()) { + return ConfigBean.jsonConversion(json) as M; } - - if(type == (EnvBean).toString()){ - return EnvBean.jsonConversion(json) as M; + + if (type == (EnvBean).toString()) { + return EnvBean.jsonConversion(json) as M; } - - if(type == (LoginBean).toString()){ - return LoginBean.jsonConversion(json) as M; + + if (type == (LoginBean).toString()) { + return LoginBean.jsonConversion(json) as M; } - - if(type == (TaskBean).toString()){ - return TaskBean.jsonConversion(json) as M; + + if (type == (TaskBean).toString()) { + return TaskBean.jsonConversion(json) as M; } - - if(type == (TaskDetailBean).toString()){ - return TaskDetailBean.jsonConversion(json) as M; + + if (type == (TaskDetailBean).toString()) { + return TaskDetailBean.jsonConversion(json) as M; } - + throw Exception("not found"); } static M _getListChildType(List data) { - if([] is M){ - return data.map((e) => ConfigBean.jsonConversion(e)).toList() as M; + if ([] is M) { + return data.map((e) => ConfigBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ + + if ([] is M) { return data.map((e) => EnvBean.jsonConversion(e)).toList() as M; } - - if([] is M){ - return data.map((e) => LoginBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data.map((e) => LoginBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ - return data.map((e) => TaskBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data.map((e) => TaskBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ - return data.map((e) => TaskDetailBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data + .map((e) => TaskDetailBean.jsonConversion(e)) + .toList() as M; } - + throw Exception("not found"); } } diff --git a/lib/main.dart b/lib/main.dart index cf64079..20633dd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -35,7 +35,8 @@ void main() async { ), ); if (Platform.isAndroid) { - SystemUiOverlayStyle style = const SystemUiOverlayStyle(statusBarColor: Colors.transparent); + SystemUiOverlayStyle style = + const SystemUiOverlayStyle(statusBarColor: Colors.transparent); SystemChrome.setSystemUIOverlayStyle(style); } } @@ -60,7 +61,9 @@ class MyApp extends ConsumerWidget { home: Builder( builder: (context) { showDebugBtn(context, btnColor: Colors.blue); - return getIt().isLogined() ? const HomePage() : LoginPage(); + return getIt().isLogined() + ? const HomePage() + : LoginPage(); }, ), // home: LoginPage(), diff --git a/lib/module/a.dart b/lib/module/a.dart index e69de29..8b13789 100644 --- a/lib/module/a.dart +++ b/lib/module/a.dart @@ -0,0 +1 @@ + diff --git a/lib/module/config/config_bean.dart b/lib/module/config/config_bean.dart index 6d2d905..56396e0 100644 --- a/lib/module/config/config_bean.dart +++ b/lib/module/config/config_bean.dart @@ -2,7 +2,6 @@ import 'package:json_conversion_annotation/json_conversion_annotation.dart'; @JsonConversion() class ConfigBean { - String? title; String? value; @@ -19,6 +18,7 @@ class ConfigBean { data['value'] = this.value; return data; } + static ConfigBean jsonConversion(Map json) { return ConfigBean.fromJson(json); } diff --git a/lib/module/config/config_edit_page.dart b/lib/module/config/config_edit_page.dart index 5a0d8b5..9036416 100644 --- a/lib/module/config/config_edit_page.dart +++ b/lib/module/config/config_edit_page.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:qinglong_app/base/common_dialog.dart'; import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/ql_app_bar.dart'; import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/module/config/config_viewmodel.dart'; +import 'package:qinglong_app/utils/extension.dart'; class ConfigEditPage extends ConsumerStatefulWidget { final String content; @@ -41,15 +41,16 @@ class _ConfigEditPageState extends ConsumerState { InkWell( onTap: () async { if (value == null) { - failDialog(context, "请先点击保存"); + "请先点击保存".toast(); return; } - HttpResponse response = await Api.saveFile(widget.title, _controller.text); + HttpResponse response = + await Api.saveFile(widget.title, _controller.text); if (response.success) { ref.read(configProvider).loadContent(widget.title); Navigator.of(context).pop(); } else { - failDialog(context, response.message ?? ""); + (response.message ?? "").toast(); } }, child: const Padding( diff --git a/lib/module/config/config_page.dart b/lib/module/config/config_page.dart index d5ef862..d51b9ff 100644 --- a/lib/module/config/config_page.dart +++ b/lib/module/config/config_page.dart @@ -16,7 +16,8 @@ class ConfigPage extends StatefulWidget { ConfigPageState createState() => ConfigPageState(); } -class ConfigPageState extends State with SingleTickerProviderStateMixin { +class ConfigPageState extends State + with SingleTickerProviderStateMixin { TabController? _tabController; @override @@ -28,7 +29,8 @@ class ConfigPageState extends State with SingleTickerProviderStateMi Widget build(BuildContext context) { return BaseStateWidget( builder: (ref, model, child) { - _tabController ??= TabController(length: model.list.length, vsync: this); + _tabController ??= + TabController(length: model.list.length, vsync: this); return Column( children: [ @@ -60,7 +62,10 @@ class ConfigPageState extends State with SingleTickerProviderStateMi padding: const EdgeInsets.symmetric( horizontal: 15, ), - theme: ref.watch(themeProvider).themeColor.codeEditorTheme(), + theme: ref + .watch(themeProvider) + .themeColor + .codeEditorTheme(), tabSize: 14, ), ), @@ -80,9 +85,10 @@ class ConfigPageState extends State with SingleTickerProviderStateMi void editMe(WidgetRef ref) { if (_tabController == null || _tabController!.length == 0) return; - navigatorState.currentState?.pushNamed(Routes.route_ConfigEdit, arguments: { + navigatorState.currentState?.pushNamed(Routes.routeConfigEdit, arguments: { "title": ref.read(configProvider).list[_tabController?.index ?? 0].title, - "content": ref.read(configProvider).content[ref.read(configProvider).list[_tabController?.index ?? 0].title] + "content": ref.read(configProvider).content[ + ref.read(configProvider).list[_tabController?.index ?? 0].title] }); } } diff --git a/lib/module/env/add_env_page.dart b/lib/module/env/add_env_page.dart index 2f04575..0a6c131 100644 --- a/lib/module/env/add_env_page.dart +++ b/lib/module/env/add_env_page.dart @@ -1,14 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:qinglong_app/base/common_dialog.dart'; import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/ql_app_bar.dart'; import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/env/env_viewmodel.dart'; -import 'package:qinglong_app/module/task/task_bean.dart'; -import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart'; -import 'package:qinglong_app/module/task/task_viewmodel.dart'; +import 'package:qinglong_app/utils/extension.dart'; class AddEnvPage extends ConsumerStatefulWidget { final EnvBean? taskBean; @@ -180,11 +177,11 @@ class _AddEnvPageState extends ConsumerState { void submit() async { if (_nameController.text.isEmpty) { - failDialog(context, "名称不能为空"); + "名称不能为空".toast(); return; } if (_valueController.text.isEmpty) { - failDialog(context, "值不能为空"); + "值不能为空".toast(); return; } @@ -196,12 +193,11 @@ class _AddEnvPageState extends ConsumerState { id: envBean.sId); if (response.success) { - successDialog(context, "操作成功").then((value) { - ref.read(envProvider).updateEnv(envBean); - Navigator.of(context).pop(); - }); + "操作成功".toast(); + ref.read(envProvider).updateEnv(envBean); + Navigator.of(context).pop(); } else { - failDialog(context, response.message ?? ""); + (response.message ?? "").toast(); } } } diff --git a/lib/module/env/env_bean.dart b/lib/module/env/env_bean.dart index 53b6e6c..1cf32f9 100644 --- a/lib/module/env/env_bean.dart +++ b/lib/module/env/env_bean.dart @@ -12,12 +12,12 @@ class EnvBean { EnvBean( {this.value, - this.sId, - this.created, - this.status, - this.timestamp, - this.name, - this.remarks}); + this.sId, + this.created, + this.status, + this.timestamp, + this.name, + this.remarks}); EnvBean.fromJson(Map json) { value = json['value']; @@ -40,7 +40,8 @@ class EnvBean { data['remarks'] = this.remarks; return data; } + static EnvBean jsonConversion(Map json) { return EnvBean.fromJson(json); } -} \ No newline at end of file +} diff --git a/lib/module/env/env_page.dart b/lib/module/env/env_page.dart index c4f1b45..bac4f48 100644 --- a/lib/module/env/env_page.dart +++ b/lib/module/env/env_page.dart @@ -1,17 +1,16 @@ import 'dart:io'; -import 'package:drag_and_drop_lists/drag_and_drop_lists.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:qinglong_app/base/base_state_widget.dart'; -import 'package:qinglong_app/base/common_dialog.dart'; import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/ui/empty_widget.dart'; import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/env/env_viewmodel.dart'; +import 'package:qinglong_app/utils/extension.dart'; class EnvPage extends StatefulWidget { const EnvPage({Key? key}) : super(key: key); @@ -50,14 +49,12 @@ class _EnvPageState extends State { return model.loadData(false); }, child: ReorderableListView( - keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, + keyboardDismissBehavior: + ScrollViewKeyboardDismissBehavior.onDrag, header: searchCell(ref), onReorder: (int oldIndex, int newIndex) { if (list.length != model.list.length) { - WidgetsBinding.instance - ?.addPostFrameCallback((timeStamp) { - failDialog(context, "请先清空搜索关键词"); - }); + "请先清空搜索关键词".toast(); return; } @@ -68,7 +65,7 @@ class _EnvPageState extends State { } final EnvBean item = model.list.removeAt(oldIndex); model.list.insert(newIndex, item); - model.update(); + model.update(item.sId ?? "", newIndex, oldIndex); }); }, children: list, @@ -146,7 +143,7 @@ class EnvItemCell extends StatelessWidget { flex: 1, onPressed: (_) { Navigator.of(context) - .pushNamed(Routes.route_AddEnv, arguments: bean); + .pushNamed(Routes.routeAddEnv, arguments: bean); }, foregroundColor: Colors.white, icon: CupertinoIcons.pencil, diff --git a/lib/module/env/env_viewmodel.dart b/lib/module/env/env_viewmodel.dart index 30fb65f..2673885 100644 --- a/lib/module/env/env_viewmodel.dart +++ b/lib/module/env/env_viewmodel.dart @@ -19,7 +19,6 @@ class EnvViewModel extends BaseViewModel { if (result.success && result.bean != null) { list.clear(); list.addAll(result.bean!); - sortList(); success(); } else { list.clear(); @@ -27,12 +26,6 @@ class EnvViewModel extends BaseViewModel { } } - void sortList() { - list.sort((a, b) { - return a.status!.compareTo(b.status!); - }); - } - Future delEnv(String id) async { HttpResponse result = await Api.delEnv(id); if (result.success) { @@ -61,7 +54,6 @@ class EnvViewModel extends BaseViewModel { if (response.success) { list.firstWhere((element) => element.sId == sId).status = 0; - sortList(); success(); } else { failToast(response.message, notify: true); @@ -71,14 +63,15 @@ class EnvViewModel extends BaseViewModel { if (response.success) { list.firstWhere((element) => element.sId == sId).status = 1; - sortList(); success(); } else { failToast(response.message, notify: true); } } } - void update(){ - // update + + void update(String id, int newIndex, int oldIndex) async { + await Api.moveEnv(id, oldIndex, newIndex); + loadData(false); } } diff --git a/lib/module/home/home_page.dart b/lib/module/home/home_page.dart index 1d63211..e485889 100644 --- a/lib/module/home/home_page.dart +++ b/lib/module/home/home_page.dart @@ -38,7 +38,7 @@ class _HomePageState extends ConsumerState { actions.add(InkWell( onTap: () { Navigator.of(context).pushNamed( - Routes.route_AddTask, + Routes.routeAddTask, ); }, child: const Padding( @@ -58,7 +58,7 @@ class _HomePageState extends ConsumerState { actions.add(InkWell( onTap: () { Navigator.of(context).pushNamed( - Routes.route_AddEnv, + Routes.routeAddEnv, ); }, child: const Padding( diff --git a/lib/module/login/login_bean.dart b/lib/module/login/login_bean.dart index 9cb4ac4..c686f77 100644 --- a/lib/module/login/login_bean.dart +++ b/lib/module/login/login_bean.dart @@ -11,11 +11,11 @@ class LoginBean { LoginBean( {this.token, - this.lastip, - this.lastaddr, - this.lastlogon, - this.retries, - this.platform}); + this.lastip, + this.lastaddr, + this.lastlogon, + this.retries, + this.platform}); LoginBean.fromJson(Map json) { token = json['token']; @@ -36,6 +36,7 @@ class LoginBean { data['platform'] = this.platform; return data; } + static LoginBean jsonConversion(Map json) { return LoginBean.fromJson(json); } diff --git a/lib/module/login/login_page.dart b/lib/module/login/login_page.dart index 3c9b2f0..788e547 100644 --- a/lib/module/login/login_page.dart +++ b/lib/module/login/login_page.dart @@ -1,13 +1,13 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:qinglong_app/base/common_dialog.dart'; import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/userinfo_viewmodel.dart'; import 'package:qinglong_app/main.dart'; +import 'package:qinglong_app/utils/extension.dart'; import 'package:qinglong_app/utils/utils.dart'; import 'login_bean.dart'; @@ -180,24 +180,24 @@ class _LoginPageState extends ConsumerState { isLoading, child: CupertinoButton( color: (_hostController.text.isNotEmpty && - _userNameController.text.isNotEmpty && - _passwordController.text.isNotEmpty && - !isLoading) + _userNameController.text.isNotEmpty && + _passwordController.text.isNotEmpty && + !isLoading) ? ref - .watch(themeProvider) - .themeColor - .buttonBgColor() + .watch(themeProvider) + .themeColor + .buttonBgColor() : Theme.of(context) - .primaryColor - .withOpacity(0.4), + .primaryColor + .withOpacity(0.4), child: isLoading ? const CupertinoActivityIndicator() : const Text( - "登 录", - style: TextStyle( - fontSize: 16, - ), - ), + "登 录", + style: TextStyle( + fontSize: 16, + ), + ), onPressed: () { Http.pushedLoginPage = false; Utils.hideKeyBoard(context); @@ -227,9 +227,9 @@ class _LoginPageState extends ConsumerState { HttpResponse response = await Api.login(userName, password); if (response.success) { getIt().updateToken(response.bean?.token ?? ""); - Navigator.of(context).pushReplacementNamed(Routes.route_HomePage); + Navigator.of(context).pushReplacementNamed(Routes.routeHomePage); } else { - failDialog(context, response.message ?? "请检查网络情况"); + (response.message ?? "请检查网络情况").toast(); isLoading = false; setState(() {}); } diff --git a/lib/module/others/other_page.dart b/lib/module/others/other_page.dart index a58d54e..0c9a11f 100644 --- a/lib/module/others/other_page.dart +++ b/lib/module/others/other_page.dart @@ -213,7 +213,8 @@ class _OtherPageState extends ConsumerState { ), onPressed: () { getIt().updateToken(""); - Navigator.of(context).pushReplacementNamed(Routes.route_LOGIN); + Navigator.of(context) + .pushReplacementNamed(Routes.routeLogin); }), ), ), diff --git a/lib/module/task/add_task_page.dart b/lib/module/task/add_task_page.dart index 6b5df2f..8260910 100644 --- a/lib/module/task/add_task_page.dart +++ b/lib/module/task/add_task_page.dart @@ -1,12 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:qinglong_app/base/common_dialog.dart'; import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/ql_app_bar.dart'; import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart'; import 'package:qinglong_app/module/task/task_viewmodel.dart'; +import 'package:qinglong_app/utils/extension.dart'; class AddTaskPage extends ConsumerStatefulWidget { final TaskBean? taskBean; @@ -180,15 +180,15 @@ class _AddTaskPageState extends ConsumerState { void submit() async { if (_nameController.text.isEmpty) { - failDialog(context, "任务名称不能为空"); + "任务名称不能为空".toast(); return; } if (_commandController.text.isEmpty) { - failDialog(context, "命令不能为空"); + "命令不能为空".toast(); return; } if (_cronController.text.isEmpty) { - failDialog(context, "定时不能为空"); + "定时不能为空".toast(); return; } @@ -200,12 +200,11 @@ class _AddTaskPageState extends ConsumerState { id: taskBean.sId); if (response.success) { - successDialog(context, "操作成功").then((value) { - ref.read(taskProvider).updateBean(taskBean); - Navigator.of(context).pop(); - }); + "操作成功".toast(); + ref.read(taskProvider).updateBean(taskBean); + Navigator.of(context).pop(); } else { - failDialog(context, response.message ?? ""); + response.message.toast(); } } } diff --git a/lib/module/task/intime_log/intime_log_page.dart b/lib/module/task/intime_log/intime_log_page.dart index 68ad43f..41fec4e 100644 --- a/lib/module/task/intime_log/intime_log_page.dart +++ b/lib/module/task/intime_log/intime_log_page.dart @@ -9,7 +9,8 @@ class InTimeLogPage extends StatefulWidget { final String cronId; final bool needTimer; - const InTimeLogPage(this.cronId, this.needTimer, {Key? key}) : super(key: key); + const InTimeLogPage(this.cronId, this.needTimer, {Key? key}) + : super(key: key); @override _InTimeLogPageState createState() => _InTimeLogPageState(); diff --git a/lib/module/task/task_detail/task_detail_bean.dart b/lib/module/task/task_detail/task_detail_bean.dart index fa7d5a7..e648c15 100644 --- a/lib/module/task/task_detail/task_detail_bean.dart +++ b/lib/module/task/task_detail/task_detail_bean.dart @@ -17,17 +17,17 @@ class TaskDetailBean { TaskDetailBean( {this.name, - this.command, - this.schedule, - this.saved, - this.sId, - this.created, - this.status, - this.timestamp, - this.isSystem, - this.isDisabled, - this.logPath, - this.isPinned}); + this.command, + this.schedule, + this.saved, + this.sId, + this.created, + this.status, + this.timestamp, + this.isSystem, + this.isDisabled, + this.logPath, + this.isPinned}); TaskDetailBean.fromJson(Map json) { name = json['name']; diff --git a/lib/module/task/task_detail/task_detail_page.dart b/lib/module/task/task_detail/task_detail_page.dart index 8dbdb98..7e5a81b 100644 --- a/lib/module/task/task_detail/task_detail_page.dart +++ b/lib/module/task/task_detail/task_detail_page.dart @@ -27,7 +27,7 @@ class _TaskDetailPageState extends ConsumerState { builder: (WidgetRef context, TaskDetailViewModel value, Widget? child) { return Container(); }, - onReady: (model){ + onReady: (model) { model.loadDetail(widget.taskBean.sId!); }, ), diff --git a/lib/module/task/task_detail/task_detail_viewmodel.dart b/lib/module/task/task_detail/task_detail_viewmodel.dart index 115f5d5..69bedbe 100644 --- a/lib/module/task/task_detail/task_detail_viewmodel.dart +++ b/lib/module/task/task_detail/task_detail_viewmodel.dart @@ -4,7 +4,8 @@ import 'package:qinglong_app/base/http/api.dart'; import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart'; -var taskDetailProvider = AutoDisposeChangeNotifierProvider((ref) { +var taskDetailProvider = + AutoDisposeChangeNotifierProvider((ref) { return TaskDetailViewModel(); }); diff --git a/lib/module/task/task_page.dart b/lib/module/task/task_page.dart index 958e29a..3e74d43 100644 --- a/lib/module/task/task_page.dart +++ b/lib/module/task/task_page.dart @@ -196,7 +196,7 @@ class TaskItemCell extends StatelessWidget { onPressed: () { Navigator.of(context).pop(); Navigator.of(context) - .pushNamed(Routes.route_AddTask, arguments: bean); + .pushNamed(Routes.routeAddTask, arguments: bean); }, trailingIcon: CupertinoIcons.pencil_outline, ), @@ -435,7 +435,7 @@ class TaskItemCell extends StatelessWidget { onPressed: () { Navigator.pop(context); Navigator.of(context) - .pushNamed(Routes.route_AddTask, arguments: bean); + .pushNamed(Routes.routeAddTask, arguments: bean); }, ), CupertinoActionSheetAction( diff --git a/lib/utils/QlNavigatorObserver.dart b/lib/utils/QlNavigatorObserver.dart index 09e6ac3..a346a72 100644 --- a/lib/utils/QlNavigatorObserver.dart +++ b/lib/utils/QlNavigatorObserver.dart @@ -7,7 +7,7 @@ class QlNavigatorObserver extends NavigatorObserver { @override void didPush(Route route, Route? previousRoute) { super.didPush(route, previousRoute); - if (Routes.route_LOGIN == route.settings.name) { + if (Routes.routeLogin == route.settings.name) { isInLoginPage = true; } else { isInLoginPage = false; diff --git a/lib/utils/codeeditor_theme.dart b/lib/utils/codeeditor_theme.dart index f3edb7f..564e173 100644 --- a/lib/utils/codeeditor_theme.dart +++ b/lib/utils/codeeditor_theme.dart @@ -1,14 +1,13 @@ - import 'package:flutter/material.dart'; const qinglongLightTheme = { 'root': - TextStyle(color: Color(0xff333333), backgroundColor: Color(0xffffffff)), + TextStyle(color: Color(0xff333333), backgroundColor: Color(0xffffffff)), 'comment': TextStyle(color: Color(0xff999988), fontStyle: FontStyle.italic), 'quote': TextStyle(color: Color(0xff999988), fontStyle: FontStyle.italic), 'keyword': TextStyle(color: Color(0xff333333), fontWeight: FontWeight.bold), 'selector-tag': - TextStyle(color: Color(0xff333333), fontWeight: FontWeight.bold), + TextStyle(color: Color(0xff333333), fontWeight: FontWeight.bold), 'subst': TextStyle(color: Color(0xff333333), fontWeight: FontWeight.normal), 'number': TextStyle(color: Color(0xff008080)), 'literal': TextStyle(color: Color(0xff008080)), @@ -19,12 +18,12 @@ const qinglongLightTheme = { 'title': TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), 'section': TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), 'selector-id': - TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), + TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), 'type': TextStyle(color: Color(0xff445588), fontWeight: FontWeight.bold), 'tag': TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), 'name': TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), 'attribute': - TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), + TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), 'regexp': TextStyle(color: Color(0xff009926)), 'link': TextStyle(color: Color(0xff009926)), 'symbol': TextStyle(color: Color(0xff990073)), @@ -39,13 +38,12 @@ const qinglongLightTheme = { }; const qinglongDarkTheme = { - 'root': - TextStyle(color: Color(0xff333333), backgroundColor: Colors.black), + 'root': TextStyle(color: Color(0xff333333), backgroundColor: Colors.black), 'comment': TextStyle(color: Color(0xff999988), fontStyle: FontStyle.italic), 'quote': TextStyle(color: Color(0xff999988), fontStyle: FontStyle.italic), 'keyword': TextStyle(color: Color(0xff333333), fontWeight: FontWeight.bold), 'selector-tag': - TextStyle(color: Color(0xff333333), fontWeight: FontWeight.bold), + TextStyle(color: Color(0xff333333), fontWeight: FontWeight.bold), 'subst': TextStyle(color: Color(0xff333333), fontWeight: FontWeight.normal), 'number': TextStyle(color: Color(0xff008080)), 'literal': TextStyle(color: Color(0xff008080)), @@ -56,12 +54,12 @@ const qinglongDarkTheme = { 'title': TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), 'section': TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), 'selector-id': - TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), + TextStyle(color: Color(0xff990000), fontWeight: FontWeight.bold), 'type': TextStyle(color: Color(0xff445588), fontWeight: FontWeight.bold), 'tag': TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), 'name': TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), 'attribute': - TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), + TextStyle(color: Color(0xff000080), fontWeight: FontWeight.normal), 'regexp': TextStyle(color: Color(0xff009926)), 'link': TextStyle(color: Color(0xff009926)), 'symbol': TextStyle(color: Color(0xff990073)), diff --git a/lib/utils/extension.dart b/lib/utils/extension.dart index bc70745..8dab197 100644 --- a/lib/utils/extension.dart +++ b/lib/utils/extension.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:fluttertoast/fluttertoast.dart'; extension ContextExt on BuildContext { T read(ProviderBase provider) { @@ -10,3 +11,15 @@ extension ContextExt on BuildContext { return (this as WidgetRef).watch(provider); } } + +extension StringExt on String? { + void toast() { + if (this == null || this!.isEmpty) return; + Fluttertoast.showToast( + msg: this!, + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + timeInSecForIosWeb: 1, + ); + } +} diff --git a/lib/utils/sp_utils.dart b/lib/utils/sp_utils.dart index 4cd854f..004766b 100644 --- a/lib/utils/sp_utils.dart +++ b/lib/utils/sp_utils.dart @@ -56,7 +56,8 @@ class SpUtil { } /// get obj list. - static List? getObjList(String key, T f(Map v), {List defValue = const []}) { + static List? getObjList(String key, T f(Map v), + {List defValue = const []}) { List? dataList = getObjectList(key); List? list = dataList?.map((value) { return f(value); @@ -123,7 +124,8 @@ class SpUtil { } /// get string list. - static List getStringList(String key, {List defValue = const []}) { + static List getStringList(String key, + {List defValue = const []}) { if (_prefs == null) return defValue; return _prefs!.getStringList(key) ?? defValue; } @@ -168,4 +170,4 @@ class SpUtil { static bool isInitialized() { return _prefs != null; } -} \ No newline at end of file +} diff --git a/pubspec.lock b/pubspec.lock index 31ce6d9..4165fc2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,238 +5,238 @@ packages: dependency: transitive description: name: _fe_analyzer_shared - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "22.0.0" analyzer: dependency: transitive description: name: analyzer - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.7.2" archive: dependency: transitive description: name: archive - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.1.8" args: dependency: transitive description: name: args - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.3.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.8.2" back_button_interceptor: dependency: "direct main" description: name: back_button_interceptor - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "5.0.2" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" build: dependency: transitive description: name: build - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.2.1" build_config: dependency: transitive description: name: build_config - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" build_daemon: dependency: transitive description: name: build_daemon - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" build_resolvers: dependency: transitive description: name: build_resolvers - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.4" build_runner: dependency: "direct dev" description: name: build_runner - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.7" build_runner_core: dependency: transitive description: name: build_runner_core - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "7.2.3" built_collection: dependency: transitive description: name: built_collection - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "5.1.1" built_value: dependency: transitive description: name: built_value - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "8.1.3" + version: "8.1.4" change_app_package_name: dependency: "direct dev" description: name: change_app_package_name - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.1.3" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" charcode: dependency: transitive description: name: charcode - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.1" checked_yaml: dependency: transitive description: name: checked_yaml - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.1" cli_util: dependency: transitive description: name: cli_util - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.3.5" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" code_builder: dependency: transitive description: name: code_builder - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.1.0" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.15.0" convert: dependency: transitive description: name: convert - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" crypto: dependency: transitive description: name: crypto - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.4" dart_style: dependency: transitive description: name: dart_style - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" dio: dependency: "direct main" description: name: dio - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.0.4" dio_log: dependency: "direct main" description: name: dio_log - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" drag_and_drop_lists: dependency: "direct main" description: name: drag_and_drop_lists - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.3.2+2" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" ffi: dependency: transitive description: name: ffi - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.2" file: dependency: transitive description: name: file - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "6.1.2" fixnum: dependency: transitive description: name: fixnum - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" flutter: @@ -248,49 +248,49 @@ packages: dependency: "direct dev" description: name: flutter_app_name - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.1.1" flutter_highlight: dependency: "direct main" description: name: flutter_highlight - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.7.0" flutter_launcher_icons: dependency: "direct dev" description: name: flutter_launcher_icons - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.9.2" flutter_lints: dependency: "direct dev" description: name: flutter_lints - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.4" flutter_native_splash: dependency: "direct dev" description: name: flutter_native_splash - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.3" flutter_riverpod: dependency: "direct main" description: name: flutter_riverpod - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.3" flutter_slidable: dependency: "direct main" description: name: flutter_slidable - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" flutter_test: @@ -303,312 +303,319 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + url: "https://pub.flutter-io.cn" + source: hosted + version: "8.0.8" frontend_server_client: dependency: transitive description: name: frontend_server_client - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.2" get_it: dependency: "direct main" description: name: get_it - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "7.2.0" glob: dependency: transitive description: name: glob - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" graphs: dependency: transitive description: name: graphs - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" highlight: dependency: transitive description: name: highlight - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.7.0" http_multi_server: dependency: transitive description: name: http_multi_server - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.1" http_parser: dependency: transitive description: name: http_parser - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.0.0" image: dependency: transitive description: name: image - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.1.1" intl: dependency: "direct main" description: name: intl - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.17.0" io: dependency: transitive description: name: io - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.3" js: dependency: transitive description: name: js - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.6.3" json_annotation: dependency: transitive description: name: json_annotation - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.4.0" json_conversion: dependency: "direct dev" description: name: json_conversion - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.0.4" json_conversion_annotation: dependency: "direct main" description: name: json_conversion_annotation - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.0.4" lints: dependency: transitive description: name: lints - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.1" logger: dependency: "direct main" description: name: logger - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" logging: dependency: transitive description: name: logging - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.12.11" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.7.0" mime: dependency: transitive description: name: mime - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.1" package_config: dependency: transitive description: name: package_config - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.8.0" path_provider_linux: dependency: transitive description: name: path_provider_linux - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.5" path_provider_platform_interface: dependency: transitive description: name: path_provider_platform_interface - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.3" path_provider_windows: dependency: transitive description: name: path_provider_windows - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.5" pedantic: dependency: transitive description: name: pedantic - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.11.1" petitparser: dependency: transitive description: name: petitparser - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.4.0" platform: dependency: transitive description: name: platform - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.1.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.2" pool: dependency: transitive description: name: pool - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.5.0" process: dependency: transitive description: name: process - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "4.2.4" pub_semver: dependency: transitive description: name: pub_semver - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" pubspec_parse: dependency: transitive description: name: pubspec_parse - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" riverpod: dependency: transitive description: name: riverpod - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.3" shared_preferences: dependency: "direct main" description: name: shared_preferences - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.12" shared_preferences_android: dependency: transitive description: name: shared_preferences_android - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.10" shared_preferences_ios: dependency: transitive description: name: shared_preferences_ios - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.9" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.4" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.2" shared_preferences_platform_interface: dependency: transitive description: name: shared_preferences_platform_interface - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" shared_preferences_web: dependency: transitive description: name: shared_preferences_web - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.3" shared_preferences_windows: dependency: transitive description: name: shared_preferences_windows - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.4" shelf: dependency: transitive description: name: shelf - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" shelf_web_socket: dependency: transitive description: name: shelf_web_socket - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.1" sky_engine: @@ -620,140 +627,140 @@ packages: dependency: transitive description: name: source_gen - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.3" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.10.0" state_notifier: dependency: transitive description: name: state_notifier - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "0.7.1" + version: "0.7.2+1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" stream_transform: dependency: transitive description: name: stream_transform - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" synchronized: dependency: "direct main" description: name: synchronized - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.0.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.4.3" timing: dependency: transitive description: name: timing - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.0" typed_data: dependency: transitive description: name: typed_data - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.3.0" universal_io: dependency: transitive description: name: universal_io - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.0.4" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.1" watcher: dependency: transitive description: name: watcher - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "1.0.1" web_socket_channel: dependency: transitive description: name: web_socket_channel - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0" win32: dependency: transitive description: name: win32 - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted - version: "2.3.3" + version: "2.3.6" xdg_directories: dependency: transitive description: name: xdg_directories - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "0.2.0" xml: dependency: transitive description: name: xml - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "5.3.1" yaml: dependency: transitive description: name: yaml - url: "https://pub.dartlang.org" + url: "https://pub.flutter-io.cn" source: hosted version: "3.1.0" sdks: diff --git a/pubspec.yaml b/pubspec.yaml index 4aa110e..ea190e9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: get_it: ^7.2.0 flutter_highlight: ^0.7.0 drag_and_drop_lists: ^0.3.2+2 + fluttertoast: ^8.0.8 dev_dependencies: flutter_native_splash: ^1.3.3 diff --git a/test/widget_test.dart b/test/widget_test.dart index a6993ad..d23c01e 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -14,7 +14,4 @@ import 'package:qinglong_app/main.dart'; import 'package:qinglong_app/module/login/login_bean.dart'; import 'package:qinglong_app/module/login/login_viewmodel.dart'; -void main() { - - -} +void main() {}