Am getting this error when am setting the picked image, future dynamic is not a subtype of string.
This is how am setting the image
This is how am saving the image path using shared preferences

Where could I have gone wrong?
Am getting this error when am setting the picked image, future dynamic is not a subtype of string.
This is how am setting the image
This is how am saving the image path using shared preferences

Where could I have gone wrong?
that's because getImagePathFromSharedPreferences doesn't return String?, it returns a Future
you either handle the async task in the initState or use a FutureBuilder
make sure to set the return type of getImagePathFromSharedPreferences
Future<String?> getImagePathFromSharedPreferences() async {
// ...
}
I'm gonna use FutureBuilder:
FutureBuilder<String?>(
future: getImagePathFromSharedPreferences(),
initialData: null,
builder: (
BuildContext context,
AsyncSnapshot<String?> snapshot,
) {
if (snapshot.connectionState != ConnectionState.done) {
return const CircularProgressIndicator();
} else if (!snapshot.hasError) {
return CircleAvatar(
radius: 45.0,
backgroundImage: _imageFile != null
? Image.file(_imageFile).image
: snapshot.hasData
? FileImage(snapshot.data!)
: AssetImage(_imageUrl),
);
} else {
return const Text('Error');
}
},
),