parent
dd103d1ecf
commit
2f477dc908
@ -0,0 +1,62 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:velocity_x/velocity_x.dart';
|
||||
|
||||
class LoggerCard extends StatelessWidget {
|
||||
final dynamic data;
|
||||
const LoggerCard({Key key, this.data}) : super(key: key);
|
||||
Widget _buildDioErr() {
|
||||
DioError error = data;
|
||||
return VxBox(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Spacer(),
|
||||
Chip(
|
||||
backgroundColor: Colors.greenAccent,
|
||||
label: Text(error.request.method),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(error.message),
|
||||
Text(error.request.path),
|
||||
Text(error.request.method),
|
||||
],
|
||||
),
|
||||
)
|
||||
.height(200)
|
||||
.p4
|
||||
.red200
|
||||
.margin(EdgeInsets.all(5))
|
||||
.shadowSm
|
||||
.make()
|
||||
.material(color: Colors.transparent);
|
||||
}
|
||||
|
||||
Widget _buildResponse() {
|
||||
Response response = data;
|
||||
return Card(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(response.statusCode.toString()),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getLoggerView() {
|
||||
switch (data.runtimeType) {
|
||||
case DioError:
|
||||
return _buildDioErr();
|
||||
case Response:
|
||||
return _buildResponse();
|
||||
default:
|
||||
return Text("UNKNOW");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => _getLoggerView();
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
import 'package:akuCommunity/utils/logger_card.dart';
|
||||
import 'package:akuCommunity/utils/logger_data.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.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(
|
||||
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 < 100) _x = 50;
|
||||
if (_y < 100) _y = 75;
|
||||
if (_x > screenWidth - 50) _x = screenWidth - 50;
|
||||
if (_y > screenHeight - 50) _y = screenHeight - 50;
|
||||
_moving = false;
|
||||
setState(() {});
|
||||
},
|
||||
onTap: () {
|
||||
Get.to(LoggerView());
|
||||
},
|
||||
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 Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: ListView.builder(
|
||||
itemBuilder: (context, index) =>
|
||||
LoggerCard(data: LoggerData.data[index]),
|
||||
itemCount: LoggerData.data.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue