0

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.

David
  • 473
  • 1
  • 4
  • 14
  • Are you running it on web? – Ali Punjabi Jan 24 '22 at 14:33
  • both android simulator and physical phone – David Jan 24 '22 at 14:39
  • run in debug mode and track the code flow, there should be a runApp within your build which causing hot restart on every save/hot reload. Moreover you can visit these links, it will help you: https://stackoverflow.com/questions/60927958/flutter-being-sent-back-to-initial-page-after-hot-reload https://stackoverflow.com/questions/65181421/flutter-app-keeps-going-back-to-initial-route-after-hot-reload – Ali Punjabi Jan 24 '22 at 14:48

1 Answers1

1

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