flutter futurebuilder 中的 if 语句只接受 =
if statment in flutter future builder accept just =
FutureBuilder(
future: getData,
builder: (BuildContext, AsyncSnapshot snapshot) {
var sn = snapshot.data;
var tp1 = snapshot.data[0]["currentprice"];
var ent = snapshot.data[0]["entryprice"];
Color col = Colors.blue;
if (ent > tp1) {
col = Colors.red;
} else {
col = Colors.grey;
}
**if 语句仅适用于 = 调节器,当我使用 > keep 运行 这个错误
Class 'String' has no instance method '>'.
Receiver: "1"
Tried calling: >("1.25454")
**
ent
或 tp1
是字符串。请记住,>
运算符仅适用于双精度数和整数。因此,您可以做的是将该 String 解析为 double 或 int,然后继续执行其余操作。像这样:
double.parse(ent);
int.parse(tp1);
然后,它会工作得很好! :)
将您的 String
值转换为 double
FutureBuilder(
future: getData,
builder: (BuildContext, AsyncSnapshot snapshot) {
var sn = snapshot.data;
//convert your String to double
var tp1 = double.parse(snapshot.data[0]["currentprice"]);
var ent = double.parse(snapshot.data[0]["entryprice"]);
Color col = Colors.blue;
if (ent > tp1) {
col = Colors.red;
} else {
col = Colors.grey;
}
});
FutureBuilder(
future: getData,
builder: (BuildContext, AsyncSnapshot snapshot) {
var sn = snapshot.data;
var tp1 = snapshot.data[0]["currentprice"];
var ent = snapshot.data[0]["entryprice"];
Color col = Colors.blue;
if (ent > tp1) {
col = Colors.red;
} else {
col = Colors.grey;
}
**if 语句仅适用于 = 调节器,当我使用 > keep 运行 这个错误
Class 'String' has no instance method '>'. Receiver: "1" Tried calling: >("1.25454")
**
ent
或 tp1
是字符串。请记住,>
运算符仅适用于双精度数和整数。因此,您可以做的是将该 String 解析为 double 或 int,然后继续执行其余操作。像这样:
double.parse(ent);
int.parse(tp1);
然后,它会工作得很好! :)
将您的 String
值转换为 double
FutureBuilder(
future: getData,
builder: (BuildContext, AsyncSnapshot snapshot) {
var sn = snapshot.data;
//convert your String to double
var tp1 = double.parse(snapshot.data[0]["currentprice"]);
var ent = double.parse(snapshot.data[0]["entryprice"]);
Color col = Colors.blue;
if (ent > tp1) {
col = Colors.red;
} else {
col = Colors.grey;
}
});