Example for bloc_connectivity
This example demonstrates the usage of the NetworkChecker
widget from the bloc_connectivity
package.
Getting Started
- Install the package by adding it to your
pubspec.yaml
file:
dependencies:
bloc_connectivity: ^1.0.0
- Import the package in your Dart code:
import 'package:bloc_connectivity/bloc_connectivity.dart';
Use the NetworkChecker widget to handle network connectivity in your app:
dart
Copy code
import 'package:flutter/material.dart';
import 'package:bloc_connectivity/bloc_connectivity.dart';
void main() {
runApp(
NetworkChecker(
child: MyApp(),
networkOffDialog: AlertDialog(
title: Text('Network Offline'),
content: Text('Please check your internet connection.'),
actions: [
TextButton(
onPressed: () {
// Handle retry action
},
child: Text('Retry'),
),
],
),
),
);
}
// ... rest of your code ...
- Feel free to adjust the structure based on your preferences and the complexity of your documentation and example.
Libraries
- bloc_connectivity
- A Flutter package that provides a
NetworkChecker
widget to handle network connectivity in your app. - main
- network_checker
- networking/bloc/network_connectivity_bloc
- networking/bloc/network_connectivity_event
- networking/bloc/network_connectivity_state