首页 > 其他分享 >真机调试 Flutter 报错:Lookup failed: title in @getters in MyHomePage in package:flutter_demo02/main.dart

真机调试 Flutter 报错:Lookup failed: title in @getters in MyHomePage in package:flutter_demo02/main.dart

时间:2023-12-10 16:55:05浏览次数:49  
标签:src 真机 package dart demo02 报错 MyHomePage main flutter

发生缘由

学习 Flutter 更改 lib 目录下面的 main.dart 文件之后真机调试运行 flutter run 报错:

 1 # 小组件库异常
 2 ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
 3 # 构建MyHomePage的时候抛出下列_CompileTimeError
 4 The following _CompileTimeError was thrown building MyHomePage(dirty, dependencies:
 5 [_InheritedTheme, _LocalizationsScope-[GlobalKey#34833]], state: _MyHomePageState#2db8a):
 6 # 查找失败:包 MyHomePage 中 @getters 中的标题:flutter_demo02/main.dart
 7 Lookup failed: title in @getters in MyHomePage in package:flutter_demo02/main.dart
 8 
 9 # 相关的导致错误的小部件是:MyHomePage
10 The relevant error-causing widget was:
11   MyHomePage
12   MyHomePage:file:///D:/Prog/flutter/material/flutter_proj/flutter_demo02/lib/main.dart:34:19
13 
14 When the exception was thrown, this was the stack:
15 #0      StatefulElement.build (package:flutter/src/widgets/framework.dart:5583:27)
16 #1      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5471:15)
17 #2      StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5634:11)
18 #3      Element.rebuild (package:flutter/src/widgets/framework.dart:5187:7)
19 #4      BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2895:19)
20 #5      WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:984:21)
21 #6      RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
22 #7      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
23 #8      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
24 #9      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:978:7)   
25 #13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
26 (elided 3 frames from class _Timer and dart:async-patch)

main.dart 文件内容如下:

 1 import 'package:flutter/material.dart';
 2 
 3 void main() {
 4     // 顶层组件MaterialApp,它封装了应用程序实现 Material Design 所需要的一些 Widget。
 5     runApp(MaterialApp(
 6         // 基础布局组件Scaffold 是MaterialDesign布局结构的实现 提供了显示drawer、snackbar和底部sheet的API
 7         home: Scaffold(
 8             appBar: AppBar(title: const Text("你好Flutter")),
 9             // 抽离出来了一个HomeWidget的组件
10             body: const HomeWidget(),
11         ),
12     ));
13 }
14 
15 // 自定义组件其实就是一个类,这个类需要继承StatelessWidget或者StatefulWidget
16 // StatelessWidget 是无状态组件,状态不可变的widget
17 class HomeWidget extends StatelessWidget {
18     // 构造函数调用父类的构造函数
19     const HomeWidget({Key? key}) : super(key: key);
20 
21     @override
22     Widget build(BuildContext context) {
23         return const Center(
24             child: Text(
25                 "我是一个文本",
26                 textDirection: TextDirection.ltr,
27                 style: TextStyle(
28                     fontSize: 40.0,
29                     // color: Colors.yellow,
30                     color: Color.fromRGBO(244, 233, 121, 0.5),
31                 ),
32             ),
33         );
34     }
35 }

运行环境

  • 电脑系统版本:Windows 10 64bit

  • VS Code:1.72.0(user setup)

  • Flutter:3.16.0

# 查看Flutter版本
C:\Windows\System32>flutter --version
Flutter 3.16.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision db7ef5bf9f (4 weeks ago) • 2023-11-15 11:25:44 -0800
Engine • revision 74d16627b9
Tools • Dart 3.2.0 • DevTools 2.28.2

问题解决

问题出在 test 目录下面的 widget_test.dart 文件,正是它让项目构建失败了。因为修改完 main.dart 文件之后导致MyApp 组件,因此该测试文件就会出错。

解决原因很简单:

  • 将测试文件删掉

  • 亦或是将 HomeWidget 类更改为 MyApp。

最后告诫

删除掉文件亦或是修改完之后如果 r 键没有作用,那么可以 R 键。

常用快捷键作用
r 键 点击后热加载,也就算是重新加载吧
R键 热重启项目
p 键 显示网格,这个可以很好的掌握布局情况,工作中很有用
o 键 切换android和ios的预览模式
q 键 退出调试预览模式

标签:src,真机,package,dart,demo02,报错,MyHomePage,main,flutter
From: https://www.cnblogs.com/linxuannihao/p/17892870.html

相关文章

  • Github提交大文件时报错
    Github提交大文件时报错报错如下remote:error:GH001:Largefilesdetected.YoumaywanttotryGitLargeFileStorage-https://git-lfs.github.com.​​​​解决办法下载git-lfs后安装https://www.123pan.com/s/KYyzVv-hwrzv.html提取码:GmA0下载并安装......
  • 安装 lxml==4.5.1版本报错
    前言全局说明安装lxml==4.5.1版本时,报错:一、先说解决方法原因:可能是模块指定版本太老,需要的python版本也要旧一些,安装3.10.11和3.9都不行,解决:降到3.8.10就可以了安装包名:python-3.8.10-amd64.exe有的说jiang到python==3.9.12也可以(我没试,就直接用我之前安装......
  • yum安装软件时报错"Curl error (37): Couldn't read a file:// file for file:///etc/
    问题描述安装gcc时出现以下问题:Curlerror(37):Couldn'treadafile://fileforfile:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64[Couldn'topenfile/etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64]系统情况系统:fedora-39国内镜像源:阿里云1、阿里云2解决方案此......
  • flinkcdc连接oracle的报错汇总
    报错一:原因分析:字面原因,找不到 org.apache.flink.table.api.ValidationException类。解决办法:根据类名可知,应该 org.apache.flink.table.api包下面的,然后去阿里云maven仓库搜索,添加如下依赖即可 报错二:原因分析:ORA-16331:容器"ORCLPDB1"未打开。解决办法:使用命令打......
  • 卸载节点Clusterware执行rootcrs.pl时报错"Compilation failed in require..."
    问题描述:卸载节点Clusterware执行rootcrs.pl时报错"Compilationfailedinrequire...",如下所示:系统:rhel7.364位数据库:oracle11.2.0.4rac3节点1、异常重现[root@rac3install]#./rootcrs.pl-deconfig-forceCan'tlocateEnv.pmin@INC(@INCcontains:/usr/local/li......
  • 报错:java.lang.IllegalArgumentException
    问题表象开发,测试环境运行正常的接口到现场报错,报错日志关键信息如下:java.lang.IllegalArgumentException:Invalidcharacterfoundintherequesttarget.ThevalidcharactersaredefinedinRFC7230andRFC3986。问题分析及原因由于代码在开发测试环境测试通过,判断大概......
  • 虚拟机安装MySQL报错
    错误——mysql-community-common(x86-64)=5.7.28-1.el7被mysql-community-server-5.7.28-1.el7.x86_64需要 等可以通过yumremove-ymysql-libs命令解决  再之后正常操作就可以下载各种.rpm了 这个错解决了将近一天!(不知道为什么之前的解决方案不管用......
  • UBUNTU 18.04.6 编译PRELOADER遇到报错 undefined reference "“
    我是参考https://www.cnblogs.com/DoreenLiu/p/14392442.html安装的ubuntu-18.04.6-desktop-amd64.iso)接着参考Intel的SD卡image设计的教程(https://rocketboards.org/foswiki/Documentation/EmbeddedLinuxBeginnerSGuide),遇到问题参考https://www.cnblogs.com/DoreenLiu/p/1......
  • mybatis动态sql将字符串转换成数字类型报错
    报错信息org.mybatis.spring.MyBatisSystemException:nestedexceptionisorg.apache.ibatis.exceptions.PersistenceException: ###Errorqueryingdatabase.Cause:java.lang.NumberFormatException:Forinputstring:"xxx" ###Cause:java.lang.NumberFo......
  • 如何解决yum安装软件时报错This system is not registered with an entitlement serve
    RedHat、基于redhat源代码所编译的centos都会遇到这种问题,红帽需要对当前的系统进行注册后才能使用yum安装软件,解决方法多种多样,如直接注册+订阅/换yum源/干掉RedHatSubscriptionManager订阅管理器解决方法:这里介绍最简单的一种:禁用RedHatSubscriptionManager订阅管理......