I am getting a crash on some android devices when running my Flutter app.
I have been able to debug a release version of the app and this is the only debug output:
W/FlutterJNI(27448): FlutterJNI.loadLibrary called more than once
W/FlutterJNI(27448): FlutterJNI.prefetchDefaultFontManager called more than once
W/FlutterJNI(27448): FlutterJNI.init called more than once
I donĀ“t know where should I begin to look for the reason of the issue.
The device is showing a gray screen and stops working.
Wherever you create the firebaseMessagingBackgroundHandler, annotate it with #pragma('vm:entry-point') like this:
#pragma('vm:entry-point')
Future<void> firebaseMessagingBackgroundHandler(RemoteMessage message) async {
}
The reason is explained here:
https://github.com/firebase/flutterfire/blob/master/packages/firebase_messaging/firebase_messaging/example/lib/main.dart#L46
Related
I am using Telephony plugin to develop a SMS app, and according to the similar solution, I added a decorator on the top of the background handler at the top level, then run it in release mode,
after running, debug mode is normal, and foreground is also normal in release mode,only both "background" and "terminated" are incorrect
#pragma('vm:entry-point')
Future<void> onBackgroundMessage(SmsMessage message) async {
debugPrint("onBackgroundMessage called");
............
}
after adding, it's still not working and appeared the same Dart error message:
"Dart Error: Dart_LookupLibrary: library 'package:telephony/telephony.dart' not found."
I have already added the decorator #pragma('vm:entry-point'), still doesn't work.
I solved the problem,just need to change or add a git link in pubspec.yaml,
telephony:
git:
url: https://github.com/definev/Telephony.git
ref: develop
want to create a screen that launch when a firebase notification is received while the app is in the background or terminated in flutter (like package callKeep ).please anyone help me create that.
You just need to handle its background handler method it will works.You need to initialize this method in main() method.
Future<void> backgroundHandler(RemoteMessage message) async {
debugPrint(message.toString());
debugPrint(message.data.toString());
debugPrint(message.notification!.title);
}
FirebaseMessaging.onBackgroundMessage(backgroundHandler);
I'm having an issue after my Simulator was updated to iOS 15 in my upcoming Flutter app. When I press the 'Home' button at the top it causes my app to fire the didChangePlatformBrightness() function twice.
Seriously thinking on remove this check while the app is already open and leave it only at startup. Anyone with the same problem and any tips on how to solve it?
On Android everything works fine, just as expected.
I solved this question by monitoring the App lifecycle state. If the app is in resumed state, then I change the color scheme, otherwise I'll do nothing. It occurs because when you press the Home button, the app state changes. See the example below:
void didChangePlatformBrightness() {
if (appState == AppLifecycleState.resumed) {
//give the user a choice for restarting the app, so the colors will
//all be set correctly
showThemeChangeWarning();
setColorScheme();
super.didChangePlatformBrightness();
}
}
Flutter Driver code has to tap on the native "Allow" button to continue and simulate the correct user behaviour.
See this screenshot. Native iOS popup before app starts - Allow Notifications
App has not yet completely started and is waiting for this tap.
How does one get the driver to tap on the native iOS popup?
Any suggestions and ideas are welcome.
Here is the code for one attempt to wait for the app before continuing with other tests; it just awaits indefinitely:
setUpAll(() async {
driver = await FlutterDriver.connect();
await driver.waitUntilFirstFrameRasterized();
});
Here is another attempt at finding the word "Allow" in the popup and tapping on it:
test('Allow app to send Notifications.', () async {
final allow = find.byTooltip("Allow");
await delay(750);
await driver.tap(allow);
});
It does not find the word.
The issue is probably that Flutter Driver is not aware of the iOS native popup.
Other tests are very simple once in the app, for example, to tap on fields, enter text, scroll pages, etc.
Any ideas on how to do this?
Unfortunately this feature is currently not possible. Flutter Driver can't interact with native elements (v1.20.4).
https://github.com/flutter/flutter/issues/34345
https://github.com/flutter/flutter/issues/12561
I am new in Flutter. I am working on one of my demo Flutter app. I have created 3 screens (Login, Signup and Home) in my app. I am just navigating to the Home screen from the login screen. Now I want to check - Is my app is alive or closed? - by clearing the app from the recent apps in Android and IOS. I have checked AppLifecycleState.detached and also checked override method dispose() but these are not calling while user killed the app.
Please help me how I come to know that my app got killed. Which method I need to use.
I have used AppLifecycleState.paused for other process. So I want any other way to handle it.
In native Android we can check this with the help of onDestroy() method and in iOS native app we can check it with the help of applicationWillTerminate() .
Which method I need to use for Flutter?
Please help me to fix it.
Thanks in Advance.
Hey so first of all we have to understand few things. The AppLifecycleState is invoked by flutter engine when the app goes in background or comes to foreground.
When its getting killed, its an OS callback, so you will have to deal with both iOS and android natively.
For android when an app is killed, an intent is fired, which is known as ACTION_PACKAGE_RESTARTED. You can invoke a broadcaster when it happens like
public class RestartReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String action= intent.getAction();
}
Note this is a Java code so you might have to write kotlin version yourself. Now you can invoke your broadcaster from Androidmanifest.xml
<receiver android:name=".ReceiverTest">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_RESTARTED" />
</intent-filter>
</receiver>
Something similar is available for Apple where you can get a callback for app termination.
I found one solution to detect if the app destroyed or exit. In flutter we have dispose() method. In my case the dispose() method was not called when app destroyed. So I just updated my dispose() method. See the below code.
#mustCallSuper
#protected
void dispose() {
// TODO: implement dispose
print('dispose called.............');
super.dispose();
}