我在有状态小部件中使用银行列表。将列表传递给pageState
使用 List<Bank> bankLists = this.widget.bankLists;
问题 1.为什么gradientcolor: gradientBankCard("FFB74093","FFB74093"))
在初始化程序中只能访问静态成员时出现错误?
Que 2.如何将 const Data 传递给gradientBankCard
method 。例如,我想传递Color.fromRGBO(220, 132, 58, 1.0)
给错误的参数。一世
List<Bank> bankLists = [
Bank(
id: "1",
name: "B1",
loanAmount: "₹ 250000",
emi: "₹11732",
intrest_rate: "11.69 % ",
processing_fee: "1.29 %",
tenure: "2 years",
gradientcolor: gradientBankCard('#e48634', '#e48634')), // //Error : Only static members can be accessed in initializers
Bank(
id: "2",
name: "B2",
loanAmount: "₹ 250000",
emi: "₹11732",
intrest_rate: "11.69 % ",
processing_fee: "1.29 %",
tenure: "2 years",
gradientcolor: gradientBankCard('#e48634', '#e48634')) //Error : Only static members can be accessed in initializers
];
现在我在我的列表屏幕中使用。
LinearGradient gradientBankCard(String startColor, String endColor){
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(hexToInt(startColor)),Color(hexToInt(endColor))]
);
}
银行模型.dart
import 'package:flutter/material.dart';
class Bank {
final String id;
final String name;
final String loanAmount;
final String emi;
final String intrest_rate;
final String processing_fee;
final String tenure;
LinearGradient gradientcolor;
Bank({this.id, this.name, this.loanAmount, this.emi, this.intrest_rate,
this.processing_fee, this.tenure,this.gradientcolor});
}