error of another project when compiling with flutt

2020-02-15 12:09发布

问题:

[  +48 ms] I/flutter ( 5459): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
[   +4 ms] I/flutter ( 5459): The following message was thrown:
[   +1 ms] I/flutter ( 5459): Could not navigate to initial route.
[  +11 ms] I/flutter ( 5459): The requested route name was: "/login"
[        ] I/flutter ( 5459): The following routes were therefore attempted:
[        ] I/flutter ( 5459):  * /
[   +1 ms] I/flutter ( 5459):  * /login
[        ] I/flutter ( 5459): This resulted in the following objects:
[   +1 ms] I/flutter ( 5459):  * null
[        ] I/flutter ( 5459):  * MaterialPageRoute<dynamic>(RouteSettings("/login", null), animation: null)
[   +2 ms] I/flutter ( 5459): One or more of those objects was null, and therefore the initial route specified will be ignored and
[   +1 ms] I/flutter ( 5459): "/" will be used instead.
[        ] Building APK
[  +26 ms] Running Gradle task 'assembleDebug'...
[   +2 ms] gradle.properties already sets `android.enableR8`
[   +5 ms] Using gradle from D:\proyectos flutter\test2\android\gradlew.bat.
[  +12 ms] executing: D:\programas\Android Studio\jre\bin\java -version
[  +82 ms] Exit code 0 from: D:\programas\Android Studio\jre\bin\java -version
[        ] openjdk version "1.8.0_202-release"
           OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
           OpenJDK 64-Bit Server VM (build 25.202-b03, mixed mode)
[   +3 ms] executing: [D:\proyectos flutter\test2\android\] D:\proyectos flutter\test2\android\gradlew.bat -Pverbose=true
-Ptarget=D:\proyectos flutter\test2\lib\main.dart -Ptrack-widget-creation=true -Pfilesystem-scheme=org-dartlang-root
-Ptarget-platform=android-x86 assembleDebug
[   +2 ms] I/flutter ( 5459): ════════════════════════════════════════════════════════════════════════════════════════════════════
[   +1 ms] I/flutter ( 5459): Another exception was thrown: Could not find a generator for route RouteSettings("/", null) in the
_WidgetsAppState.

This error appeared to me for the first time when executing a project that had this error, from that moment all the projects that I launched the code compiles and works, but it always shows me this error that has nothing to do with the projects, but always shows this error that belongs to the project bull compilation

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          // Column is also a layout widget. It takes a list of children and
          // arranges them vertically. By default, it sizes itself to fit its
          // children horizontally, and tries to be as tall as its parent.
          //
          // Invoke "debug painting" (press "p" in the console, choose the
          // "Toggle Debug Paint" action from the Flutter Inspector in Android
          // Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
          // to see the wireframe for each widget.
          //
          // Column has various properties to control how it sizes itself and
          // how it positions its children. Here we use mainAxisAlignment to
          // center the children vertically; the main axis here is the vertical
          // axis because Columns are vertical (the cross axis would be
          // horizontal).
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

As you can see the code should not show this error but when I run "flutter run" in any project that error always shows it in console when that error should only show it when executing another project. I tried to uninstall all flutter and run "flutter clean" but this persists and I'm going crazy trying to fix this. I use windows 10 and vscode

回答1:

This is some bug in version 1.12 where it prints old error messages.

This can be seen even if you rerun the same code. Not reload or restart but stop the program and run it again. The error starts printing even in the compilation phase.

Related git issue https://github.com/flutter/flutter/issues/45478

It will be fixed in the next version.

A quick hack is cleaning the logs before starting the code.

flutter logs -c  (to clear, run in the project directory)

This needs to be used only once before launching the code and not after every restart or reload.



标签: flutter dart