Flutter Android Toast Message Using platform channel

Ishan Fernando
Mar 9 · 2 min read

What is Platform channel

Implementation

Flutter side

import 'package:flutter/services.dart';
static const platform = const MethodChannel("toast.flutter.io/toast");
platform.invokeMethod("showToast");

Android side

private static final String CHANNEL = "toast.flutter.io/toast";
new MethodChannel(getFlutterView(),CHANNEL).setMethodCallHandler(new MethodChannel.MethodCallHandler() { @Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
if(methodCall.method.equals("showToast")){
Toast.makeText(getApplicationContext(),"Flutter Toast",Toast.LENGTH_SHORT).show();
}
else {
result.notImplemented();
}
}
});

FlutterPub

The Pub(lication) for all about the Flutter and its magic

Ishan Fernando

Written by

App developer. Android | ios | Flutter . Blogger

FlutterPub

The Pub(lication) for all about the Flutter and its magic