diff --git a/README.md b/README.md index 77c44d0..914e724 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ LoggerData.addData(data); ## WARNING -*only tested on flutter 1.22.5 +*only tested on flutter `1.22.5`,`1.22.6` ## author diff --git a/example/lib/main.dart b/example/lib/main.dart index 79b932d..5987268 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -51,10 +51,7 @@ class _MyHomePageState extends State { .then((e) { LoggerData.addData(e); }); - Future.delayed( - Duration(milliseconds: 300), - () => PowerLogger.init(context), - ); + PowerLogger.start(context); LoggerData.addData('TEST'); } diff --git a/lib/src/power_logger.dart b/lib/src/power_logger.dart index 3201e55..36e4bb2 100644 --- a/lib/src/power_logger.dart +++ b/lib/src/power_logger.dart @@ -1,7 +1,6 @@ import 'dart:ui'; import 'package:flutter/material.dart'; -import 'package:power_logger/power_logger.dart'; import 'package:power_logger/src/widgets/logger_fab.dart'; class PowerLogger { @@ -15,13 +14,31 @@ class PowerLogger { ///```dart ///PowerLogger.init(context,debug:true); ///``` + @Deprecated("use PowerLogger.start") static init(BuildContext context, {bool debug = true}) { PowerLogger.debug = debug; - if (debug) - Overlay.of(context).insert(OverlayEntry( - builder: (context) { - return LoggerFab(); - }, - )); + if (debug) if (debug) _insertToOverlay(context); + } + + ///初始化 + /// + ///默认开启debug + /// + ///```dart + ///PowerLogger.start(context,debug:true); + ///``` + static start(BuildContext context, {bool debug = true}) { + WidgetsBinding.instance.addPostFrameCallback((_) { + PowerLogger.debug = debug; + if (debug) _insertToOverlay(context); + }); + } + + static _insertToOverlay(BuildContext context) { + Overlay.of(context).insert(OverlayEntry( + builder: (context) { + return LoggerFab(); + }, + )); } }