|
1 | 1 | package yy.inc.flutter_custom_dialog;
|
2 | 2 |
|
| 3 | +import androidx.annotation.NonNull; |
| 4 | + |
| 5 | +import io.flutter.embedding.engine.plugins.FlutterPlugin; |
3 | 6 | import io.flutter.plugin.common.MethodCall;
|
4 | 7 | import io.flutter.plugin.common.MethodChannel;
|
5 | 8 | import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
|
6 | 9 | import io.flutter.plugin.common.MethodChannel.Result;
|
7 | | -import io.flutter.plugin.common.PluginRegistry.Registrar; |
8 | 10 |
|
9 | 11 | /** FlutterCustomDialogPlugin */
|
10 | | -public class FlutterCustomDialogPlugin implements MethodCallHandler { |
11 | | - /** Plugin registration. */ |
12 | | - public static void registerWith(Registrar registrar) { |
13 | | - final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_custom_dialog"); |
14 | | - channel.setMethodCallHandler(new FlutterCustomDialogPlugin()); |
| 12 | +public class FlutterCustomDialogPlugin implements FlutterPlugin, MethodCallHandler { |
| 13 | + |
| 14 | + private MethodChannel channel; |
| 15 | + |
| 16 | + @Override |
| 17 | + public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { |
| 18 | + channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "flutter_custom_dialog"); |
| 19 | + channel.setMethodCallHandler(this); |
15 | 20 | }
|
16 | 21 |
|
17 | 22 | @Override
|
18 | | - public void onMethodCall(MethodCall call, Result result) { |
| 23 | + public void onMethodCall(@NonNullMethodCall call,@NonNull Result result) { |
19 | 24 | if (call.method.equals("getPlatformVersion")) {
|
20 | 25 | result.success("Android " + android.os.Build.VERSION.RELEASE);
|
21 | 26 | } else {
|
22 | 27 | result.notImplemented();
|
23 | 28 | }
|
24 | 29 | }
|
| 30 | + |
| 31 | + @Override |
| 32 | + public void onDetachedFromEngine(FlutterPluginBinding binding) { |
| 33 | + channel.setMethodCallHandler(null); |
| 34 | + } |
25 | 35 | }
|
0 commit comments