FilledStacks / flutter-tutorials

The repo contains the source code for all the tutorials on the FilledStacks Youtube channel.
MIT License
4.75k stars 1.76k forks source link

How to handle "Network Aware" for web too along with mobile? #100

Open pallavbohara opened 4 years ago

pallavbohara commented 4 years ago

Hello FilledStacks Team, I really love your tutorials. While following tutorial for network connectivity I found that connectivity plugin is not returning correct values for web I also tried to add connectivity_for_web. Although web is offline always. But I cannot setup for both in single code base. Please guide to do so.

Regards, Pallav Bohara

FilledStacks commented 4 years ago

Hi there,

In my experience there won't be much difference. what exactly are you struggling with setting up for both?

pallavbohara commented 4 years ago

Hello, Thanks for quick reply. Actually right now I am using connectivity: ^0.4.9+2 and it is returning "ConnectivityStatus.Offline" every time for web(which is I think wrong). And I think if we can check some where if it is web then just avoid connectivity check as web always will have connectivity.

FilledStacks commented 4 years ago

@pallavbohara sounds like an option. the constant kIsWeb tells you if it's running on web or not. You can use that for your logic.

pallavbohara commented 4 years ago

Hello, It is not working. I am trying like this(In reference to your 'NetWork Aware Code' in connectivity_servie.dart :

ConnectivityStatus _getStatusFromResult(ConnectivityResult result) { if (kIsWeb) { return ConnectivityStatus.Cellular; } switch (result) { case ConnectivityResult.mobile: return ConnectivityStatus.Cellular; break; case ConnectivityResult.wifi: return ConnectivityStatus.Wifi; break; case ConnectivityResult.none: return ConnectivityStatus.Offline; break; default: return ConnectivityStatus.Offline; } }

But It is always picking Offline code. I am attacing whole project zip in case you need.

network_sensitive (2).zip

pallavbohara commented 4 years ago

Hello, It is not working. I am trying like this(In reference to your 'NetWork Aware Code' in connectivity_servie.dart :

ConnectivityStatus _getStatusFromResult(ConnectivityResult result) { if (kIsWeb) { return ConnectivityStatus.Cellular; } switch (result) { case ConnectivityResult.mobile: return ConnectivityStatus.Cellular; break; case ConnectivityResult.wifi: return ConnectivityStatus.Wifi; break; case ConnectivityResult.none: return ConnectivityStatus.Offline; break; default: return ConnectivityStatus.Offline; } }

But It is always picking Offline code. I am attacing whole project zip in case you need.

network_sensitive (2).zip

Sorry, I have mistakenly created a new issue.

FilledStacks commented 4 years ago

That's the constant I used, maybe if changed. there's other ways to check for web as well. I don't have it on hand right now.