Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to enter variable to SliverAppBar title value

I have an application. I’ve added a page to my app and that page will have product information. I was also able to redirect to the page and show the information on that page. I want to put the name of the product in the title value of the SliverAppBar. The product name is written in the productName variable.

But I can’t enter a variable in the SliverAppBar‘s title value. When trying to login I get this error:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Evaluation of this constant expression throws an exception.dart(const_eval_throws_exception)

A value of type 'Null' can't be assigned to a parameter of type 'String' in a const constructor.
Try using a subtype, or removing the keyword 'const'.dartconst_constructor_param_type_mismatch

Avoid using braces in interpolation when not needed.dartunnecessary_brace_in_string_interps

Invalid constant value.

Codes:

child: CustomScrollView(
  slivers: <Widget>[
    const SliverAppBar(
      pinned: true,
      expandedHeight: 250.0,
      flexibleSpace: FlexibleSpaceBar(
        title: Text("Product ${productName}"),
      ),
    ),
  // ...

How can I solve this problem? Thanks in advance for your help.

>Solution :

Just remove the const keyword in front of SliverAppBar widget

 SliverAppBar(
      pinned: true,
      expandedHeight: 250.0,
      flexibleSpace: FlexibleSpaceBar(
        title: Text("Product ${productName}"),
      ),
    ),
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading