I want to show a dialog in whole app when a intent is triggered. For this, I add onNewIntent listener in android and invoke a flutter method:
@Override
protected void onNewIntent(Intent intent) {
if (intent.getAction().equals("android.hardware.usb.action.USB_DEVICE_ATTACHED")) {
methodChannel.invokeMethod("method_name", null);
}
super.onNewIntent(intent);
}
and in the main.dart, in initState method set a methodCallHandler for this method:
@override
void initState() {
super.initState();
AndroidApi.platform.setMethodCallHandler((call) async {
debugPrint("here");
if (call.method == "method_name") {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) => const LoadingDialog(),
);
}
});
}
In the console, I see the onNewIntent log and "method_name"
is called. and I see the "here"
log in my console. but the dialog is not shown. Can you find the problem?