From fd0a5492965c612db5a394c78aa5866cfbd11b5d Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 18 Jan 2021 11:16:48 +0800 Subject: [PATCH] logger view add extra page --- lib/utils/logger/logger_dio_err.dart | 22 +++++++++- lib/utils/logger/logger_dio_success.dart | 53 ++++++++++++++++++++++-- lib/utils/logger/logger_view.dart | 13 ++++-- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/lib/utils/logger/logger_dio_err.dart b/lib/utils/logger/logger_dio_err.dart index f885f68d..69197115 100644 --- a/lib/utils/logger/logger_dio_err.dart +++ b/lib/utils/logger/logger_dio_err.dart @@ -1,6 +1,7 @@ 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 { @@ -13,7 +14,7 @@ class LoggerDioErr extends StatelessWidget { elevation: 10, highlightElevation: 1, color: Colors.red[100], - onPressed: () {}, + onPressed: () => Get.to(_LoggerErrDetail(error: error)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -39,3 +40,22 @@ class LoggerDioErr extends StatelessWidget { ); } } + +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 index 462aae98..09adb267 100644 --- a/lib/utils/logger/logger_dio_success.dart +++ b/lib/utils/logger/logger_dio_success.dart @@ -1,6 +1,7 @@ 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 { @@ -10,10 +11,9 @@ class LoggerDioSuccess extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialButton( - elevation: 10, - highlightElevation: 1, + elevation: 0, color: Colors.white, - onPressed: () {}, + onPressed: () => Get.to(_LoggerSuccessDetail(response: response)), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -38,3 +38,50 @@ class LoggerDioSuccess extends StatelessWidget { ); } } + +class _LoggerSuccessDetail extends StatefulWidget { + final Response response; + _LoggerSuccessDetail({Key key, this.response}) : super(key: key); + + @override + __LoggerSuccessDetailState createState() => __LoggerSuccessDetailState(); +} + +class __LoggerSuccessDetailState extends State<_LoggerSuccessDetail> { + @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()), + widget.response.request?.headers.toString().text.make(), + 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()), + widget.response?.headers.toString().text.make(), + 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 index 266466f6..4bb3ea32 100644 --- a/lib/utils/logger/logger_view.dart +++ b/lib/utils/logger/logger_view.dart @@ -32,6 +32,7 @@ class _LoggerFABState extends State { return Stack( children: [ AnimatedPositioned( + curve: Curves.easeInOutCubic, duration: _moving ? Duration.zero : Duration(milliseconds: 300), left: _x - 25, top: _y - 25, @@ -46,10 +47,14 @@ class _LoggerFABState extends State { }); }, onPanEnd: (detail) { - if (_x < 100) _x = 50; - if (_y < 100) _y = 75; - if (_x > screenWidth - 50) _x = screenWidth - 50; - if (_y > screenHeight - 50) _y = screenHeight - 50; + if ((_x < screenWidth / 2)) { + _x = 50; + } else + _x = screenWidth - 50; + if ((_y < screenHeight / 2)) { + _y = 70; + } else + _y = screenHeight - 50; _moving = false; setState(() {}); },