Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 添加“时出错”;小部件;“内部为字段”;国家<;NormalMenuState>&引用;颤振类_Flutter_Dart - Fatal编程技术网

Flutter 添加“时出错”;小部件;“内部为字段”;国家<;NormalMenuState>&引用;颤振类

Flutter 添加“时出错”;小部件;“内部为字段”;国家<;NormalMenuState>&引用;颤振类,flutter,dart,Flutter,Dart,此类实施的目的 登录脚手架主体后,显示管理员和用户的不同视图 错误 在状态类中使用小部件作为字段时显示以下错误 “_NormalMenuState.widget”(”)→ Widget')不是对“State.Widget”()的有效重写→ NormalMenuState') 代码 class NormalMenu extends StatelessWidget { final String userType; NormalMenu({this.userType}); @overr

此类实施的目的

登录
脚手架主体
后,显示
管理员
用户
的不同视图

错误

状态
类中使用
小部件
作为字段时显示以下错误

“_NormalMenuState.widget”(”)→ Widget')不是对“State.Widget”()的有效重写→ NormalMenuState')

代码

class NormalMenu extends StatelessWidget {
  final String userType;

  NormalMenu({this.userType});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyHomePage(this.userType),
    );
  }
}

class NormalMenuState extends StatefulWidget {
  final String userType;

  NormalMenuState(this.userType);

  @override
  State<StatefulWidget> createState() => _NormalMenuState(userType: this.userType);
}

class _NormalMenuState extends State<NormalMenuState> {
  String appTitle = 'Welcome';
  final String userType;
  Widget widget; //<= `This line shows error`

  _NormalMenuState({this.userType});

  @override
  void initState() {
    if (this.userType == UserType.admin) {
      this.appTitle = "User Information";
      widget = UserInformation();
    } else {
      this.appTitle = "Pay Fair";
      widget = BookTicket();
    }
    super.initState();
  }
class NormalMenu扩展了无状态小部件{
最终字符串用户类型;
NormalMenu({this.userType});
@凌驾
小部件构建(构建上下文){
返回材料PP(
主页:MyHomePage(this.userType),
);
}
}
类NormalMenuState扩展StatefulWidget{
最终字符串用户类型;
NormalMenuState(this.userType);
@凌驾
State createState()=>\u NormalMenuState(用户类型:this.userType);
}
类_NormalMenuState扩展状态{
字符串appTitle='Welcome';
最终字符串用户类型;

Widget Widget;//如果您检查源代码:

abstract class State<T extends StatefulWidget> extends Diagnosticable {
  T get widget => _widget;

我建议您将小部件更改为displayWidget。因为小部件已经用于检索在NormalMenuState中传递的值,例如userType

Widget widget; => Widget myWidget;