flutter - 试图运行颤振程序并不断收到此错误“方法'HomeScreen'没有为'MyApp'类型定义
问题描述
试图运行颤振程序并不断收到此错误“方法'HomeScreen'没有为我需要的'MyApp'类型定义并快速回答这个问题
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 Food Delivery UI',
debugShowCheckedModeBanner: false,
theme: ThemeData(
scaffoldBackgroundColor: Colors.grey[50],
primaryColor: Colors.deepOrangeAccent,
// 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: HomeScreen(),
);
}
}
解决方案
我认为您错过了 main.dart 顶部的 HomeScreen 导入文件。HomeScreen 类未根据您的代码在 main.dart 文件中定义。
或者也许类名是别的东西。再次检查。
推荐阅读
- php - 如何获取某个数组参数的值并将其放入另一个数组中?
- javascript - 如何有条件地为材质ui TreeView组件设置扩展道具
- reactjs - 如果用户来自浏览器 url 栏,NextJS 重定向不起作用
- vaticle-typedb - 如何从 grakn 控制台中删除键空间?
- php - 如何在复选框中显示回显“选中”编辑?
- html - 想要将一个 CSS 类添加到另一个具有不同属性的 CSS 类中
- scala - 如何实现接受参数化特征的子类型并返回它的scala泛型函数
- rasa - 安装rasa堆栈时出错
- flutter - Flutter - Material Design 2 半透明appbar
- java - 在 ec2 机器中声明时的 Tomcat 8