背景
相信很多人剛用flutter的時候,看到自帶的異常捕捉log列印都懵圈過,即使是上手之後,也不能快速的找到對應的異常程式碼行數
前言
在尋找開源庫的時候,發現了一個dart團隊做的可以調整log格式的庫,但是很遺憾這個庫只會捕捉系統包和外掛包的異常,並不會捕捉本專案的異常,所以本人就做了一個基於此庫的異常捕捉log列印庫,並且做了一些flutter系統包異常的過濾
專案地址
stack_trace列印
I/flutter ( 3068): PlatformException(error, Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference, null)
I/flutter ( 3068): package:flutter/src/services/message_codecs.dart 551:7 StandardMethodCodec.decodeEnvelope
I/flutter ( 3068): package:flutter/src/services/platform_channel.dart 292:18 MethodChannel.invokeMethod
I/flutter ( 3068): dart:async/future_impl.dart 22:43 _Completer.completeError
I/flutter ( 3068): dart:async/runtime/libasync_patch.dart 40:18 _AsyncAwaitCompleter.completeError
I/flutter ( 3068): package:flutter/src/services/platform_channel.dart MethodChannel.invokeMethod
I/flutter ( 3068): dart:async/zone.dart 1053:19 _CustomZone.registerUnaryCallback
I/flutter ( 3068): dart:async/runtime/libasync_patch.dart 77:23 _asyncThenWrapperHelper
I/flutter ( 3068): package:flutter/src/services/platform_channel.dart MethodChannel.invokeMethod
I/flutter ( 3068): package:fluttertoast/fluttertoast.dart 53:33 Fluttertoast.showToast
複製程式碼
flutter_stack_trace列印
I/flutter ( 3068): PlatformException(error, Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference, null)
I/flutter ( 3068): package:flutter/src/services/message_codecs.dart 551:7 StandardMethodCodec.decodeEnvelope
I/flutter ( 3068): package:flutter/src/services/platform_channel.dart 292:18 MethodChannel.invokeMethod
I/flutter ( 3068): package:fluttertoast/fluttertoast.dart 53:33 Fluttertoast.showToast
I/flutter ( 3068): package:example/ui/login_page.dart 198:18 _LoginPageState.showAccountNameEmpty
I/flutter ( 3068): package:example/presenter/login_presenter.dart 19:12 LoginPresenter.login
I/flutter ( 3068): package:example/ui/login_page.dart 135:31 _LoginPageState.buildBody.<fn>
I/flutter ( 3068): package:flutter/src/material/ink_well.dart 507:14 _InkResponseState._handleTap
I/flutter ( 3068): package:flutter/src/material/ink_well.dart 562:30 _InkResponseState.build.<fn>
I/flutter ( 3068): package:flutter/src/gestures/recognizer.dart 102:24 GestureRecognizer.invokeCallback
I/flutter ( 3068): package:flutter/src/gestures/tap.dart 242:9 TapGestureRecognizer._checkUp
I/flutter ( 3068): package:flutter/src/gestures/tap.dart 175:7 TapGestureRecognizer.handlePrimaryPointer
I/flutter ( 3068): package:flutter/src/gestures/recognizer.dart 315:9 PrimaryPointerGestureRecognizer.handleEvent
I/flutter ( 3068): package:flutter/src/gestures/pointer_router.dart 73:12 PointerRouter._dispatch
I/flutter ( 3068): package:flutter/src/gestures/pointer_router.dart 101:11 PointerRouter.route
I/flutter ( 3068): package:flutter/src/gestures/binding.dart 180:19 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent
I/flutter ( 3068): package:flutter/src/gestures/binding.dart 158:22 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent
I/flutter ( 3068): package:flutter/src/gestures/binding.dart 138:7 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent
I/flutter ( 3068): package:flutter/src/gestures/binding.dart 101:7 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
I/flutter ( 3068): package:flutter/src/gestures/binding.dart 85:7 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
I/flutter ( 3068): dart:async/zone.dart 1136:13 _rootRunUnary
I/flutter ( 3068): dart:async/zone.dart 1029:19 _CustomZone.runUnary
I/flutter ( 3068): dart:async/zone.dart 931:7 _CustomZone.runUnaryGuarded
I/flutter ( 3068): dart:ui/hooks.dart 170:10 _invoke1
I/flutter ( 3068): dart:ui/hooks.dart 122:5 _dispatchPointerDataPacket
複製程式碼
flutter_stack_trace的Simple Mode列印
I/flutter ( 3068): PlatformException(error, Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference, null)
I/flutter ( 3068): package:fluttertoast/fluttertoast.dart 53:33 Fluttertoast.showToast
I/flutter ( 3068): package:example/ui/login_page.dart 198:18 _LoginPageState.showAccountNameEmpty
I/flutter ( 3068): package:example/presenter/login_presenter.dart 19:12 LoginPresenter.login
I/flutter ( 3068): package:example/ui/login_page.dart 135:31 _LoginPageState.buildBody.<fn>
複製程式碼
用法
import 'package:flutter_stack_trace/flutter_stack_trace.dart';
//default simple mode
void main() => FlutterChain.capture(
() {
runApp(MyApp());
},
);
//just print in debug mode
//isShowTime default true
FlutterChain.print("test",isShowTime: false);
複製程式碼