What is the `Arguments of a constant creation must

2019-07-22 12:30发布

问题:

I don't know why the dart compiler shows me an error in my code. What is that actually means? Thanks.

Source:

          const SliverAppBar(
        pinned: true,
        expandedHeight: 300.0, // TODO: check out later
        flexibleSpace: FlexibleSpaceBar(
            title: new Column(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Text('_SliverAppBar'),
                Text('subtitle'),
              ],
            ),
            background: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text('Info'),
              ],
            )),

回答1:

I have commented the original answer that lead to that problem. But here is why:

As @aziza pointed, you have instantiated your SliverAppBar with the const keyword. Therefore, all properties should be instantiated with const.

In your case, just changing from new Column to const Column would solve the problem, but, dart 2 can infer how it will instantiate the class. Just omit the new and const keywords, and let dart do the work.



标签: dart flutter