簡體   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