From 4a25f07e8aceb3f09c04e1f23c09488abe0145d2 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Thu, 21 Jan 2021 14:03:23 +0800 Subject: [PATCH] refactor logger View --- lib/pages/sign/sign_in_page.dart | 2 +- lib/pages/splash/splash_page.dart | 4 +- lib/utils/logger/logger_card.dart | 33 ------- lib/utils/logger/logger_data.dart | 14 --- lib/utils/logger/logger_dio_err.dart | 61 ------------ lib/utils/logger/logger_dio_success.dart | 113 ----------------------- lib/utils/logger/logger_view.dart | 109 ---------------------- lib/utils/network/net_util.dart | 2 +- pubspec.lock | 41 +++++++- pubspec.yaml | 7 +- 10 files changed, 48 insertions(+), 338 deletions(-) delete mode 100644 lib/utils/logger/logger_card.dart delete mode 100644 lib/utils/logger/logger_data.dart delete mode 100644 lib/utils/logger/logger_dio_err.dart delete mode 100644 lib/utils/logger/logger_dio_success.dart delete mode 100644 lib/utils/logger/logger_view.dart diff --git a/lib/pages/sign/sign_in_page.dart b/lib/pages/sign/sign_in_page.dart index c02dd143..832ce07a 100644 --- a/lib/pages/sign/sign_in_page.dart +++ b/lib/pages/sign/sign_in_page.dart @@ -10,7 +10,6 @@ import 'package:akuCommunity/pages/sign/sign_up/sign_up_pick_plot_page.dart'; import 'package:akuCommunity/pages/tab_navigator.dart'; import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart'; -import 'package:akuCommunity/utils/logger/logger_data.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; import 'package:dio/dio.dart'; @@ -22,6 +21,7 @@ import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/assets_image.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart' hide Response; +import 'package:power_logger/power_logger.dart'; import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index 3d0807a8..3f1a458a 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -1,13 +1,13 @@ import 'package:akuCommunity/pages/tab_navigator.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/hive_store.dart'; -import 'package:akuCommunity/utils/logger/logger_view.dart'; import 'package:amap_location_fluttify/amap_location_fluttify.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:hive/hive.dart'; import 'package:hive_flutter/hive_flutter.dart'; +import 'package:power_logger/power_logger.dart'; import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -45,7 +45,7 @@ class _SplashPageState extends State { void initState() { super.initState(); Future.delayed(Duration(milliseconds: 300), () { - if (mounted) LoggerFAB.openLogger(context); + if (mounted) PowerLogger.init(context); }); _initOp().then((value) => Get.offAll(TabNavigator())); } diff --git a/lib/utils/logger/logger_card.dart b/lib/utils/logger/logger_card.dart deleted file mode 100644 index a54ad9f8..00000000 --- a/lib/utils/logger/logger_card.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'package:akuCommunity/utils/logger/logger_dio_err.dart'; -import 'package:akuCommunity/utils/logger/logger_dio_success.dart'; -import 'package:dio/dio.dart'; -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; - -class LoggerCard extends StatelessWidget { - final dynamic data; - const LoggerCard({Key key, this.data}) : super(key: key); - Widget _buildDioErr() { - DioError error = data; - return LoggerDioErr(error: error); - } - - Widget _buildResponse() { - Response response = data; - return LoggerDioSuccess(response: response); - } - - Widget _getLoggerView() { - switch (data.runtimeType) { - case DioError: - return _buildDioErr(); - case Response: - return _buildResponse(); - default: - return Text("UNKNOW"); - } - } - - @override - Widget build(BuildContext context) => _getLoggerView(); -} diff --git a/lib/utils/logger/logger_data.dart b/lib/utils/logger/logger_data.dart deleted file mode 100644 index a341c3ad..00000000 --- a/lib/utils/logger/logger_data.dart +++ /dev/null @@ -1,14 +0,0 @@ -class LoggerData { - static int maxCount = 100; - static List _data = []; - static List get data => _data; - - static addData(dynamic item) { - if (_data.length < maxCount) - _data.insert(0, item); - else { - _data.removeLast(); - _data.insert(item, 0); - } - } -} diff --git a/lib/utils/logger/logger_dio_err.dart b/lib/utils/logger/logger_dio_err.dart deleted file mode 100644 index 69197115..00000000 --- a/lib/utils/logger/logger_dio_err.dart +++ /dev/null @@ -1,61 +0,0 @@ -import 'package:akuCommunity/extensions/num_ext.dart'; -import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:velocity_x/velocity_x.dart'; - -class LoggerDioErr extends StatelessWidget { - final DioError error; - const LoggerDioErr({Key key, this.error}) : super(key: key); - - @override - Widget build(BuildContext context) { - return MaterialButton( - elevation: 10, - highlightElevation: 1, - color: Colors.red[100], - onPressed: () => Get.to(_LoggerErrDetail(error: error)), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - 5.wb, - error.request.path.text.bold.make().expand(), - Chip( - backgroundColor: Colors.redAccent, - label: Text(error.response?.statusCode?.toString() ?? 'UNKNOW'), - ), - 5.wb, - Chip( - backgroundColor: Colors.greenAccent, - label: Text(error.request.method), - ), - ], - ), - error.response.headers['date'].first.toString().text.make(), - error.message.text.sm.light.make(), - ], - ), - ); - } -} - -class _LoggerErrDetail extends StatefulWidget { - final DioError error; - _LoggerErrDetail({Key key, this.error}) : super(key: key); - - @override - __LoggerErrDetailState createState() => __LoggerErrDetailState(); -} - -class __LoggerErrDetailState extends State<_LoggerErrDetail> { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: widget.error.request.path.text.make(), - ), - ); - } -} diff --git a/lib/utils/logger/logger_dio_success.dart b/lib/utils/logger/logger_dio_success.dart deleted file mode 100644 index 8ac940f1..00000000 --- a/lib/utils/logger/logger_dio_success.dart +++ /dev/null @@ -1,113 +0,0 @@ -import 'package:akuCommunity/extensions/num_ext.dart'; -import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; -import 'package:get/get.dart' hide Response; -import 'package:velocity_x/velocity_x.dart'; - -class LoggerDioSuccess extends StatelessWidget { - final Response response; - const LoggerDioSuccess({Key key, this.response}) : super(key: key); - - @override - Widget build(BuildContext context) { - return MaterialButton( - elevation: 0, - color: Colors.white, - onPressed: () => Get.to(_LoggerSuccessDetail(response: response)), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - 5.wb, - response.request.path.text.bold.make().expand(), - Chip( - backgroundColor: Colors.green, - label: Text(response?.statusCode?.toString() ?? 'UNKNOW'), - ), - 5.wb, - Chip( - backgroundColor: Colors.greenAccent, - label: Text(response.request.method), - ), - ], - ), - response.headers['date'].first.toString().text.make(), - ], - ), - ); - } -} - -class _LoggerSuccessDetail extends StatefulWidget { - final Response response; - _LoggerSuccessDetail({Key key, this.response}) : super(key: key); - - @override - __LoggerSuccessDetailState createState() => __LoggerSuccessDetailState(); -} - -class __LoggerSuccessDetailState extends State<_LoggerSuccessDetail> { - _buildTable(Map tableData) { - return Table( - border: TableBorder( - horizontalInside: BorderSide(color: Colors.black12), - verticalInside: BorderSide(color: Colors.black12), - ), - children: [ - TableRow( - decoration: BoxDecoration(color: Colors.black12), - children: [ - 'Key'.text.make().p2(), - 'Value'.text.make().p2(), - ], - ), - ...tableData.entries.map((e) { - return TableRow( - children: [ - e.key.text.make().p2(), - e.value.toString().text.make().p2(), - ], - ); - }).toList(), - ], - ); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: widget.response.request.path.text.make(), - ), - body: ListView( - padding: EdgeInsets.symmetric(horizontal: 10), - children: [ - ListTile( - title: 'Request'.text.bold.size(22).make(), - trailing: [ - Chip( - label: widget.response.request.method.text.make(), - backgroundColor: Colors.lightGreen, - ), - ].row(), - ), - ListTile(title: 'headers'.text.make()), - _buildTable(widget.response.request.headers), - ListTile(title: 'queryParameters'.text.make()), - (widget.response.request?.queryParameters ?? '') - .toString() - .text - .make(), - ListTile(title: 'data'.text.make()), - (widget.response.request?.data ?? '').toString().text.make(), - ListTile(title: 'Response'.text.bold.size(22).make()), - ListTile(title: 'headers'.text.make()), - _buildTable(widget.response.headers.map), - ListTile(title: 'data'.text.make()), - (widget.response?.data ?? '').toString().text.make(), - ], - ), - ); - } -} diff --git a/lib/utils/logger/logger_view.dart b/lib/utils/logger/logger_view.dart deleted file mode 100644 index b2fb82fc..00000000 --- a/lib/utils/logger/logger_view.dart +++ /dev/null @@ -1,109 +0,0 @@ -import 'package:akuCommunity/utils/logger/logger_card.dart'; -import 'package:akuCommunity/utils/logger/logger_data.dart'; -import 'package:akuCommunity/extensions/page_router.dart'; -import 'package:akuCommunity/widget/bee_scaffold.dart'; - -import 'package:flutter/material.dart'; - -class LoggerFAB extends StatefulWidget { - static openLogger(BuildContext context) { - Overlay.of(context).insert(OverlayEntry( - builder: (context) { - return LoggerFAB(); - }, - )); - } - - LoggerFAB({Key key}) : super(key: key); - - @override - _LoggerFABState createState() => _LoggerFABState(); -} - -class _LoggerFABState extends State { - double _x = 100; - double _y = 100; - - double get screenWidth => MediaQuery.of(context).size.width; - double get screenHeight => MediaQuery.of(context).size.height; - bool _moving = false; - @override - Widget build(BuildContext context) { - return Stack( - children: [ - AnimatedPositioned( - curve: Curves.easeInOutCubic, - duration: _moving ? Duration.zero : Duration(milliseconds: 300), - left: _x - 25, - top: _y - 25, - child: GestureDetector( - onPanStart: (detail) { - _moving = true; - }, - onPanUpdate: (details) { - setState(() { - _x = details.globalPosition.dx; - _y = details.globalPosition.dy; - }); - }, - onPanEnd: (detail) { - if ((_x < screenWidth / 2)) { - _x = 50; - } else - _x = screenWidth - 50; - if ((_y < screenHeight / 2)) { - _y = 70; - } else - _y = screenHeight - 50; - _moving = false; - setState(() {}); - }, - onTap: () { - LoggerView().to(); - }, - child: Container( - decoration: BoxDecoration( - color: Colors.yellowAccent, - borderRadius: BorderRadius.circular(25), - ), - height: 50, - width: 50, - child: Icon(Icons.code), - ), - ), - ) - ], - ); - } -} - -class LoggerView extends StatefulWidget { - LoggerView({Key key}) : super(key: key); - init() {} - - @override - _LoggerViewState createState() => _LoggerViewState(); -} - -class _LoggerViewState extends State { - @override - void initState() { - super.initState(); - } - - @override - Widget build(BuildContext context) { - return BeeScaffold( - title: 'Logger', - actions: [ - IconButton(icon: Icon(Icons.list), onPressed: () {}), - ], - body: ListView.separated( - separatorBuilder: (context, index) => Divider(height: 1, thickness: 1), - itemBuilder: (context, index) => - LoggerCard(data: LoggerData.data[index]), - itemCount: LoggerData.data.length, - ), - ); - } -} diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index fa8ce2f3..5b4f3de1 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -1,6 +1,5 @@ import 'package:akuCommunity/pages/sign/sign_in_page.dart'; import 'package:akuCommunity/provider/user_provider.dart'; -import 'package:akuCommunity/utils/logger/logger_data.dart'; import 'package:akuCommunity/utils/network/base_list_model.dart'; import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:bot_toast/bot_toast.dart'; @@ -9,6 +8,7 @@ import 'package:dio/dio.dart'; import 'package:akuCommunity/constants/api.dart'; import 'package:get/get.dart' hide Response; import 'package:logger/logger.dart'; +import 'package:power_logger/power_logger.dart'; import 'package:provider/provider.dart'; class NetUtil { diff --git a/pubspec.lock b/pubspec.lock index ac97fa63..853a899a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.39.17" + animations: + dependency: transitive + description: + name: animations + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.2" animator: dependency: transitive description: @@ -126,7 +133,7 @@ packages: name: chewie url: "https://pub.flutter-io.cn" source: hosted - version: "0.12.1+1" + version: "0.12.2" chewie_audio: dependency: transitive description: @@ -356,6 +363,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.8" + flutter_highlight: + dependency: transitive + description: + name: flutter_highlight + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.6.0" flutter_html: dependency: "direct main" description: @@ -483,6 +497,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0" + highlight: + dependency: transitive + description: + name: highlight + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.6.0" hive: dependency: "direct main" description: @@ -777,6 +798,22 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.3" + power_logger: + dependency: "direct main" + description: + path: "." + ref: HEAD + resolved-ref: c972545147e812d192795a56b33357aefd60d479 + url: "http://192.168.2.201:8099/aku_fe/power_logger.git" + source: git + version: "0.0.1" + pretty_json: + dependency: transitive + description: + name: pretty_json + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.1.0" process: dependency: transitive description: @@ -911,7 +948,7 @@ packages: name: shared_preferences_windows url: "https://pub.flutter-io.cn" source: hosted - version: "0.0.1+3" + version: "0.0.2+2" shimmer: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 30d20afc..22e15e54 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -94,11 +94,14 @@ dependencies: hive_flutter: logger: ^0.9.4 flutter_easyrefresh: ^2.1.8 - random_character: - git: + random_character: + git: url: http://192.168.2.201:8099/zhangmeng/random_character.git image_picker: ^0.6.7+21 + power_logger: + git: + url: http://192.168.2.201:8099/aku_fe/power_logger.git dev_dependencies: flutter_test: