有人可以指出我為什么會遇到這個問題以及如何解決它?
在終端我收到這條訊息:
我真的不知道為什么會出現此錯誤:我使用了“?” 空安全符號,但我仍然不斷指出相同的錯誤
error: Too many positional arguments: 0 expected, but 9 found. (extra_positional_arguments_could_be_named at [bankingapp] lib\model\card_model.dart:29)

import 'package:flutter/material.dart';
import 'package:bankingapp/constants/color_constant.dart';
class CardModel {
String? name;
String? type;
String? balance;
String? valid;
String? moreIcon;
String? cardBackground;
Color? bgColor;
Color? firstColor;
Color? secondColor;
CardModel(
{this.name,
this.type,
this.balance,
this.valid,
this.moreIcon,
this.cardBackground,
this.bgColor,
this.firstColor,
this.secondColor});
}
List<CardModel> cards = cardData
.map((item) => CardModel(
item['name'], // <-- Line 29: error occurs here
item['type'],
item['balance'],
item['valid'],
item['moreIcon'],
item['cardBackground'],
item['bgColor'],
item['firstColor'],
item['secondColor']))
.toList();
uj5u.com熱心網友回復:
您使用了命名引數,但我認為您需要在將地圖隱藏到串列時使用引數
class CardModel {
String? name;
String? type;
String? balance;
String? valid;
String? moreIcon;
String? cardBackground;
Color? bgColor;
Color? firstColor;
Color? secondColor;
CardModel(
{this.name,
this.type,
this.balance,
this.valid,
this.moreIcon,
this.cardBackground,
this.bgColor,
this.firstColor,
this.secondColor});
}
List<CardModel> cards = cardData
.map((item) => CardModel( // here need to change
name: item['name'],
type: item['type'],
balance: item['balance'],
valid: item['valid'],
moreIcon: item['moreIcon'],
cardBackground:item['cardBackground'],
bgColor: item['bgColor'],
firstColor:item['firstColor'],
secondColor:item['secondColor']))
.toList();
uj5u.com熱心網友回復:
您使用了命名引數,因此您需要在宣告類時對其進行命名。命名引數不是必需的,因此您不需要使用它們。這就是錯誤的原因(預期為 0 個引數,因為它們都不是必需的)。
所以解決方案應該是:從建構式中洗掉{},使引數成為強制性的或使用代碼:
class CardModel {
String? name;
String? type;
String? balance;
String? valid;
String? moreIcon;
String? cardBackground;
Color? bgColor;
Color? firstColor;
Color? secondColor;
CardModel(
{this.name,
this.type,
this.balance,
this.valid,
this.moreIcon,
this.cardBackground,
this.bgColor,
this.firstColor,
this.secondColor});
}
List<CardModel> cards = cardData
.map((item) => CardModel(
name: item['name'], // <-- Line 29: error occurs here
type: item['type'],
balance: item['balance'],
valid: item['valid'],
moreIcon: item['moreIcon'],
cardBackground: item['cardBackground'],
bgColor: item['bgColor'],
firstColor: item['firstColor'],
secondColor: item['secondColor']))
.toList();
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/408813.html
標籤:
上一篇:Dart中的列舉有比較運算子嗎?
