0

Dart as you can see in the below php code.i am trig to crater variable name "token" of **getTokenValue()and use into tokenaddSingleProduct(productInfo,token,callback)**int thi function as String but i can't use

Future <String> getTokenValue()async{
 final  SharedPreferences sharedPreferences=await SharedPreferences.getInstance();
 final String token=sharedPreferences.getString('token');
 print("accept token : ${token}");
  return token;
}
 final token= getTokenValue();

onPressed: (){
                  addSingleProduct(productInfo,token,callback);   //"token"  The argument type 'Future<String>' can't be assigned to the parameter type 'String'.
                },

1 Answers1

0

You have to await until you get the string value. So call the function inside button press call

onPressed: ()async{
    String token = await getTokenValue();
    addSingleProduct(productInfo,token,callback);
         }

Hope this fix your issue.

towhid
  • 2,778
  • 5
  • 18
  • 28