From 476c29e5f25bb160b313d0c6263c7c8e6fa828e7 Mon Sep 17 00:00:00 2001 From: Ahmed alaa Date: Thu, 31 Oct 2024 13:43:29 +0300 Subject: [PATCH] doc:comment why not use const constructor --- .../flutter/InstabugFlutterPlugin.java | 28 ++++++++----------- .../private_views/instabug_private_view.dart | 1 + .../instabug_sliver_private_view.dart | 1 + 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/android/src/main/java/com/instabug/flutter/InstabugFlutterPlugin.java b/android/src/main/java/com/instabug/flutter/InstabugFlutterPlugin.java index 170d28de7..ec6f3045a 100644 --- a/android/src/main/java/com/instabug/flutter/InstabugFlutterPlugin.java +++ b/android/src/main/java/com/instabug/flutter/InstabugFlutterPlugin.java @@ -30,6 +30,7 @@ import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; import io.flutter.embedding.engine.renderer.FlutterRenderer; import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.PluginRegistry; public class InstabugFlutterPlugin implements FlutterPlugin, ActivityAware { private static final String TAG = InstabugFlutterPlugin.class.getName(); @@ -39,6 +40,15 @@ public class InstabugFlutterPlugin implements FlutterPlugin, ActivityAware { PrivateViewManager privateViewManager; + /** + * Embedding v1 + */ + @SuppressWarnings("deprecation") + public static void registerWith(PluginRegistry.Registrar registrar) { + activity = registrar.activity(); + register(registrar.context().getApplicationContext(), registrar.messenger(), (FlutterRenderer) registrar.textures()); + } + @Override public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { @@ -69,7 +79,6 @@ public void onDetachedFromActivityForConfigChanges() { @Override public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { activity = binding.getActivity(); - privateViewManager.setActivity(activity); } @@ -81,7 +90,7 @@ public void onDetachedFromActivity() { } - private void register(Context context, BinaryMessenger messenger, FlutterRenderer renderer) { + private static void register(Context context, BinaryMessenger messenger, FlutterRenderer renderer) { ApmApi.init(messenger); BugReportingApi.init(messenger); CrashReportingApi.init(messenger); @@ -94,19 +103,4 @@ private void register(Context context, BinaryMessenger messenger, FlutterRendere SurveysApi.init(messenger); } - @Nullable - private static Bitmap takeScreenshot(FlutterRenderer renderer) { - try { - final View view = activity.getWindow().getDecorView().getRootView(); - - view.setDrawingCacheEnabled(true); - final Bitmap bitmap = renderer.getBitmap(); - view.setDrawingCacheEnabled(false); - - return bitmap; - } catch (Exception e) { - Log.e(TAG, "Failed to take screenshot using " + renderer.toString() + ". Cause: " + e); - return null; - } - } } diff --git a/lib/src/utils/private_views/instabug_private_view.dart b/lib/src/utils/private_views/instabug_private_view.dart index 603a9ff28..b9fc0dfeb 100644 --- a/lib/src/utils/private_views/instabug_private_view.dart +++ b/lib/src/utils/private_views/instabug_private_view.dart @@ -5,6 +5,7 @@ import 'package:instabug_flutter/src/utils/private_views/visibility_detector/vis class InstabugPrivateView extends StatefulWidget { final Widget child; + // Making the constructor const prevents the VisibilityDetector from detecting changes in the view, // ignore: prefer_const_constructors_in_immutables InstabugPrivateView({required this.child}) : super(key: null); diff --git a/lib/src/utils/private_views/instabug_sliver_private_view.dart b/lib/src/utils/private_views/instabug_sliver_private_view.dart index d9649badd..c0ad8358c 100644 --- a/lib/src/utils/private_views/instabug_sliver_private_view.dart +++ b/lib/src/utils/private_views/instabug_sliver_private_view.dart @@ -6,6 +6,7 @@ import 'package:instabug_flutter/src/utils/private_views/visibility_detector/sli class InstabugSliverPrivateView extends StatefulWidget { final Widget sliver; + // Making the constructor const prevents the VisibilityDetector from detecting changes in the view, // ignore: prefer_const_constructors_in_immutables InstabugSliverPrivateView({Key? key, required this.sliver}) : super(key: key);