4

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,
 );
}
ישו אוהב אותך
29.9k11 gold badges83 silver badges98 bronze badges
asked Apr 2, 2021 at 11:38

2 Answers 2

12

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.

answered Apr 2, 2021 at 11:50
Sign up to request clarification or add additional context in comments.

Comments

2

Remove the const keyword before the Stack.children and provide datatype for the _Image and _ListOfInputs methods to Widget instead of dynamic.

Stack(
 fit: StackFit.passthrough,
 textDirection: TextDirection.ltr,
 children: [
 _Image(),
 _ListOfInputs(userNameNode: userNameNode),
]);
answered Apr 2, 2021 at 11:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.