I Created CircularPercentIndicator Inside my code and I Stored The Percent value in ShardPreference and I use FutureBuilder to Fetch The percent value from SharedPreference Like the Below code but I get The Error The argument type 'FutureBuilder' can't be assigned to the parameter type 'double'
CircularPercentIndicator(
radius: 30.0,
lineWidth: 10,
progressColor: Colors.white,
backgroundColor: Colors.grey,
percent: FutureBuilder(
future: getPercentValue("index1"),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData && snapshot.data != null) {
return snapshot.data;} else {
return CircularProgressIndicator(); }
}),),
//here is my Method to Fetch the Percent Value from SharedPreference
Future<double> getPercentValue(String key)async{
SharedPreferences sharedPreferences=await SharedPreferences.getInstance();
double storedvalue= await sharedPreferences.getDouble(key)??0.0;
return storedvalue;
}
CodePudding user response:
You need to swap the CircularPercentIndicator and the FutureBuilder. the percent
parameter needs a double but you provide the FutureBuilder. So do it like this:
FutureBuilder(
future: getPercentValue("index1"),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData && snapshot.data != null) {
return CircularPercentIndicator(
radius: 30.0,
lineWidth: 10,
progressColor: Colors.white,
backgroundColor: Colors.grey,
percent: snapshot.data);
} else {
return CircularProgressIndicator();
}
}),