Flutter:如何在沒有評級動作的情況下實現評級欄 (Flutter : How to implement rating bar without rating action)


問題描述

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 YounesAlberto Sáez Vela)

參考文件

  1. Flutter : How to implement rating bar without rating action (CC BY‑SA 2.5/3.0/4.0)

#dart #Flutter #ratingbar






相關問題

如何將數據傳遞給有狀態的小部件 (How to pass data to stateful widget)

顫振無線電值在步進器中沒有改變 (Flutter Radio Value not Changing in Stepper)

如何在顫動中製作響應式播放按鈕? (How to make a responsive play button in flutter?)

如何將數據數組轉換為在顫振/飛鏢中展開或折疊的小部件列表? (How to convert an array of data to a list of widgets with expand or fold in flutter/dart?)

Flutter - 迭代異步/未來列表 (Flutter - iterate over an asynchrous/future list)

使用顫振將圖像作為blob存儲在mysql數據庫中 (Storing image's as blob in mysql database with flutter)

如何在顫動中將視頻播放器浮動在 youtube 等所有頁面上? (How to float a video player over all pages like youtube in flutter?)

無法設置回調函數。錯誤說:“DropDown”必須有一個方法體,因為“ListLayout”不是抽象的 (Unable to set callback function . Error Says: 'DropDown' must have a method body because 'ListLayout' isn't abstract)

Flutter:如何在沒有評級動作的情況下實現評級欄 (Flutter : How to implement rating bar without rating action)

設置狀態內存洩漏 (set state memory leak)

Flutter 視頻播放器不接受自簽名 https 連接 (Flutter video player wont accept self signed https connection)

為什麼有時上下文被替換為下劃線或“_”? (Why sometimes context is being replace as underscore or "_"?)







留言討論