用flutter编译时另一个项目的错误 [英] error of another project when compiling with flutter

查看:104
本文介绍了用flutter编译时另一个项目的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[  +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.
    );
  }
}

您可以看到代码不应显示此错误但是当我在任何项目中运行 flutter run时,该错误始终在控制台中显示,而该错误仅在执行另一个项目时才显示。我尝试卸载所有的Flutter,然后运行 flutter clean,但是这种情况仍然存在,并且我为解决此问题而发疯。我使用Windows 10和vscode

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.12版中的一些错误,它会打印旧的错误消息。

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.

相关git问题 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编译时另一个项目的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