Flutter Internet Connetion

Mobile Apps Development A-Z Guide.

Volodymyr Babenko
Pharos Production
3 min readApr 1, 2019

--

Give us a message if you’re interested in Blockchain and FinTech software development or just say Hi at Pharos Production Inc.

Or follow us on Youtube to know more about Software Architecture, Distributed Systems, Blockchain, High-load Systems, Microservices, and Enterprise Design Patterns.

Pharos Production Youtube channel

The vast majority of mobile applications are very dependent on internet connection. However, if the network is absent under any conditions, then the user should receive information according to the current state of the network. Namely, either the cached data or the message about the disconnection.

In this article, I would like to use a practical example to show how to get information about a connection and how to track it. Material for the article is taken from the official Flutter repository. So, let’s begin!

Step 1. Create a new Flutter project and add to pubspec.yaml next dependency:

And then you need to run the next command in terminal:

Step2. Create a ConnectionPage widget:

Step3. Add the following local variables to the _ConnectionPageState class:

We also display the connection status in the Text widget in the center of the screen:

Step4. We describe a function that will take on the input of a ConnectResult, analyze and save the state accordingly:

Step5. Next, to determine the state of the network at the time of launching the page it’s necessary to use the next function:

Step 6. In order to receive up-to-date information on network status changes, we need to add a listener to the state change event:

Application example.

An example of code you can find on the link below:

Thanks for reading.

--

--