Send Keyboard Event Flutter - flutter

I am trying to find a way to send keyboard events from my flutter app to a WebView that I have open in app. For example, the WebView has some JS code with an Observer that waits for key events to happen. Any idea how could I do that?

You can use the KeyboardListener class and send the data on the WebView javaScriptChannels property (considering you are using webview_flutter package).

Related

How can I use Navigator in onBackgroundMessageHandler of Firebase in killed state in Flutter?

I have developed a flutter app where it has calling feature with Agora SDK. In the latest version of firebase_messaging package, the method onBackgroundMessageHandler is made a separate isolate which will have its own context and memory.
Isolates should be
Top level methods or
Static methods inside the class.
when onBackgroundMessageHandler is made top-level function, the method doesn't get called in killed state in release mode. The solution for release mode issue is being solved as per most of the solutions provided by the flutter community.
The solution is to use #pragma like below
#pragma('vm:entry-point')
Future<void> onBackgroundMessageHandler(RemoteMessage message){}
This #pragma('vm:entry-point') is used to indicate the compiler that this method will be used from native code.
Using #pragma('vm:entry-point') poses an issue of not able to access the navigator context to show the incoming call.
Libraries used to achieve calling feature
Agora SDK for voice calling : agora_rtc_engine
Flutter Incoming Call for calling notification : flutter_incoming_call
GetX for navigation: get
Problems
Adding #pragma('vm:entry-point') does not provide Navigator in killed state to push a new screen.
Not Adding #pragma('vm:entry-point') does not work in the killed state.
I'm using flutter_incoming_call for showing the calling notification where I'm showing "Accept" and "Decline" buttons. Tapping on "Accept" button somehow I'm able to navigate to Incoming call screen but the next time when I'm trying to navigate to any screen without relaunching the app, throws an error as below
You are trying to use contextless navigation without
a GetMaterialApp or Get.key.
If you are testing your app, you can use:
[Get.testMode = true], or if you are running your app on
a physical device or emulator, you must exchange your [MaterialApp]
for a [GetMaterialApp].
I tried replacing this with global key implementation.
GlobalKey<NavigationState> navigatorKey = GlobalKey<NavigationState>();
This gives navigorKey.currentState as null.
I would need the help from Flutter community to resolve this issue of navigating to any screen from killed state in onBackgroundMessageHandler method of firebase.
If there are any other solutions, I'd like to hear them too. Please provide any suggestions.

flutter, after push a native viewController from flutter, is this possible display more content above native viewController with flutter again?

I have a native viewController which implement from a framework, I can't directly change it into flutter view.
So I think I can:
Display the UI in native ViewController(a 3rd party native video player) from flutter main app.
Then I need display some extra content(for example user avatar, some text message and so on) above/on native ViewController
But I would prefer implement this extra content with flutter, if it's possible?
Is this good approach ? If not, then I think have to do the things bellow:
Display the UI in native ViewController(a video player) from flutter main app.
Then display some extra content with native code.
PS: why I can't change the native VideController into flutter ? it's because it integration with a native video player which integration cache logic and I can't change the source code in that.
According to [1] it is fine to have some component native, because there just are not all features in new cross platform frameworks like flutter.
According to [2] you could use Decorators from Container to show content in layers, taken that you can show the native content embedded to the Flutter code. In that case, definitely use approach 1.
However, I could only find platform-channels type of solution from Flutter documentation [4] to do native code execution and there it states for example this:
To comply with channels’ UI thread requirement, you may need to jump from a background thread to Android’s UI thread to execute a channel method.
and in other post [3] on platform-channels:
When the user clicks back I want to navigate back to flutter [..]
Both imply everything that is native happens in native thread and view, so I don't see possibility other than your second approach, where all is native.
So, all depends how you fit the native element to Flutter. If you embed, use Flutter for overlays, otherwise do all native. I think good way to measure this is that if you see anything from Flutter generated code when inside the native viewer, you have chances to overlay, otherwise just go native.
[1] Open native UIViewController in Flutter
[2] https://cogitas.net/overlay-text-icon-image-flutter/
[3] How to change the root view controller back to flutter from native iOS?
[4] https://flutter.dev/docs/development/platform-integration/platform-channels

How to know if FCM's `onLaunch` callback is gonna be called or not

So my project has the different navigation logic based on how user launch my app: by tap the icon laucher or via FCM's notification's tap. The case is I don't know if the FCM's onLaunch callback is gonna be called or not to decide which logic to use. Is there any good approach to this problem?
You can check how your activitiy is started like this (You can use invoke method of flutter to get this result in flutter)
if("android.intent.action.MAIN".equals(getIntent().getAction())){
// By taping the icon launcher
}else{
//By other source
}

How to detect hardware key taps?

I am at a point where I need to detect if any of the hardware buttons was presses when the flutter app is in foreground or when it is open.*
For example, when someone presses a volume or another button (even if it is the power off one) I want to perform some action in my app.
I know that when a flutter app is open and I am looking at the app logs and I tap any hardware button is tapped the lops related to that tap is printed in the logs.
Like when I press Vol down Key Down Tap Detected related logs are printed in logs.
How do can I perform a function when any of the above specified action is performed?
New plugin called Hardware Buttons was released just a few days ago.
It supports volume button events and power button events, which seems like fits your need.
Maybe have a go with this?
You will need find the proper flutter packages to do so.
Any system level call needs to use the platform channel api
https://flutter.io/platform-channels/
Here is the repository
https://pub.dartlang.org/flutter/
Here is an example of a method channel.
https://github.com/flutter/plugins/blob/master/packages/device_info/lib/device_info.dart
Here is an example of a stream listener.
https://github.com/flutter/plugins/tree/master/packages/sensors
The stream listener wasn't really well documented when I tried to grab mic fragments.

How to Detect if WebView is showing a specific Website on iPhone

I am new in iOS development and trying to make a button called backhome which is only visible when the user tap on the changes the native Website I set in the loadRequest.
Now my question: Is there any way to detect if the user leaves the website I set for e.g in a if statement?
Set a delegate for your "UIWebView" object and then write a method to respond to:
webView:shouldStartLoadWithRequest:navigationType:
The request parameter in that call has a URL and from there, you can tell if the user has left your default website.