-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new PlatformDispatcher onError method if available (#109)
* Use new PlatformDispatcher onError method if available * Updated Flutter Demo with more types of possible uncaught errors
- Loading branch information
Showing
5 changed files
with
118 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:rollbar_dart/rollbar.dart'; | ||
|
||
abstract class Hook { | ||
FutureOr<void> install(final Config config); | ||
|
||
FutureOr<void> uninstall(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'dart:ui'; | ||
import 'package:rollbar_dart/rollbar.dart'; | ||
import 'hook.dart'; | ||
|
||
class PlatformHook implements Hook { | ||
ErrorCallback? _originalOnError; | ||
PlatformDispatcher? _platformDispatcher; | ||
|
||
bool onError(Object exception, StackTrace stackTrace) { | ||
Rollbar.error(exception, stackTrace); | ||
|
||
if (_originalOnError != null) { | ||
return _originalOnError!(exception, stackTrace); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@override | ||
void install(_) { | ||
_platformDispatcher = PlatformDispatcher.instance; | ||
_originalOnError = _platformDispatcher?.onError; | ||
_platformDispatcher?.onError = onError; | ||
} | ||
|
||
@override | ||
void uninstall() { | ||
if (_platformDispatcher?.onError == onError) { | ||
_platformDispatcher?.onError = _originalOnError; | ||
_originalOnError = null; | ||
_platformDispatcher = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters