mchome / flutter_advanced_networkimage

flutter advanced network image provider
https://pub.dev/packages/flutter_advanced_networkimage
MIT License
285 stars 180 forks source link

Occasional exception when trying to load a bad URL #68

Closed davbaron closed 5 years ago

davbaron commented 5 years ago

I am using AdvancedNetworkImage to load image URLs for 'people' in a ListView. Each image shows up in a CircleAvatar. I can reliably reproduce a fault which throws an exception, resulting in a 'blank' CircleAvatar (the fallbackAssetImage does not get displayed). The pattern seems to be as follows:

  1. I have 20 items in my ListView
  2. I can only see the first 10 upon loading the page.
  3. There is a 'bad URL' in item #15. #15 does NOT seem to be 'loaded' when the screen first is displayed.
  4. If I scroll the ListView so that #15 begins to come into view, the 'loadFromRemote' code executes and faults out within the _response = await run(() async { block, specifically when the subscription is trying to listen to incoming bytes. image

If you notice in the code, I have hovered the mouse over the url value, and its properties window is displayed. If I read this right, it's value appears to be '.' I had set a breakpoint higher up in the code, and the incoming url value to loadFromRemote does contain the full url.

In any case, even though the code is executed within a try-catch block, the code performs an if-then and decides to throw and exception, and thus does not continue on, looking for a fallbackImage...

I cannot explain how or why the url value is a simple 'dot'.

This only seems to happen on a 'full' start (from stop), or a 'Hot Restart', but not from a regular 'Restart' or even from a manual 'reload of the list' instigated by end-user input. Once the exception has occurred (and I have run past it), the user can manually reload the ListView and all works well, even with the 'hidden' CircleAvatar coming into view again.

Please let me know if this is something you can reproduce, and if not I will try to build an example app.

Thank you!

mchome commented 5 years ago

HI, i can't reproduce this, an example would be super useful.

davbaron commented 5 years ago

I tried to reproduce this in a new project. Similar functionality did NOT reproduce the error. I went back to my true project and just happened to notice that the 'Breakpoints on All Exceptions' was checked. Upon unchecking the option I see no further runtime issues! I then went back into the new project and checked that option just to see what happens, and sure enough the exception is thrown! When I uncheck the box, all is well again.

I will leave this to you to decide whether to close this or not. Clearly with a 'bad URL' the response must be 'bad' (404 for example) - I'm just not sure you want to be throwing the Exception or not.

Thank you again!

mchome commented 5 years ago

That exception is expected, i can close this and make a new release.