Do Flutter have InternetAddress.lookup packages or similar?

196 views
Skip to first unread message

Niyazi Toros

unread,
Jun 13, 2018, 3:10:43 AM6/13/18
to Flutter Dev
Hi,

In my app I use connectivity packages (connectivity: (import 'package:connectivity/connectivity.dart';)) in initState() and its works perfectly.
If the connectivity = false; I have very simple scaffold, that gives warning to user. When user turns on mobile connection or wifi without living app original app scaffold builds perfectly. 

Now before I build my original scaffold while connection is on I need to check the server and work for it. If the server is dead I need to warn user again using InternetAddress.lookup as shown below.

final result = await InternetAddress.lookup('8.8.8.8');

My question is that, Do Flutter have InternetAddress.lookup packages or similar 
to connectivity?

In below code I need to use something like appLive = 2; so I can give user a another warning that currently we are in maintenance mode.



CODE:


// TODO: 4) _MyHomePageState Class

class _MyHomePageState extends State<MyHomePage> {

  var _connectionStatus = 'Unknown';

  Connectivity connectivity;

  StreamSubscription<ConnectivityResult> subscription;


  @override

  void initState() {

    // TODO: implement initState

    super.initState();

    connectivity = new Connectivity();

   subscription =

        connectivity.onConnectivityChanged.listen((ConnectivityResult result) {

      _connectionStatus = result.toString();

      if (result == ConnectivityResult.wifi ||

          result == ConnectivityResult.mobile) {

        setState(() {

          appLive = 1;

        });

      } else {

        setState(() {

          appLive = 0;

        });

      }

    });

  }


  @override

  void dispose() {

    subscription.cancel();

    super.dispose();

  }


  // TODO: BUILD WIDGET

  @override

  Widget build(BuildContext context) {

    if (appLive == 0) {

      return new Scaffold(

          backgroundColor: darkMainGreen,

          body: new Center(

           ......

           // WARN USER

           ......

          )

      );

    } else {

            return new Scaffold(

          backgroundColor: darkMainGreen,

          body: new Center(

           ......

           // SHOW ORIGINAL APPP

           ......

          )

      );

    }

  } // build Widget


} // _MyHomePageState Class



Reply all
Reply to author
Forward
0 new messages