internet_availability 0.0.5 copy "internet_availability: ^0.0.5" to clipboard
internet_availability: ^0.0.5 copied to clipboard

A flutter package which check for internet availability and push a new page on top of the current route if internet is not available.

Internet Availability #

A Flutter package which check the internet availability and push a new page on top of the current route if internet is not available. Once the internet is available that page will automatically pop to previous route.

Note: The package will only work with go_router

Features #

example.gif

Getting started #

flutter pub add internet_availability
flutter pub get

Usage #

  • In your routes list add one more route
GoRoute(
      path: NoInternetPage.routeName,
      builder: (context, state) => const NoInternetPage(),
    ),

The route should not be a nested route. You can provide any value to path property and even your own Widget to builder property.

  • add redirect and refreshListenable property of GoRouter and paste below code
redirect: (context, state) {
    switch (InternetAvailabilityConfig.showNoInternetPage()) {
      case true:
        InternetAvailabilityConfig.prevRoute = state.subloc;
        return NoInternetPage.routeName; //page route path
      case false:
        return InternetAvailabilityConfig.prevRoute;
      default:
        return null;
    }
  },
refreshListenable: RefreshStream(
      InternetAvailabilityConfig.internetAvailabilityCubit.stream),

Note: For go_router version lower than 5.0 use GoRouterRefreshStream and redirect will only take state as an argument.

refreshListenable: GoRouterRefreshStream(
      InternetAvailabilityConfig.internetAvailabilityCubit.stream),

Additional Information #

check the example repository of the project for complete code.

12
likes
130
points
52
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter package which check for internet availability and push a new page on top of the current route if internet is not available.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, flutter, flutter_bloc, freezed_annotation, go_router

More

Packages that depend on internet_availability