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
user15405245
2 Answers 2
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.
Sign up to request clarification or add additional context in comments.
Comments
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
Ashok Kuvaraja
7264 silver badges12 bronze badges
Comments
lang-dart