|
| 1 | +package com.mtechviral.fluttertoast; |
| 2 | + |
| 3 | +import android.app.Activity; |
| 4 | +import android.widget.Toast; |
| 5 | + |
| 6 | +import io.flutter.plugin.common.MethodCall; |
| 7 | +import io.flutter.plugin.common.MethodChannel; |
| 8 | +import io.flutter.plugin.common.MethodChannel.MethodCallHandler; |
| 9 | +import io.flutter.plugin.common.MethodChannel.Result; |
| 10 | +import io.flutter.plugin.common.PluginRegistry.Registrar; |
| 11 | + |
| 12 | +/** FlutterToastPlugin */ |
| 13 | +public class FlutterToastPlugin implements MethodCallHandler { |
| 14 | + |
| 15 | + private final MethodChannel channel; |
| 16 | + private Activity activity; |
| 17 | + |
| 18 | + /** Plugin registration. */ |
| 19 | + public static void registerWith(Registrar registrar) { |
| 20 | + final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_toast"); |
| 21 | + channel.setMethodCallHandler(new FlutterToastPlugin(registrar.activity(),channel)); |
| 22 | + } |
| 23 | + |
| 24 | + private FlutterToastPlugin(Activity activity, MethodChannel channel){ |
| 25 | + this.activity = activity; |
| 26 | + this.channel = channel; |
| 27 | + this.channel.setMethodCallHandler(this); |
| 28 | + } |
| 29 | + |
| 30 | + |
| 31 | + @Override |
| 32 | + public void onMethodCall(MethodCall call, Result result) { |
| 33 | + if (call.method.equals("getPlatformVersion")) { |
| 34 | + result.success("Android " + android.os.Build.VERSION.RELEASE); |
| 35 | + } |
| 36 | + else if(call.method.equals("showToast")){ |
| 37 | + String msg = call.argument("msg").toString(); |
| 38 | + Toast.makeText(activity,msg,Toast.LENGTH_LONG).show(); |
| 39 | + } |
| 40 | + |
| 41 | + else { |
| 42 | + result.notImplemented(); |
| 43 | + } |
| 44 | + } |
| 45 | +} |
0 commit comments