問題描述
Flutter:如何在沒有評級動作的情況下實現評級欄 (Flutter : How to implement rating bar without rating action)
我有一些產品,每個產品都有他的評分值(如 4.2 、 4 、 3.5 等),我想用評分欄顯示這些值
這是我這部分的代碼
Align(
alignment:Alignment.topLeft,
child:SmoothStarRating(
allowHalfRating:false,
starCount:5,
rating: adminAcceptStatusAdd[index]['rate'].toDouble(),
size: 20.0,
isReadOnly:false,
color: Colors.yellow,
borderColor:Colors.yellow,
filledIconData:Icons.star,
halfFilledIconData:Icons.star_half,
defaultIconData:Icons.star_border,
spacing: .5,
),
)
現在我有兩個問題,第一個是評分欄允許用戶更改價值率,所以我想讓它只是為了顯示,第二個問題我無法將 api 的值從字符串轉換為我正在嘗試的雙精度值
adminAcceptStatusAdd[index]['rate'].toDouble()
但它不起作用所以任何人都可以幫助我!
p>參考解法
方法 1:
For parse double from string:
double.parse(adminAcceptStatusAdd[index]['rate'])
(by Mariam Younes、Alberto Sáez Vela)