Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The values in a const list literal must be constants

Tags:

flutter

dart

I am trying to create a FocusNode to list of texts but I fault to do so.

The userNameNode is:

 final FocusNode userNameNode =FocusNode();

The usage of userNameNode which caused the error:

Stack(
     fit: StackFit.passthrough,
      textDirection: TextDirection.ltr,
      children: const [
        _Image(),
        _ListOfInputs(
          userNameNode:  userNameNode,
)]);

The error of userNameNode is:

The values in a const list literal must be constants.
Try removing the keyword 'const' from the list literal.dart(non_constant_list_element)
The element type 'dynamic' can't be assigned to the list type 'Widget'.

The _ListOfInputs class is:

class _ListOfInputs extends StatelessWidget {
      final FocusNode userNameNode;
      const ListOfInputs(
        this.userNameNode,
      );
}

1 Answers

your code is:

Stack(
      fit: StackFit.passthrough,
      textDirection: TextDirection.ltr,
      children: const [
                _ListOfInputs(userNameNode:  userNameNode,)]);

so change it:

Stack(
      fit: StackFit.passthrough,
      textDirection: TextDirection.ltr,
      children: [
               _ListOfInputs(userNameNode:  userNameNode,)]);

because the list is not const.

like image 137
Qasim Avatar answered Sep 07 '25 22:09

Qasim