Flutter Dart调试器断点失效求助:仅main.dart可正常触发
解决Flutter调试断点仅main.dart生效的问题
Hey there, I've run into similar breakpoint issues with Flutter in Android Studio before, let's walk through some fixes that worked for me and others facing this exact problem:
可能的解决步骤
- 检查文件的目录标记:有时候非
main.dart的文件会被误标记为非编译资源。在Android Studio里右键目标文件所在的文件夹,选择Mark Directory as > Sources Root,确保IDE把这些文件当成可编译的源码。 - 禁用Android Studio的即时运行:Instant Run经常会和Flutter的调试机制冲突。去
File > Settings > Build, Execution, Deployment > Instant Run,勾选Disable Instant Run,然后重启IDE再试。 - 彻底清理项目缓存:先执行
flutter clean命令清空旧的构建文件,接着运行flutter pub get重新拉取依赖,最后重新构建并启动调试。 - 更新IDE插件版本:虽然你切换了Flutter通道,但Android Studio的Dart和Flutter插件版本可能不匹配。打开
File > Settings > Plugins,检查这两个插件是否是最新版,或者和当前Flutter版本兼容,更新后重启IDE。 - 删除项目配置文件:手动删除项目根目录下的
.idea文件夹和build文件夹,然后重新打开项目,让IDE重新生成所有配置文件,这能解决很多奇怪的配置问题。 - 测试新项目:创建一个全新的Flutter默认项目,测试断点是否正常工作。如果新项目没问题,那大概率是当前项目的配置出了问题,可以逐步把代码迁移过去排查。
你提供的代码和环境信息
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(), ); } }
flutter doctor 输出
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.
内容的提问来源于stack exchange,提问作者gregko
相关产品推荐
相关产品推荐

