fluttercommunity / community

Flutter Community - A central place for community made Flutter content.
1.56k stars 121 forks source link

Detect 2G / 3G / 4G whereas Wifi is connected [ConnectivityPlus] #116

Open ChristopheLyonnaz opened 1 year ago

ChristopheLyonnaz commented 1 year ago

Discussion: [ConnectivityPlus for Flutter]

This issue has been made to discuss [ConnectivityPlus package for Flutter] and is asking for help to detect if 2G/3G/4G/5G network is available whereas the device is connected to Wifi.

Summary

I develop a Flutter application that needs to select the most valuable network between a Wifi modem and the mobile data network (4G). In my specific case, let's say that using the Wifi is far more expensive than using 4G.

However, by default, whenever you have Wifi access, the smartphone connects on Wifi and get rid of 4G network. My needs is to be able to check of 4G network may be available whereas I am connected to Wifi. How can I achieve such a check ?

Thank you for your valuable help, Christophe.

tuceturan commented 1 year ago

Hello,

You can check NetworkInterfaces

    List<NetworkInterface> interfaces = await NetworkInterface.list(
        includeLoopback: true, includeLinkLocal: true);

    for (int i = 0; i < interfaces.length; i++) {
      if (interfaces[i].name == "eth0") ethernet = true;
    }

I need It has a ethernet connection I use that and I want to change default connection But I can see just connecting networks not change default connection