FlutterError:“在DrawerMenu上查找停用的小部件的祖先是不安全的”?

时间:2020-09-11 08:34:05

标签: flutter drawer

我有一个如下所示的列表。由于我上载了菜单项“语言”,因此返回部分无效。当我单击Flutter检查器时,出现如下图所示的错误。

List<MenuItem> menuItems = [
    MenuItem(title: 'Contact' items: [
      MenuItem(title: 'WriteUs'),
      MenuItem(title: 'Call Center' items: [
        MenuItem(title: 'Call Call Center'),
        MenuItem(title: 'We will call you'),
      ]),
      MenuItem(title: 'WhatsApp'),
    ]),
    MenuItem(title: 'Language' items: [
      MenuItem(title: 'English'),
      MenuItem(title: 'Pусский'),
    ]),
    MenuItem(title:'Dealer'),
  ];

我仅在两个地方使用菜单项,它们的代码在这里。当我从这里看时,很多回答是应该添加脚手架。我尝试了一下,但是没有用

  renderContent() {
return Scaffold(
  body: SafeArea(
    child: Padding(
      padding: EdgeInsets.only(
        left: 22,
        right: 22,
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MaterialButton(
            padding: EdgeInsets.only(top: 5, bottom: 5),
            onPressed: () {
              Navigator.pop(context);
            },
            child: Row(
              children: [
                Icon(Cat.x, size: 19, color: HexColor('#2C2C2C')),
              ],
            ),
          ),
          ...renderMenuItems(context, menuItems),
        ],
      ),
    ),
  ),
);

}

renderContentWithLogin() {
final topPadding = MediaQuery.of(context).padding.top;
return isLoading
    ? Container(
        color: Colors.white60,
        width: double.infinity,
        height: double.infinity,
        child: Padding(
          padding: EdgeInsets.all(10),
          child: CupertinoActivityIndicator(
            radius: 30,
          ),
        ),
      )
    : Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            padding: EdgeInsets.only(
                left: 22, right: 22, top: topPadding, bottom: 22),
            color: HexColor('#FFA300'),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                MaterialButton(
                  padding: EdgeInsets.only(top: 5, bottom: 25),
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  child: Row(
                    children: [
                      Icon(Cat.x, size: 19, color: Colors.white),
                    ],
                  ),
                ),
                Text(
                  me != null ? '${me['firstName']} ${me['lastName']}' : '',
                  style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                    color: Colors.white,
                  ),
                ),
                Text(
                  customer != null ? customer['name'] + ' $countryCode': '',
                  style: TextStyle(
                    fontSize: 14,
                    fontWeight: FontWeight.w600,
                    color: Colors.white,
                  ),
                ),
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.all(22),
            child: Column(
              children: [
                ...renderCustomers(context),
              ],
            ),
            decoration: BoxDecoration(
              border: Border(
                bottom: BorderSide(width: 1, color: HexColor('#D2D2D2')),
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.all(22),
            child: Column(
              children: [
                ...renderMenuItems(context, menuItems),
              ],
            ),
          ),
        ],
      );

}

这是我的渲染mwnu项目,

  renderMenuSubItems(BuildContext context) {
return selectedMenuItem.items.map(
  (item) => MaterialButton(
    onPressed: () {
      redirectItem(item);
    },
    padding: EdgeInsets.only(top: 5, bottom: 5),
    child: Row(
      children: [
        Text(
          item.title,
          style: TextStyle(fontSize: 14),
        ),
      ],
    ),
  ),
);

}

enter image description here

0 个答案:

没有答案