refactor logger View

hmxc
小赖 4 years ago
parent a4e68851d5
commit 4a25f07e8a

@ -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';

@ -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<SplashPage> {
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()));
}

@ -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();
}

@ -1,14 +0,0 @@
class LoggerData {
static int maxCount = 100;
static List<dynamic> _data = [];
static List<dynamic> get data => _data;
static addData(dynamic item) {
if (_data.length < maxCount)
_data.insert(0, item);
else {
_data.removeLast();
_data.insert(item, 0);
}
}
}

@ -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(),
),
);
}
}

@ -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<String, dynamic> 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(),
],
),
);
}
}

@ -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<LoggerFAB> {
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<LoggerView> {
@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,
),
);
}
}

@ -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 {

@ -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:

@ -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:

Loading…
Cancel
Save