首页 > 解决方案 > 试图运行颤振程序并不断收到此错误“方法'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(),
    );
  }
}

标签: flutter

解决方案


我认为您错过了 main.dart 顶部的 HomeScreen 导入文件。HomeScreen 类未根据您的代码在 main.dart 文件中定义。

或者也许类名是别的东西。再次检查。


推荐阅读