Flutter App Keeps going back to intial route when I save changes - flutter

I am building a flutter app for Android and iOS. The challenge I am facing is that whenever I make any changes to the code and save, the app falls back to the initial route. It doesn't matter whether I use stateless or stateful widgets.
My flutter version:
Flutter 2.9.0-1.0.pre.465 • channel master • https://github.com/flutter/flutter.git
Framework • revision 2104a6d97f (3 hours ago) • 2022-01-24 05:05:21 -0500
Engine • revision 8204850dbe
Tools • Dart 2.17.0 (build 2.17.0-49.0.dev) • DevTools 2.9.2
My Doctor:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, 2.9.0-1.0.pre.465, on Microsoft Windows [Version 10.0.22000.466], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1)
[√] IntelliJ IDEA Community Edition (version 2020.3)
[√] VS Code (version 1.63.2)
[√] Connected device (3 available)
[√] HTTP Host Availability
• No issues found!
My Main:
void main() async {
if (Platform.isAndroid) {
runApp(const AndroidApp());
} else if (Platform.isIOS) {
runApp(const IosApp());
}
}
Everything else works well but I have several pages in my application and I have to navigate to each page I am working on each time I make a change. This also affects my input fields.
Please help.

convert your widget to a stateful widget and put your variable that contains your navigator key out of the build method of your widget, this will work

Related

Cannot see Flutter Web activity history in Firebase Analytics

I have added Firebase Analytics to a game I have developed as a Flutter web project and can see real-time data bars coming through for users in the last 30 minutes, but cannot see any historic user or event data. I added Firebase to my project yesterday and had a number of users access it, but cannot see any record of those events today.
I have gone through the set-up process again to check that everything is set up correctly and I believe that it is.
Accessing the web site this morning, I saw a real-time record of me accessing the app as below:
However, the historic user activity over time graph shows nothing:
I have created a Singleton to be able to access the analytics instances as follows:
// Singleton class to hold the Analytics for for Firebase
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:septuple/firebase_options.dart';
class Analytics {
Analytics._();
// Generate an instance of the firebase analytics class
final FirebaseAnalytics analytics = FirebaseAnalytics.instance;
// Create an instance of this class as a singleton
static final Analytics _instance = Analytics._();
// Initialise firebase for the app
static Future<void> init() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
getData().setAnalyticsCollectionEnabled(true);
}
//Get the FirebaseAnalystics object to do event logging
static FirebaseAnalytics getData() {
return _instance.analytics;
}
}
I have initialised this in my main() method as follows:
void main() async {
//
// Initialise the Hive database
await Hive.initFlutter();
await Hive.openBox('septupleBox');
//
// Initialise firebase in the Analytics singleton to enable event logging
//
await Analytics.init();
//
// Run the app
runApp(Game());
}
I am logging events in my state manager class, for example when the user guesses the word, as follows:
void setWin(int attempts) {
// Log end of game and that the user guessed correctly
Analytics.getData().logLevelEnd(
levelName: 'septuple',
success: attempts,
);
gameState = GameState.win;
_box.put(_gameStateName, gameState.toString());
_game.gameTimer.startCountdown();
notifyListeners();
}
"logLevelEnd is a default event type so I am assuming that this should just appear in Firebase Analytics. Do I need to configure anything so that it actively captures and retains this?
I am using the following dependencies for the project:
dependencies:
flutter:
sdk: flutter
hive: ^2.2.3
hive_flutter: ^1.1.0
responsive_sizer: ^3.1.1
#flutter_launcher_icons: ^0.10.0
toggle_switch: ^2.0.1
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
firebase_core: ^2.3.0
firebase_analytics: ^10.0.6
And finally, I have a firebase_options.dart file that is configured for web.
For completeness, here is the output from flutter doctor -v:
flutter doctor -v
[√] Flutter (Channel stable, 3.3.9, on Microsoft Windows [Version 10.0.22621.819], locale en-GB)
• Flutter version 3.3.9 on channel stable at D:\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision b8f7f1f986 (10 days ago), 2022-11-23 06:43:51 +0900
• Engine revision 8f2221fbef
• Dart version 2.18.5
• DevTools version 2.15.0
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0-rc1)
• Android SDK at C:\Users\LaptopBob\AppData\Local\Android\Sdk
• Platform android-33, build-tools 32.0.0-rc1
• ANDROID_HOME = C:\Users\LaptopBob\AppData\Local\Android\Sdk
• ANDROID_SDK_ROOT = D:\Users\LaptopBob\Android_SDK\avd
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.20)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.11.32929.386
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2021.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[√] VS Code (version 1.73.1)
• VS Code at C:\Users\LaptopBob\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.54.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.819]
• Chrome (web) • chrome • web-javascript • Google Chrome 108.0.5359.71
• Edge (web) • edge • web-javascript • Microsoft Edge 107.0.1418.56
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
As per this post, I have waited 24 hours for the data to come through (it is now 26 hours since I started getting bars on the "Users in last 30 minutes" panel).
Does anyone have any ideas why I am not seeing historic user or event data in Firebase Analytics?
The solution to this problem is "wait". The data turned up some time between 30 and 42 hours after the first event was posted to Firebase. Events from the following day also showed up (only 18 hours delay), so maybe there is an initial, longer delay when you first use the service. The only reference to updates I could find in the Firebase Analytics documentation says that the data is updated 'periodically' so I'm not sure how often the data will be updated.

