parent
a4e68851d5
commit
4a25f07e8a
@ -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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue