[英]The values in a const list literal must be constants
我正在嘗試為文本列表創建一個FocusNode
,但我沒有這樣做。
用戶名節點是:
final FocusNode userNameNode =FocusNode();
導致錯誤的 userNameNode 的用法:
Stack(
fit: StackFit.passthrough,
textDirection: TextDirection.ltr,
children: const [
_Image(),
_ListOfInputs(
userNameNode: userNameNode,
)]);
userNameNode 的錯誤是:
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'.
_ListOfInputs class 是:
class _ListOfInputs extends StatelessWidget {
final FocusNode userNameNode;
const ListOfInputs(
this.userNameNode,
);
}
刪除 Stack.children 之前的 const 關鍵字,並將_Image
和_ListOfInputs
方法的數據類型提供給 Widget 而不是動態的。
Stack(
fit: StackFit.passthrough,
textDirection: TextDirection.ltr,
children: [
_Image(),
_ListOfInputs(userNameNode: userNameNode),
]);
你的代碼是:
Stack(
fit: StackFit.passthrough,
textDirection: TextDirection.ltr,
children: const [
_ListOfInputs(userNameNode: userNameNode,)]);
所以改變它:
Stack(
fit: StackFit.passthrough,
textDirection: TextDirection.ltr,
children: [
_ListOfInputs(userNameNode: userNameNode,)]);
因為列表不是常量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.