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.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
import 'package:go_router/go_router.dart';
import 'package:internet_availability/internet_availability.dart';

final GoRouter router = GoRouter(
  routes: [
    GoRoute(
      path: '/',
      builder: (context, state) => const Page1(),
    ),
    GoRoute(
      path: NoInternetPage.routeName,
      builder: (context, state) => const NoInternetPage(),
    ),
  ],
  redirect: (context, state) {
    switch (InternetAvailabilityConfig.showNoInternetPage()) {
      case true:
        InternetAvailabilityConfig.prevRoute = state.subloc;
        return NoInternetPage.routeName;
      case false:
        return InternetAvailabilityConfig.prevRoute;
      default:
        return null;
    }
  },
  refreshListenable: RefreshStream(
      InternetAvailabilityConfig.internetAvailabilityCubit.stream),
);

void main() {
  usePathUrlStrategy();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      routerConfig: router,
    );
  }
}

class Page1 extends StatelessWidget {
  static const String routeName = '/';
  const Page1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
        body: Center(
      child: Text('Page 1'),
    ));
  }
}
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