From 416792645143d737c4fba089f6d6bb5e54c2c1c6 Mon Sep 17 00:00:00 2001 From: Matias Pequeno Date: Wed, 2 Aug 2023 11:43:51 -0300 Subject: [PATCH] Encapsulate the as dynamic hack inside the platform hook --- rollbar_flutter/lib/src/hooks/platform_hook.dart | 9 +++++++++ rollbar_flutter/lib/src/rollbar.dart | 10 ---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/rollbar_flutter/lib/src/hooks/platform_hook.dart b/rollbar_flutter/lib/src/hooks/platform_hook.dart index 09632eb..e8a7cac 100644 --- a/rollbar_flutter/lib/src/hooks/platform_hook.dart +++ b/rollbar_flutter/lib/src/hooks/platform_hook.dart @@ -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); diff --git a/rollbar_flutter/lib/src/rollbar.dart b/rollbar_flutter/lib/src/rollbar.dart index 2ae2e45..ec56b78 100644 --- a/rollbar_flutter/lib/src/rollbar.dart +++ b/rollbar_flutter/lib/src/rollbar.dart @@ -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'; @@ -64,13 +63,4 @@ class RollbarFlutter { await appRunner(); } - - static bool get requiresCustomZone { - try { - (PlatformDispatcher.instance as dynamic)?.onError; - return false; - } on NoSuchMethodError { - return true; - } - } }