|
|
@ -1,13 +1,15 @@
|
|
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:power_logger/power_logger.dart';
|
|
|
|
import 'package:power_logger/power_logger.dart';
|
|
|
|
|
|
|
|
|
|
|
|
/// logger data storage
|
|
|
|
/// logger data storage
|
|
|
|
class LoggerData {
|
|
|
|
class LoggerData {
|
|
|
|
static int _maxLength = 100;
|
|
|
|
static int _maxLength = 100;
|
|
|
|
|
|
|
|
|
|
|
|
static List<dynamic> _data = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// the real logger data.
|
|
|
|
/// the real logger data.
|
|
|
|
static List<dynamic> get data => _data;
|
|
|
|
static List<dynamic> get data => _listenableData.value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static _LoggerDataNotifer<List<dynamic>> _listenableData =
|
|
|
|
|
|
|
|
_LoggerDataNotifer([]);
|
|
|
|
|
|
|
|
|
|
|
|
/// set the logger max number.
|
|
|
|
/// set the logger max number.
|
|
|
|
static setMax(int max) {
|
|
|
|
static setMax(int max) {
|
|
|
@ -17,15 +19,32 @@ class LoggerData {
|
|
|
|
/// add data to logger
|
|
|
|
/// add data to logger
|
|
|
|
static addData(dynamic data) {
|
|
|
|
static addData(dynamic data) {
|
|
|
|
if (PowerLogger.debug) {
|
|
|
|
if (PowerLogger.debug) {
|
|
|
|
if (_data.length < _maxLength)
|
|
|
|
if (_listenableData.value.length < _maxLength) {
|
|
|
|
_data.insert(0, data);
|
|
|
|
_listenableData.value.insert(0, data);
|
|
|
|
else {
|
|
|
|
_listenableData.notify();
|
|
|
|
_data.removeLast();
|
|
|
|
} else {
|
|
|
|
_data.insert(0, data);
|
|
|
|
_listenableData.value.removeLast();
|
|
|
|
|
|
|
|
_listenableData.value.insert(0, data);
|
|
|
|
|
|
|
|
_listenableData.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// clear all logger
|
|
|
|
/// clear all logger
|
|
|
|
static clear() => _data.clear();
|
|
|
|
static clear() => _listenableData.value.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// add data listener
|
|
|
|
|
|
|
|
static addListener(Function listener) {
|
|
|
|
|
|
|
|
_listenableData.addListener(listener);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// remove data listener
|
|
|
|
|
|
|
|
static removeListener(Function listener) {
|
|
|
|
|
|
|
|
_listenableData.removeListener(listener);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _LoggerDataNotifer<T> extends ValueNotifier {
|
|
|
|
|
|
|
|
_LoggerDataNotifer(value) : super(value);
|
|
|
|
|
|
|
|
notify() => this.notifyListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|