【问题标题】:The Material class in my new project doesn't know the home and route properties我的新项目中的 Material 类不知道 home 和 route 属性
【发布时间】:2021-10-17 18:46:57
【问题描述】:

我刚刚创建了一个新的颤振项目,当我尝试在 Material 应用程序中定义“home”属性时,我收到以下错误:“未定义参数“home”。”

可能与它有关的是我刚刚将我的 sdk 更新为:

environment:
  sdk: ">=2.12.0 <3.0.0"

之后我把它改回:

environment:
  sdk: ">=2.7.0 <3.0.0"

当我打开 Material 类时,我看到类中没有与路由相关的属性。

这是我的 main.dart 代码:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Material(home: );
  }
}
 and this is the code

Material 类(我没有更改,但创建时是这样的):

const Material({
    Key? key,
    this.type = MaterialType.canvas,
    this.elevation = 0.0,
    this.color,
    this.shadowColor,
    this.textStyle,
    this.borderRadius,
    this.shape,
    this.borderOnForeground = true,
    this.clipBehavior = Clip.none,
    this.animationDuration = kThemeChangeDuration,
    this.child,
  }) : assert(type != null),
       assert(elevation != null && elevation >= 0.0),
       assert(!(shape != null && borderRadius != null)),
       assert(animationDuration != null),
       assert(!(identical(type, MaterialType.circle) && (borderRadius != null || shape != null))),
       assert(borderOnForeground != null),
       assert(clipBehavior != null),
       super(key: key);

如您所见,不再有 home 或 routes 属性。当我打开一个旧项目时,它确实具有这些属性。

有人知道发生了什么吗?

【问题讨论】:

  • 将您的MaterialApp 代码添加到问题中

标签: flutter android-studio material-components-android


【解决方案1】:

啊,这太愚蠢了。谢谢@Sajad Abdollahi,我看到类的名称应该是 MaterialApp 而不是 Material。我一直在使用关于 Flutter 的过时课程,所以我认为这是我出错的地方。

【讨论】:

    猜你喜欢
    • 2016-01-13
    • 2017-05-12
    • 2016-06-23
    • 2023-02-24
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多