The "--platforms" argument is not supported in module template

A brand new Flutter Project created in VSCode throws the above error when I try to run it on Windows. Detailed steps to reproduce below:
I created a new default Flutter application in VSCode.
I ran flutter config --enable-windows-desktop
I ran flutter devices.
Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19043.1766] Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.66 Edge (web) • edge • web-javascript • Microsoft Edge 103.0.1264.44
I ran the app in Vscode without debugging and chose Enable Windows for this Project.
It reported the error below.
flutter create --platforms windows . The "--platforms" argument is not supported in module template. exit code 2
flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.0.4, on Microsoft Windows [Version 10.0.19043.1766], locale en-GB)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.6)
[√] Android Studio (version 4.2)
[√] VS Code (version 1.68.1)
[√] Connected device (3 available)
[√] HTTP Host Availability
• No issues found!
Edit: I recreated the applitaion from the command line and it ran through without problems. Looks like whatever the problem is, it's coming from VSCode

Flutter flutter_background_service app resuming issue

I am using the flutter package flutter_background_service
https://pub.dev/packages/flutter_background_service/example
when the app is resuming, I have this infinite message
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: plugins.flutter.io/sensors/accelerometer. Response ID XXXX
Flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.2, on Microsoft Windows [version 10.0.19042.1526], locale fr-CD)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.9.4)
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.64.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
• No issues found!
You can see this post and this issue.
But unfortunately it's not fixed yet. Maybe this is a bug.

Flutter app starts in an unusual way after reopening

I would be sounding silly but it is a real problem with me. I started flutter about a month ago and whenever I upload my app on my android device , I have never run it on an emulator ,it seems to remember its state not that state management one. I will explain what I mean.
Suppose I have my flutter with a text and appbar. So I run my app on my device It runs perfectly. Then I added a floating action button and I hot reloaded my app all is fine the floating action button is in my app. So I closed my pc and then I wanted to look at my app again So I opened it from my phone and the floating action button is gone only text and appbar.
I even uninstalled my app and reinstalled it using flutter run but there is still that problem.
Here is the output of flutter doctor
[√] Flutter (Channel beta, 1.19.0-4.1.pre, on Microsoft Windows [Version 6.3.9600], locale en-IN)
• Flutter version 1.19.0-4.1.pre at C:\flutt\flutter
• Framework revision f994b76974 (6 days ago), 2020-06-09 15:53:13 -0700
• Engine revision 9a28c3bcf4
• Dart version 2.9.0 (build 2.9.0-14.1.beta)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at C:\Users\Anupam Karn\AppData\Local\Android\sdk
• Platform android-29, build-tools 29.0.2
• Java binary at: C:\Program Files\Android\Android Studio2\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 3.6)
• Android Studio at C:\Program Files\Android\Android Studio2
• Flutter plugin version 45.1.1
• Dart plugin version 192.8052
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b04)
[√] VS Code
• VS Code at C:\Users\Anupam Karn\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.11.0
[√] Connected device (3 available)
• SM G600FY • cc07c483 • android-arm • Android 6.0.1 (API 23)
• Web Server • web-server • web-javascript • Flutter Tools
• Chrome • chrome • web-javascript • Google Chrome 83.0.4103.97
• No issues found!
Please help me sort out this issue it happens with every app I make
When you hot reload, no new apk is generated. The source code from the changed files is compiled into kernel files and sent to the mobile device’s Dart VM. The installed apk is untouched.
Read more here:
https://flutter.dev/docs/development/tools/hot-reload
So if you change something, hot reload, close the app and reopen the app it will be the old app again. If you only do flutter run (without build), you install the same old apk again. You need to run flutter build first to have an updated apk.

Error Creating new Flutter App with AndrodX

I'm trying to create a Flutter app with Android-X
following this this INFORMATION,
the date is quite recent,
so I'm assuming they are up to date.
The problem is when I run on flutter console
flutter create -a kotlin -i swift --androidx my-app-name
I get this error:
Could not find an option named "androidx".
(running: flutter create blablabla everything works fine)
[edit: this is my flutter doctor]
Doctor summary (to see all details, run flutter doctor -v): [√]
Flutter (Channel stable, v1.5.4-hotfix.2, on Microsoft Windows
[Version 10.0.17763.557], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK
version 28.0.3) [√] Android Studio (version 3.3) [√] VS Code (version
1.35.1) [√] Connected device (1 available)
• No issues found!
Did I miss something?