繁体   English   中英

抖动GridView导致Navigator.push错误

[英]flutter GridView causes Navigator.push error

我的Flutter应用程式有一个前往联络人页面的按钮。 当GridView仅具有一个floatButton时,它运行良好。 但是,当GridView具有多个floatButton时,它将出现错误。 请帮助解决此问题。

错误:

  • 颤抖:在调度程序回调期间引发了以下断言:
  • 颤动:子树中有多个共享相同标签的英雄。
  • 颤动:在每个要动画英雄的子树(通常是PageRoute子树)中,每个英雄
  • flutter:必须具有唯一的非null标签。
  • 扑:在这种情况下,多个英雄具有以下标签:
  • 扑:这是其中一个冒犯英雄的子树:
  • 扑:#英雄(标签:,状态:_HeroState#232b6)

在此处输入图片说明

class _DatabasePageState extends State<DatabasePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          backgroundColor: Colors.black,
          appBar: AppBar(
            title: Text('DB'),
            centerTitle: true,
            backgroundColor: Colors.black,
          ),
          body: _showOrderdatabase(),

        );
      }

      Widget _showOrderdatabase() {

        return Column(
          children: <Widget>[
            Container(
              height: 220.0,
              color: Colors.transparent,
              child: new Container(
                  padding: EdgeInsets.all(40.0),
                  decoration: new BoxDecoration(
                    color: Colors.green,
                    borderRadius: BorderRadius.all(const Radius.circular(40.0)),
                  ),
                  child: new Column(
                    children: <Widget>[
                      Text(
                        "vds",
                        style: TextStyle(fontSize: 16.0),
                      ),
                      IconButton(
                        icon: Icon(
                          Icons.email,
                          color: Colors.blueAccent,
                        ),
                        iconSize: 50.0,
                        onPressed: () => Navigator.push(context, MaterialPageRoute(builder: (c) => new ContactUs())),
                      ),
                    ],
                  )),
            ),
            Expanded(
              child: GridView.count(
                primary: false,
                padding: const EdgeInsets.all(20.0),
                crossAxisSpacing: 30.0,
                mainAxisSpacing: 30.0,
                crossAxisCount: 4,
                children: <Widget>[
                  FloatingActionButton(
                    onPressed: null,
                    backgroundColor: Colors.orange,
                    child: Text('今天'),
                    foregroundColor: Colors.black,
                  ),
                  FloatingActionButton(
                    onPressed: null,
                    backgroundColor: Colors.yellow,
                    child: Text('年'),
                    foregroundColor: Colors.black,
                  ),

                ],
              ),
            )
          ],
        );
      }
    }

FloatingActionButton具有heroTag属性,其默认值为const _DefaultHeroTag(), heroTag

由于您有两个FloatingActionButton ,因此应该为每个分配一个不同的标签:

   children: <Widget>[
      FloatingActionButton(
        onPressed: null,
        heroTag: 'Tag1',
        backgroundColor: Colors.orange,
        child: Text('今天'),
        foregroundColor: Colors.black,
      ),
      FloatingActionButton(
        onPressed: null,
        heroTag: 'Tag2',
        backgroundColor: Colors.yellow,
        child: Text('年'),
        foregroundColor: Colors.black,
      ),
    ],

或者,您可以将两者都设置为null这样就不会将Hero小部件添加到树中。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM