Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor
  • Loading branch information
Chris Yang committed Oct 7, 2019
commit 6488ff60c810a0a8f41a4835bd48cf83216bf3e3
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry.Registrar;

Expand All @@ -18,21 +19,16 @@ public class SharePlugin implements FlutterPlugin, ActivityAware {
private MethodCallHandler handler;
private Activity activity;
private Share share;
private MethodChannel methodChannel;

public static void registerWith(Registrar registrar) {
MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL);
Share share = new Share(registrar.activity());
MethodCallHandler handler = new MethodCallHandler(share);
channel.setMethodCallHandler(handler);
SharePlugin plugin = new SharePlugin();
plugin.setUpChannel(registrar.messenger());
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
final MethodChannel methodChannel =
new MethodChannel(binding.getFlutterEngine().getDartExecutor(), CHANNEL);
share = new Share(activity);
handler = new MethodCallHandler(share);
methodChannel.setMethodCallHandler(handler);
setUpChannel(binding.getFlutterEngine().getDartExecutor());
}

@Override
Expand All @@ -59,4 +55,11 @@ public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding
public void onDetachedFromActivityForConfigChanges() {
onDetachedFromActivity();
}

private void setUpChannel(BinaryMessenger messenger) {
methodChannel = new MethodChannel(messenger, CHANNEL);
share = new Share(activity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like activity is always null at this point. You can probably remove the local activity variable and exclusively use the setter method, instead.

handler = new MethodCallHandler(share);
methodChannel.setMethodCallHandler(handler);
}
}