无法将变量输入到 SliverAppBar 标题值

Unable to enter variable to SliverAppBar title value

我有申请。我在我的应用程序中添加了一个页面,该页面将包含产品信息。我还能够重定向到该页面并在该页面上显示信息。我想把产品名称放在 SliverAppBar 的标题值中。产品名称写在productName变量中。

但我无法在 SliverAppBartitle 值中输入变量。尝试登录时出现此错误:

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.

代码:

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

我该如何解决这个问题?预先感谢您的帮助。

只需删除 SliverAppBar 小部件前面的 const 关键字

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