繁体   English   中英

Flutter dart 调试器断点停止工作

[英]Flutter dart debugger breakpoints stopped working

我正在学习 Dart 和 Flutter 并在 Android Studio 3.1.2 下开发一个小型 Android Flutter 应用程序。 突然调试器断点停止工作 - 以调试模式启动的应用程序永远不会在它们上停止,并且指示断点的红点变为内部带有 x 的红点。 我的应用程序中唯一仍然可以工作的地方是 main.dart 模块。

我多次清理了项目,在两种不同的设备上进行了测试,完全卸载了我的 Flutter 调试应用程序,然后开始了新的 - 没有任何帮助。 beta(当前 beta 2)频道上的 Flutter 更新什么都不做。 还尝试切换到开发和主频道 - 没有帮助。

有没有人遇到过类似的情况,怎么处理?

编辑,添加mail.dart和flutter Doctor的输出(目前在master分支,但切换到beta或dev分支后也有同样的问题):

从 main.dart 或更好的所有 main.dart 导入:

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

import 'app_strings.dart';
import 'net_libs_page/net_libs_page.dart';

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        // ... app-specific localization delegate[s] here
        AppLocalizationsDelegate(),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        //FallbackMaterialLocalisationsDelegate(),
      ],
      supportedLocales: [
        Locale('en', 'US'), // English
        Locale('es', 'ES'), // Spanish
        Locale('pl', 'PL'),
        // ... other locales the app supports
      ],
      title: '@Voice Network Library', //_strings.title,
      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 press Run > Flutter Hot Reload in IntelliJ). Notice that the
        // counter didn't reset back to zero; the application is not restarted.
        primarySwatch: Colors.indigo,
      ),
      home: NetLibsPage(),
    );
  }
}

颤振医生输出:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel master, v0.4.5-pre.52, on Microsoft Windows [Version 10.0.16299.431], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
[!] IntelliJ IDEA Ultimate Edition (version 2018.1)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code, 32-bit edition (version 1.19.3)
[√] Connected devices (1 available)

! Doctor found issues in 2 categories.

不要在lib/main.dart中使用相对导入

import 'app_strings.dart';
import 'net_libs_page/net_libs_page.dart';

改为使用

import 'package:my_app/app_strings.dart';
import 'package:my_app/net_libs_page/net_libs_page.dart';

其中my_apppubspec.yaml中的name:字段。

跟踪此问题的问题https://github.com/dart-lang/sdk/issues/33076

似乎导入路径中路径的大写导致断点停止工作。 IE:

package:myApp/model/myWidget/myWidget.dart

package:myApp/model/MyWidget/MyWidget.dart

调试不一样。 有趣的是,应用程序启动时路径大小写不正确。

对于那些在 VS Code 上使用颤振的人,

请查看您对 dart 文件名所做的更改。

我在 VS Code 上遇到了同样的问题。 它没有显示编译错误,工作正常但断点不起作用。

当我进行更改时,我查看了一些我更改为的 dart 文件。

例如,我将“Home.dart”更改为“home.dart”,等等。

即使您更改文件名,VS Code 有时也不会反映更改,

这意味着即使您将 Home.dart 更改为 home.dart,

左侧面板显示 home.dart,而右侧面板显示您打开的文件仍显示“Home.dart”

下面的图片解释了我刚才提到的一切。

在此处输入图像描述

在此处输入图像描述

解决方案是简单地关闭您打开的所有 dart 文件,关闭 VS Code,然后重新打开它。 这对我有用。

就我而言,Flutter Doctor 没有发现任何错误。 在花了一些时间尝试解决它之后,Android Studio 向我显示了一条更新 Dart 和插件的正常消息。 更新后,重启 Android Studio 就足够了。 工作完美。

只是遇到同样的问题,颤振调试器永远不会在断点处停止。 这发生在我原来的模拟器损坏并重新创建了一个新的模拟器之后。

对我有用的解决方案很简单。

delete all breakpoints, watchlist
close the vscode
flutter clean
restart vscode

如果上述方法不适合您,如何调试此问题?

  1. 请参阅此github 问题 复制粘贴以下内容,方便参考
- Created a new project using the Flutter: New Project command
- Added the following code to lib/main.dart

class TestClass {
  void foo() {
    print('foo');
  }
}

- Added a breakpoint to the print line
- Added the following code to the top of the test/widget_test.dart file in the existing test

TestClass().foo();

- Clicked the Debug link above the test

如果上述方法有效,则意味着您的项目中有特定的东西导致调试器无法正常工作。

  1. 在浏览器中使用 devTool,使用它附带的调试器工具来设置你的断点,看看它是否有效。

  2. 使用 dart 程序断点

import 'dart:developer';

yourFunc() {
  // ...
  debugger();
}

从那里你可能会有一些想法来解决这个问题。 祝你好运。

对我有用的解决方案:

简单地

卸载你的颤振应用

从真实设备(在设备上手动)并再次尝试调试(!)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM