update logger fab & logger data

master
小赖 4 years ago
parent a18ee64ddb
commit 96a7f1cfdc

@ -1,5 +1,10 @@
# CHANGELOG
## [1.1.0]
* performance enhanced.
* add initAlignment.
## [1.0.1-nullsafety.1]
* add logger.

@ -39,7 +39,7 @@ class _MyHomePageState extends State<MyHomePage> {
NetTool.dio.get(
"https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png");
PowerLogger.start(context);
LoggerData.addData('TEST');
LoggerData.addData('TEST', tag: 'TAG');
}
bool loading = false;
@ -77,7 +77,7 @@ class _MyHomePageState extends State<MyHomePage> {
: () async {
loading = true;
setState(() {});
await NetTool.dio.get(_textController.text);
await NetTool.dio.get(_textController.text).catchError((e) {});
loading = false;
setState(() {});
},

@ -171,7 +171,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1-nullsafety.1"
version: "1.1.0"
sky_engine:
dependency: transitive
description: flutter

@ -5,7 +5,9 @@ import 'package:power_logger/src/view/dio_error_view.dart';
///Dio Error builder
class DioErrorBuilder extends StatefulWidget {
final DioError data;
DioErrorBuilder({Key? key, required this.data}) : super(key: key);
final DateTime date;
DioErrorBuilder({Key? key, required this.data, required this.date})
: super(key: key);
@override
_DioErrorBuilderState createState() => _DioErrorBuilderState();
@ -54,7 +56,7 @@ class _DioErrorBuilderState extends State<DioErrorBuilder> {
),
),
subtitle: Text(
widget.data.message,
'${widget.data.message}\n${widget.date}',
style: TextStyle(
color: Colors.black45,
fontWeight: FontWeight.w300,

@ -5,7 +5,9 @@ import 'package:power_logger/src/view/dio_response_view.dart';
/// Dio Response Builder
class DioResponseBuilder extends StatefulWidget {
final Response data;
DioResponseBuilder({Key? key,required this.data}) : super(key: key);
final DateTime date;
DioResponseBuilder({Key? key, required this.data, required this.date})
: super(key: key);
@override
_DioResponseBuilderState createState() => _DioResponseBuilderState();
@ -32,6 +34,7 @@ class _DioResponseBuilderState extends State<DioResponseBuilder> {
color: Colors.black87,
),
),
subtitle: Text(widget.date.toString()),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:power_logger/power_logger.dart';
/// logger data storage
@ -15,10 +16,10 @@ class LoggerData {
static Logger _logger = Logger();
/// the real logger data.
static List<dynamic> get data => _listenableData.value;
static List<LoggerInnerData> get data => _listenableData.value;
static _LoggerDataNotifer<List<dynamic>> _listenableData =
_LoggerDataNotifer([]);
static _LoggerDataNotifer<List<LoggerInnerData>> _listenableData =
_LoggerDataNotifer<List<LoggerInnerData>>([]);
/// set the logger max number.
static setMax(int max) {
@ -26,14 +27,20 @@ class LoggerData {
}
/// add data to logger
static addData(dynamic data) {
static addData(dynamic data, {String? tag}) {
if (PowerLogger.debug) {
if (_listenableData.value.length < _maxLength) {
_listenableData.value.insert(0, data);
_listenableData.value.insert(
0,
LoggerInnerData(rawData: data, date: DateTime.now(), tag: tag),
);
_listenableData.notify();
} else {
_listenableData.value.removeLast();
_listenableData.value.insert(0, data);
_listenableData.value.insert(
0,
LoggerInnerData(rawData: data, date: DateTime.now(), tag: tag),
);
_listenableData.notify();
}
}
@ -56,6 +63,17 @@ class LoggerData {
}
class _LoggerDataNotifer<T> extends ValueNotifier {
_LoggerDataNotifer(value) : super(value);
_LoggerDataNotifer(T value) : super(value);
notify() => this.notifyListeners();
}
class LoggerInnerData {
final dynamic? rawData;
final DateTime date;
final String? tag;
LoggerInnerData({
required this.rawData,
required this.date,
this.tag,
});
}

@ -1,14 +1,23 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:power_logger/power_logger.dart';
import 'package:power_logger/src/builders/dio_responses_builder.dart';
import 'package:power_logger/src/builders/dio_error_builder.dart';
import 'package:power_logger/src/parser/unfocus_parser.dart';
///LoggerDataParser
class LoggerDataParser {
static Widget builder(dynamic data) {
if (data is DioError) return DioErrorBuilder(data: data);
if (data is Response) return DioResponseBuilder(data: data);
return UnfocusParser(data: data);
static Widget builder(LoggerInnerData data) {
if (data.rawData is DioError)
return DioErrorBuilder(
data: data.rawData,
date: data.date,
);
if (data.rawData is Response)
return DioResponseBuilder(
data: data.rawData,
date: data.date,
);
return UnfocusParser(data: data.rawData, tag: data.tag);
}
}

@ -3,7 +3,9 @@ import 'package:flutter/material.dart';
/// UnfocusParser
class UnfocusParser extends StatelessWidget {
final dynamic data;
const UnfocusParser({Key? key, required this.data}) : super(key: key);
final String? tag;
const UnfocusParser({Key? key, required this.data, this.tag})
: super(key: key);
@override
Widget build(BuildContext context) {
@ -24,7 +26,7 @@ class UnfocusParser extends StatelessWidget {
maxLines: 1,
),
trailing: Chip(
label: Text(data.runtimeType.toString()),
label: Text(tag ?? data.runtimeType.toString()),
),
),
);

@ -5,6 +5,10 @@ class PowerLogger {
/// debug tag
static bool debug = true;
static OverlayEntry? entry;
static late BuildContext globalContext;
///
///
///debug
@ -15,7 +19,8 @@ class PowerLogger {
@Deprecated("use PowerLogger.start")
static init(BuildContext context, {bool debug = true}) {
PowerLogger.debug = debug;
if (debug) if (debug) _insertToOverlay(context);
globalContext = context;
if (debug) if (debug) _insertToOverlay();
}
///
@ -25,18 +30,33 @@ class PowerLogger {
///```dart
///PowerLogger.start(context,debug:true);
///```
static start(BuildContext context, {bool debug = true}) {
static start(
BuildContext context, {
bool debug = true,
Alignment initAlignment = Alignment.center,
}) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
PowerLogger.debug = debug;
if (debug) _insertToOverlay(context);
globalContext = context;
if (debug) _insertToOverlay(initAlignment: initAlignment);
});
}
static _insertToOverlay(BuildContext context) {
Overlay.of(context)!.insert(OverlayEntry(
static _insertToOverlay({Alignment initAlignment = Alignment.center}) {
entry = OverlayEntry(
builder: (context) {
return LoggerFab();
return LoggerFab(initAlignment: initAlignment);
},
));
);
Overlay.of(globalContext)!.insert(entry!);
}
static insertToOverlay({Alignment initAlignment = Alignment.center}) =>
_insertToOverlay(
initAlignment: initAlignment,
);
static removeFromOverlay() {
if (entry != null) entry!.remove();
}
}

@ -119,7 +119,8 @@ class _InfoViewState extends State<InfoView>
_buildTile('incremental', androidInfo!.version.incremental),
_buildTile('release', androidInfo!.version.release),
_buildTile('securityPatch', androidInfo!.version.securityPatch),
_buildTile('previewSdkInt', androidInfo!.version.previewSdkInt.toString()),
_buildTile(
'previewSdkInt', androidInfo!.version.previewSdkInt.toString()),
_buildTile('sdkInt', androidInfo!.version.sdkInt.toString()),
_buildTile('systemFeatures', androidInfo!.systemFeatures.join('\n')),
]));

@ -1,22 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter/physics.dart';
import 'package:power_logger/power_logger.dart';
import 'package:power_logger/src/power_logger_view.dart';
class LoggerFab extends StatefulWidget {
LoggerFab({Key? key}) : super(key: key);
final Alignment initAlignment;
LoggerFab({Key? key, this.initAlignment = Alignment.center})
: super(key: key);
@override
_LoggerFabState createState() => _LoggerFabState();
LoggerFabState createState() => LoggerFabState();
}
class _LoggerFabState extends State<LoggerFab>
class LoggerFabState extends State<LoggerFab>
with SingleTickerProviderStateMixin {
bool showSubPage = false;
AnimationController? _animationController;
var _dragAlignment = Alignment.center;
late Alignment _dragAlignment;
late Animation<Alignment> _animation;
final _spring =
const SpringDescription(mass: 15, stiffness: 1000, damping: 0.7);
Alignment get alignment => _dragAlignment;
double _normalizeVelocity(Offset velocity, Size size) {
final normalizedVelocity = Offset(
@ -50,6 +53,7 @@ class _LoggerFabState extends State<LoggerFab>
@override
void initState() {
super.initState();
_dragAlignment = widget.initAlignment;
_animationController = AnimationController.unbounded(vsync: this)
..addListener(() => setState(() => _dragAlignment = _animation.value));
}
@ -65,29 +69,24 @@ class _LoggerFabState extends State<LoggerFab>
final size = MediaQuery.of(context).size;
return Align(
alignment: _dragAlignment,
child: AnimatedOpacity(
duration: Duration(milliseconds: 300),
opacity: showSubPage ? 0 : 1,
child: GestureDetector(
onPanStart: (details) => _animationController!.stop(canceled: true),
onPanUpdate: (details) => setState(() => _dragAlignment += Alignment(
details.delta.dx / (size.width / 2),
details.delta.dy / (size.height / 2),
)),
onPanEnd: (details) =>
_runAnimation(details.velocity.pixelsPerSecond, size),
onTap: showSubPage
? null
: () async {
showSubPage = true;
await Navigator.push(
context,
MaterialPageRoute(builder: (context) => PowerLoggerView()),
);
showSubPage = false;
},
child: const _FabButton(),
),
child: GestureDetector(
onPanStart: (details) => _animationController!.stop(canceled: true),
onPanUpdate: (details) => setState(() => _dragAlignment += Alignment(
details.delta.dx / (size.width / 2),
details.delta.dy / (size.height / 2),
)),
onPanEnd: (details) =>
_runAnimation(details.velocity.pixelsPerSecond, size),
onTap: () async {
Alignment initAlignment = _dragAlignment;
PowerLogger.removeFromOverlay();
await Navigator.push(
context,
MaterialPageRoute(builder: (context) => PowerLoggerView()),
);
PowerLogger.insertToOverlay(initAlignment: initAlignment);
},
child: const _FabButton(),
),
);
}

@ -1,6 +1,6 @@
name: power_logger
description: A well log tool on flutter, support Dio and custom type data.
version: 1.0.1-nullsafety.1
version: 1.1.0
homepage: https://github.com/laiiihz/power_logger
environment:
@ -10,7 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
dio: ^4.0.0-prev3
dio: ^4.0.0
flutter_highlight: ^0.7.0
device_info: ^2.0.0
package_info: ^2.0.0

Loading…
Cancel
Save