简体   繁体   English

“没有为“MyApp”类型定义方法“SplashScreen”。”。 我尝试了很多东西,但一无所获。 有什么解决办法吗?

[英]"The method 'SplashScreen' isn't defined for the type 'MyApp'.". I have tried a lot of things and nothing. Any solution?

main.dart:主要飞镖:

import 'package:flutter/material.dart' show BuildContext, Colors, MaterialApp, StatelessWidget, ThemeData, VisualDensity, Widget, runApp;

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.

  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        // Application name
        title: 'UranteX',
        theme: ThemeData(
          primarySwatch: Colors.red,
          visualDensity: VisualDensity.adaptivePlatformDensity,
        ),
        home: SplashScreen());
  }

splashScreen.dart(2nd page) splashScreen.dart(第 2 页)

import 'package:flutter/material.dart' show BuildContext, Center, Column, Container, CrossAxisAlignment, Image, MainAxisAlignment, Scaffold, SizedBox, State, StatefulWidget, Widget;

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        height: double.infinity,
        width: double.infinity,
        child: Center(
          child: Column(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [
            SizedBox(
              height: 300.0,
              child: Image.asset('Images/logo.png'),
            )
          ]),
        ),
      ),
    );
  }
}

///The code isn't working and its saying that"The method 'SplashScreen' isn't defined for the type 'MyApp'". ///代码不起作用,它说“方法'SplashScreen'没有为类型'MyApp'定义”。 I know the solution probably is on the "Container" but I can't solve it.我知道解决方案可能在“容器”上,但我无法解决。

Solution: You have to import splashScreen.dart file into your main.dart Reason of problem: You are calling SplashScreen class which is in another file so how main.dart file will get to know that what is SplashScreen there So you need to import splashscreen.dart file so that main.dart will know that SplashScreen is a class from splashScreen.dart file.解决方案:您必须将 splashScreen.dart 文件导入 main.dart 问题原因:您正在调用另一个文件中的 SplashScreen 类,因此 main.dart 文件将如何知道那里的 SplashScreen 所以您需要导入 splashscreen .dart 文件,以便 main.dart 知道 SplashScreen 是 splashScreen.dart 文件中的一个类。

If you still have doubt then you can ask if you satisfied then give this answer an upvote so that more will learn this.如果您仍然有疑问,那么您可以询问您是否满意,然后给这个答案一个赞成票,以便更多人了解这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何清除我的 recyclerView 数据? 我从同类型的问题中尝试了很多东西,但没有任何帮助 - How can i clear my recyclerView data? I have tried a lot of stuff from same type of questions but nothing has helped me 没有为“FirebaseApp”类型定义“配置”方法 - The method 'configure' isn't defined for the type 'FirebaseApp' 方法 &#39;placemarkFromCoordinates&#39; 没有为类型 &#39;Geolocator&#39; 定义 - The method 'placemarkFromCoordinates' isn't defined for the type 'Geolocator' Dart Flutter 未为类型“sqliteDaatabase”定义方法“getDatabasePath”。 错误 - Dart Flutter The method 'getDatabasePath' isn't defined for the type 'sqliteDaatabase'. Error 错误:没有为“完成者”类型定义方法“setMapStyle” - error: The method 'setMapStyle' isn't defined for the type 'Completer' 错误:未在 flutter 中为类型“FirebaseMessaging”定义方法“configure” - error: The method 'configure' isn't defined for the type 'FirebaseMessaging' in flutter 未定义方法“MaterialPageRoute” - The method 'MaterialPageRoute' isn't defined 没有为 class 定义该方法 - The method isn't defined for the class 意图未定义尝试了很多,没有任何作用 - intent is undefined tried a lot , nothing works 没有为类型“****”定义方法“setState”。 尝试将名称更正为现有方法的名称,或定义一个名为 - The method 'setState' isn't defined for the type '****'. Try correcting the name to the name of an existing method, or defining a method named
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM