update logger fab & logger data

master
小赖 4 years ago
parent a18ee64ddb
commit 96a7f1cfdc

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

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

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

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

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

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart'; import 'package:logger/logger.dart';
import 'package:power_logger/power_logger.dart'; import 'package:power_logger/power_logger.dart';
/// logger data storage /// logger data storage
@ -15,10 +16,10 @@ class LoggerData {
static Logger _logger = Logger(); static Logger _logger = Logger();
/// the real logger data. /// the real logger data.
static List<dynamic> get data => _listenableData.value; static List<LoggerInnerData> get data => _listenableData.value;
static _LoggerDataNotifer<List<dynamic>> _listenableData = static _LoggerDataNotifer<List<LoggerInnerData>> _listenableData =
_LoggerDataNotifer([]); _LoggerDataNotifer<List<LoggerInnerData>>([]);
/// set the logger max number. /// set the logger max number.
static setMax(int max) { static setMax(int max) {
@ -26,14 +27,20 @@ class LoggerData {
} }
/// add data to logger /// add data to logger
static addData(dynamic data) { static addData(dynamic data, {String? tag}) {
if (PowerLogger.debug) { if (PowerLogger.debug) {
if (_listenableData.value.length < _maxLength) { if (_listenableData.value.length < _maxLength) {
_listenableData.value.insert(0, data); _listenableData.value.insert(
0,
LoggerInnerData(rawData: data, date: DateTime.now(), tag: tag),
);
_listenableData.notify(); _listenableData.notify();
} else { } else {
_listenableData.value.removeLast(); _listenableData.value.removeLast();
_listenableData.value.insert(0, data); _listenableData.value.insert(
0,
LoggerInnerData(rawData: data, date: DateTime.now(), tag: tag),
);
_listenableData.notify(); _listenableData.notify();
} }
} }
@ -56,6 +63,17 @@ class LoggerData {
} }
class _LoggerDataNotifer<T> extends ValueNotifier { class _LoggerDataNotifer<T> extends ValueNotifier {
_LoggerDataNotifer(value) : super(value); _LoggerDataNotifer(T value) : super(value);
notify() => this.notifyListeners(); 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:dio/dio.dart';
import 'package:flutter/material.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_responses_builder.dart';
import 'package:power_logger/src/builders/dio_error_builder.dart'; import 'package:power_logger/src/builders/dio_error_builder.dart';
import 'package:power_logger/src/parser/unfocus_parser.dart'; import 'package:power_logger/src/parser/unfocus_parser.dart';
///LoggerDataParser ///LoggerDataParser
class LoggerDataParser { class LoggerDataParser {
static Widget builder(dynamic data) { static Widget builder(LoggerInnerData data) {
if (data is DioError) return DioErrorBuilder(data: data); if (data.rawData is DioError)
if (data is Response) return DioResponseBuilder(data: data); return DioErrorBuilder(
return UnfocusParser(data: data); 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 /// UnfocusParser
class UnfocusParser extends StatelessWidget { class UnfocusParser extends StatelessWidget {
final dynamic data; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -24,7 +26,7 @@ class UnfocusParser extends StatelessWidget {
maxLines: 1, maxLines: 1,
), ),
trailing: Chip( trailing: Chip(
label: Text(data.runtimeType.toString()), label: Text(tag ?? data.runtimeType.toString()),
), ),
), ),
); );

@ -5,6 +5,10 @@ class PowerLogger {
/// debug tag /// debug tag
static bool debug = true; static bool debug = true;
static OverlayEntry? entry;
static late BuildContext globalContext;
/// ///
/// ///
///debug ///debug
@ -15,7 +19,8 @@ class PowerLogger {
@Deprecated("use PowerLogger.start") @Deprecated("use PowerLogger.start")
static init(BuildContext context, {bool debug = true}) { static init(BuildContext context, {bool debug = true}) {
PowerLogger.debug = debug; PowerLogger.debug = debug;
if (debug) if (debug) _insertToOverlay(context); globalContext = context;
if (debug) if (debug) _insertToOverlay();
} }
/// ///
@ -25,18 +30,33 @@ class PowerLogger {
///```dart ///```dart
///PowerLogger.start(context,debug:true); ///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((_) { WidgetsBinding.instance!.addPostFrameCallback((_) {
PowerLogger.debug = debug; PowerLogger.debug = debug;
if (debug) _insertToOverlay(context); globalContext = context;
if (debug) _insertToOverlay(initAlignment: initAlignment);
}); });
} }
static _insertToOverlay(BuildContext context) { static _insertToOverlay({Alignment initAlignment = Alignment.center}) {
Overlay.of(context)!.insert(OverlayEntry( entry = OverlayEntry(
builder: (context) { 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('incremental', androidInfo!.version.incremental),
_buildTile('release', androidInfo!.version.release), _buildTile('release', androidInfo!.version.release),
_buildTile('securityPatch', androidInfo!.version.securityPatch), _buildTile('securityPatch', androidInfo!.version.securityPatch),
_buildTile('previewSdkInt', androidInfo!.version.previewSdkInt.toString()), _buildTile(
'previewSdkInt', androidInfo!.version.previewSdkInt.toString()),
_buildTile('sdkInt', androidInfo!.version.sdkInt.toString()), _buildTile('sdkInt', androidInfo!.version.sdkInt.toString()),
_buildTile('systemFeatures', androidInfo!.systemFeatures.join('\n')), _buildTile('systemFeatures', androidInfo!.systemFeatures.join('\n')),
])); ]));

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

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

Loading…
Cancel
Save