
wdym?

snapshot is of type object

snapshot is basically
AsyncSnapshot<YOUR_TYPE> snapshot
no snapshot.data
would return the data of the type you have passed
and snapshot.error
would give back the exception it had during calling of the function

now the error could be of any type. In your case , it should be object or dynamic

where/how would i write checks for that there is no property error in my snapshot object

nvm figured out

@Maniac_Fighter after writing checks inside the builder the exception is still being thrown

problem comes before the builder can read the checks

can you share your futurebuilder code ??

where snapshot is the getfie(index) passed down from widget

it doesnt even matter the exception is thrown before the code is called

so it should show in the stackTrace where the exception is being thrown right?

yeah shown under debug vars too



Also let's try to refactor this as well,
getFile must be Future<Uint8List>
Also , it needs async
await
Avoid using then, if you want the result, try storing it in a variable then print it
Now when you get the error, or when it reaches the catch block, its necessary, to either return a type of Uint8List
or throw an exception
so instead of return forceError, use throw
or rethrow
Now your future builder would be able to catch it

in the stack trace, could you see the who is calling that function??

already tried async await until i realised futurebuilder expects of type Future<Object?>? and not Future<Uint8List>

FutureBuilder accepts any type you just need to define it explicitly

FutureBuilder<T>

if not types given, then it considers an object automatically

ill see what i can do thank you for your patience

i fixed it, for some reason it wouldnt use throw and rethrow so i made the types nullable and returned null at the cost of not being able to use the error property

If it works don't touch it

[SOLVED] Catching errors with futurebuilders during api calls
Recommended threads
- Flutter OAuth2 Google does not return to...
When the flow starts, the browser opens, I select an account, and it keeps showing: """ Page not found The page you're looking for doesn't exist. `general_rout...
- Redirect URL sends HTTP instead of HTTPS...
I am not sure since when this issue is present, but my Google and Apple redirect URI are no longer pointing to the HTTPS redirect URI when I try to use OAuth. ...
- Failing to run document operations on sd...
Could someone point me in the right direction I'm going in cirlces. I have a problem with sdks and my self-hosted server in production (for ~3 years) I have bee...
