zeba_academy_connectivity_manager
A lightweight Flutter connectivity management toolkit designed for apps that must work reliably even with unstable or intermittent internet connections.
zeba_academy_connectivity_manager helps developers detect network status changes, queue offline API requests, retry failed calls with automatic backoff, and manage WebSocket connections โ all in one simple package.
โจ Features
- ๐ก Network Status Detection โ Listen to realโtime connectivity changes.
- ๐ด Offline Request Queue โ Automatically queue API calls when the device is offline.
- ๐ Automatic Retry System โ Retry failed requests with configurable backoff.
- ๐ REST API Support โ Works seamlessly with HTTP requests.
- ๐ WebSocket Support โ Manage WebSocket connections and messages.
- ๐ง Connection Event Listeners โ React to online/offline changes in real time.
- โก Lightweight & Fast โ No unnecessary complexity or heavy dependencies.
๐ฆ Installation
Add the package to your pubspec.yaml:
dependencies:
zeba_academy_connectivity_manager: ^1.0.0
Then run:
flutter pub get
๐ Getting Started
Import the package:
import 'package:zeba_academy_connectivity_manager/zeba_academy_connectivity_manager.dart';
๐ก Detect Connectivity Changes
final connectivity = ConnectivityService();
connectivity.onStatusChange.listen((event) {
if (event.status == ConnectivityStatus.online) {
print("Device is online");
} else {
print("Device is offline");
}
});
๐ด Queue Requests When Offline
final queue = RequestQueue();
await queue.add(() async {
print("Executing queued request");
});
Requests added to the queue will execute sequentially.
๐ Retry Failed Requests
final retryManager = RetryManager();
final result = await retryManager.retry(() async {
// Your API call
return "Success";
});
print(result);
The retry manager automatically retries failed requests using a backoff delay.
๐ REST API Example
import 'package:http/http.dart' as http;
final connectivity = ConnectivityService();
final queue = RequestQueue();
final retry = RetryManager();
Future fetchData() async {
final online = await connectivity.isOnline();
if (!online) {
queue.add(() => fetchData());
return;
}
return retry.retry(() async {
final response = await http.get(
Uri.parse("https://jsonplaceholder.typicode.com/posts"),
);
return response.body;
});
}
๐ WebSocket Support
final socket = WebSocketManager();
socket.connect("wss://echo.websocket.events");
socket.messages.listen((message) {
print("Received: $message");
});
socket.send("Hello Server");
๐ Use Cases
This package is ideal for apps that require reliable connectivity handling:
- Offlineโfirst applications
- Messaging apps
- Delivery or rideโsharing apps
- Field service apps
- Data sync systems
- IoT dashboards
๐งช Testing
Run tests using:
flutter test
Analyze the package:
flutter analyze
๐ Package Structure
lib/
โโโ zeba_academy_connectivity_manager.dart
โโโ src/
โโโ connectivity_service.dart
โโโ request_queue.dart
โโโ retry_manager.dart
โโโ websocket_manager.dart
โโโ connectivity_event.dart
๐ฎ Planned Improvements
Future versions may include:
- Persistent offline queue (Hive/SQLite)
- Background synchronization
- Network quality detection
- Smart caching
- Automatic token refresh handling
๐ค Contributing
Contributions, bug reports, and feature requests are welcome!
If you would like to contribute, please open an issue or submit a pull request.
๐ License
This project is licensed under the GPL-3.0 License.
About Me
โจ Iโm Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects. You can learn more about me and my work at sufyanism.com or connect with me on Linkedin
Your all-in-one no-bloat hub!
๐ Explore cutting-edge resources in coding, tech, and development at zeba.academy and code.zeba.academy. Empower yourself with practical skills through curated directives, real-world projects, and hands-on experience. Level up your tech game today! ๐ปโจ
Zeba Academy is a learning platform dedicated to coding, technology, and development.
โก Visit our main site: zeba.academy
โก Explore hands-on courses and resources at: code.zeba.academy
โก Check out our YouTube for more tutorials: zeba.academy
โก Follow us on Instagram: zeba.academy
Thank you for visiting!