Skip to content

Commit

Permalink
Encapsulate the as dynamic hack inside the platform hook
Browse files Browse the repository at this point in the history
  • Loading branch information
matux committed Aug 2, 2023
1 parent fdf8b2c commit 4167926
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
9 changes: 9 additions & 0 deletions rollbar_flutter/lib/src/hooks/platform_hook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ class PlatformHook implements Hook {
ErrorCallback? _originalOnError;
PlatformDispatcher? _platformDispatcher;

static bool get isAvailable {
try {
(PlatformDispatcher.instance as dynamic)?.onError;
return true;
} on NoSuchMethodError {
return false;
}
}

bool onError(Object exception, StackTrace stackTrace) {
Rollbar.error(exception, stackTrace);

Expand Down
10 changes: 0 additions & 10 deletions rollbar_flutter/lib/src/rollbar.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
Expand Down Expand Up @@ -64,13 +63,4 @@ class RollbarFlutter {

await appRunner();
}

static bool get requiresCustomZone {
try {
(PlatformDispatcher.instance as dynamic)?.onError;
return false;
} on NoSuchMethodError {
return true;
}
}
}

0 comments on commit 4167926

Please sign in to comment.