Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the `Arguments of a constant creation must be constant expressions` in dart?

Tags:

flutter

dart

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'),
              ],
            )),

enter image description here

like image 251
DNB5brims Avatar asked Apr 20 '18 14:04

DNB5brims


1 Answers

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.

like image 109
Ian Avatar answered Oct 21 '22 18:10

Ian