Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class FlutterBarcodeScannerPlugin implements MethodCallHandler, ActivityResultListener, StreamHandler, FlutterPlugin, ActivityAware {
private static final String CHANNEL = "flutter_barcode_scanner";

private static FlutterActivity activity;
private static Activity activity;
private static Result pendingResult;
private Map<String, Object> arguments;

Expand All @@ -55,38 +55,36 @@ public class FlutterBarcodeScannerPlugin implements MethodCallHandler, ActivityR
* V2 embedding
*
* @param activity
* @param registrar
*/
private MethodChannel channel;
private FlutterPluginBinding pluginBinding;
private ActivityPluginBinding activityBinding;
private Application applicationContext;
// This is null when not using v2 embedding;
private Lifecycle lifecycle;
private LifeCycleObserver observer;

public FlutterBarcodeScannerPlugin() {
}

private FlutterBarcodeScannerPlugin(FlutterActivity activity, final PluginRegistry.Registrar registrar) {
FlutterBarcodeScannerPlugin.activity = activity;
}
// private FlutterBarcodeScannerPlugin(FlutterActivity activity, final PluginRegistry.Registrar registrar) {
// FlutterBarcodeScannerPlugin.activity = activity;
// }

/**
* Plugin registration.
*/
public static void registerWith(final PluginRegistry.Registrar registrar) {
if (registrar.activity() == null) {
return;
}
Activity activity = registrar.activity();
Application applicationContext = null;
if (registrar.context() != null) {
applicationContext = (Application) (registrar.context().getApplicationContext());
}
FlutterBarcodeScannerPlugin instance = new FlutterBarcodeScannerPlugin((FlutterActivity) registrar.activity(), registrar);
instance.createPluginSetup(registrar.messenger(), applicationContext, activity, registrar, null);
}
// public static void registerWith(final PluginRegistry.Registrar registrar) {
// if (registrar.activity() == null) {
// return;
// }
// Activity activity = registrar.activity();
// Application applicationContext = null;
// if (registrar.context() != null) {
// applicationContext = (Application) (registrar.context().getApplicationContext());
// }
// FlutterBarcodeScannerPlugin instance = new FlutterBarcodeScannerPlugin((FlutterActivity) registrar.activity(), registrar);
// instance.createPluginSetup(registrar.messenger(), applicationContext, activity, registrar, null);
// }

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
Expand Down Expand Up @@ -208,10 +206,16 @@ public void run() {
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
pluginBinding = binding;
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
this.pluginBinding = flutterPluginBinding;
this.channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), CHANNEL);
this.channel.setMethodCallHandler(this);

this.eventChannel = new EventChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_barcode_scanner_receiver");
this.eventChannel.setStreamHandler(this);
}


@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
pluginBinding = null;
Expand All @@ -234,18 +238,16 @@ public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding
* @param messenger
* @param applicationContext
* @param activity
* @param registrar
* @param activityBinding
*/
private void createPluginSetup(
final BinaryMessenger messenger,
final Application applicationContext,
final Activity activity,
final PluginRegistry.Registrar registrar,
final ActivityPluginBinding activityBinding) {


this.activity = (FlutterActivity) activity;
this.activity = activity;
eventChannel =
new EventChannel(messenger, "flutter_barcode_scanner_receiver");
eventChannel.setStreamHandler(this);
Expand All @@ -254,19 +256,12 @@ private void createPluginSetup(
this.applicationContext = applicationContext;
channel = new MethodChannel(messenger, CHANNEL);
channel.setMethodCallHandler(this);
if (registrar != null) {
// V1 embedding setup for activity listeners.
observer = new LifeCycleObserver(activity);
applicationContext.registerActivityLifecycleCallbacks(
observer); // Use getApplicationContext() to avoid casting failures.
registrar.addActivityResultListener(this);
} else {
// V2 embedding setup for activity listeners.
activityBinding.addActivityResultListener(this);
lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding);
observer = new LifeCycleObserver(activity);
lifecycle.addObserver(observer);
}

// V2 embedding setup for activity listeners.
activityBinding.addActivityResultListener(this);
lifecycle = FlutterLifecycleAdapter.getActivityLifecycle(activityBinding);
observer = new LifeCycleObserver(activity);
lifecycle.addObserver(observer);
}

@Override
Expand All @@ -276,7 +271,6 @@ public void onAttachedToActivity(ActivityPluginBinding binding) {
pluginBinding.getBinaryMessenger(),
(Application) pluginBinding.getApplicationContext(),
activityBinding.getActivity(),
null,
activityBinding);
}

Expand Down
32 changes: 32 additions & 0 deletions example/ios/Flutter/ephemeral/flutter_lldb_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Generated file, do not edit.
#

import lldb

def handle_new_rx_page(frame: lldb.SBFrame, bp_loc, extra_args, intern_dict):
"""Intercept NOTIFY_DEBUGGER_ABOUT_RX_PAGES and touch the pages."""
base = frame.register["x0"].GetValueAsAddress()
page_len = frame.register["x1"].GetValueAsUnsigned()

# Note: NOTIFY_DEBUGGER_ABOUT_RX_PAGES will check contents of the
# first page to see if handled it correctly. This makes diagnosing
# misconfiguration (e.g. missing breakpoint) easier.
data = bytearray(page_len)
data[0:8] = b'IHELPED!'

error = lldb.SBError()
frame.GetThread().GetProcess().WriteMemory(base, data, error)
if not error.Success():
print(f'Failed to write into {base}[+{page_len}]', error)
return

def __lldb_init_module(debugger: lldb.SBDebugger, _):
target = debugger.GetDummyTarget()
# Caveat: must use BreakpointCreateByRegEx here and not
# BreakpointCreateByName. For some reasons callback function does not
# get carried over from dummy target for the later.
bp = target.BreakpointCreateByRegex("^NOTIFY_DEBUGGER_ABOUT_RX_PAGES$")
bp.SetScriptCallbackFunction('{}.handle_new_rx_page'.format(__name__))
bp.SetAutoContinue(True)
print("-- LLDB integration loaded --")
5 changes: 5 additions & 0 deletions example/ios/Flutter/ephemeral/flutter_lldbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Generated file, do not edit.
#

command script import --relative-to-command-file flutter_lldb_helper.py
12 changes: 6 additions & 6 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Volumes/MyData/Flutter_SDK/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/admin/Desktop/FlutterBarcodeScanner/flutter_barcode_scanner/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_ROOT=C:\Development\flutter"
export "FLUTTER_APPLICATION_PATH=E:\Flutter\Package\flutter_barcode_scanner\example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_BUILD_NAME=2.0.0.0"
export "FLUTTER_BUILD_NUMBER=2.0.0.0"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
export "PACKAGE_CONFIG=.dart_tool/package_config.json"