flutter_log_overlay

Last updated:

0 purchases

flutter_log_overlay Image
flutter_log_overlay Images
Add to Cart

Description:

flutter log overlay

Usage #
Must(Initialize from the start page:Your Home Page)
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
FlutterLogOverlay.init(context: context);
});
}
copied to clipboard
Use
FlutterLogOverlay.show();
copied to clipboard
plugin for logger
restructure Logger
final sLog = MyLogger(
printer: PrettyPrinter(
methodCount: 0,
errorMethodCount: 0,
printEmojis: false,
printTime: true,
),
);

class MyLogger extends Logger {
LogFilter? filter;
LogPrinter? printer;
LogOutput? output;
Level? level;

MyLogger({
this.filter,
this.printer,
this.output,
this.level,
}) : super(
filter: filter,
printer: printer,
output: output,
level: level,
);

@override
void log(
Level level,
dynamic message, [
dynamic error,
StackTrace? stackTrace,
]) {
_startTime = DateTime.now();
FlutterLogOverlay.addLog(
isCore: level == Level.error,
content: [
getTime(),
"--------------------",
((printer ?? PrettyPrinter()) as PrettyPrinter)
.stringifyMessage(message),
],
);
super.log(
level,
message,
error != null || stackTrace != null
? [
error,
stackTrace,
]
: null,
);
}

DateTime? _startTime;

String getTime() {
var now = DateTime.now();
var year = _fourDigits(now.year);
var month = _twoDigits(now.month);
var day = _twoDigits(now.day);
var h = _twoDigits(now.hour);
var min = _twoDigits(now.minute);
var sec = _twoDigits(now.second);
var ms = _threeDigits(now.millisecond);
var timeSinceStart = now.difference(_startTime!).toString();
return '$year-$month-$day $h:$min:$sec.$ms (+$timeSinceStart)';
}

String _fourDigits(int n) {
if (n >= 1000) return '$n';
if (n >= 100) return '0$n';
if (n >= 10) return '00$n';
return '000$n';
}

String _threeDigits(int n) {
if (n >= 100) return '$n';
if (n >= 10) return '0$n';
return '00$n';
}

String _twoDigits(int n) {
if (n >= 10) return '$n';
return '0$n';
}
}
copied to clipboard
Optional
@override
Widget build(BuildContext context) {
return GestureDetector(
onPanEnd: FlutterLogOverlay.showOverlayPan,
behavior: HitTestBehavior.translucent,
child: const MaterialApp(
debugShowCheckedModeBanner: false,
home: FirstPgae(),
),
);
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.