Orientação gerada a partir de informações públicas. Apenas para referência.
Um pacote leve e puro em Dart projetado para verificar rapidamente e com confiabilidade a conectividade à internet em múltiplas plataformas. Ele oferece tempos de resposta subsegundos, tornando-o ideal para aplicações em tempo real que precisam de feedback imediato sobre o status da rede. O pacote funciona sem problemas no Android, iOS, Web, macOS, Windows e Linux, oferecendo um comportamento consistente independentemente do ambiente. Desenvolvido com foco em desempenho e simplicidade, fornece uma API direta para detectar estados online ou offline sem depender de código específico da plataforma.
Casos de uso
Monitoramento de status em tempo real do aplicativo
Detecção de modo offline
Verificações de saúde da rede durante o login
Atualizações dinâmicas da interface com base na conectividade
Poling de conectividade em segundo plano
Principais recursos
Tempos de resposta subsegundo
Compatibilidade multiplataforma
Implementação pura em Dart
API simples e intuitiva
Baixo uso de recursos
Sem dependências nativas
Indicado para
Aplicativos que exigem verificações rápidas de rede
Desenvolvedores procurando soluções leves
Projetos direcionados para múltiplas plataformas
Interfaces de usuário em tempo real ou reativas
Aplicações que precisam de detecção off-line confiável
Considerações
Não lida com diagnósticos de rede complexos
Depende de testes básicos de acessibilidade
Pode exigir lógica adicional para casos extremos
Não adequado para análise avançada de rede
Limitado ao status de conexão, não à largura de banda ou qualidade
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
🧠 Created by the developer of Brink: Psychological Warfare
"Can you find the sweet spot between bold and delusional?"
Support the maintenance of this package by checking out my latest indie
game!
Internet Connection Checker Plus
An enterprise-grade network connectivity monitor for Dart and Flutter.
Standard network interfaces can verify local connections (like Wi-Fi router
connectivity) but cannot guarantee actual internet reachability. This package
proactively verifies external routing by checking reachability and response
statuses against highly available global endpoints.
[!NOTE]
🚀 v3 is now available! It removes the connectivity_plus dependency to
make this a pure Dart package. Please read the
v3 Migration Guide to understand the breaking changes and
how to update your project.
Features
Accurate Verification: Verifies real internet access instead of local
network status.
High Performance: Designed for subsecond response times.
Real-Time Monitoring: Stream-based API for immediate connectivity status
updates.
Extensible Architecture: Define custom endpoints, validation criteria, and
networking clients.
Universal Compatibility: Natively supports both pure Dart environments and
Flutter applications.
Permissions (Flutter)
When using this package in a Flutter application, ensure you have the
appropriate network permissions enabled for your target platforms.
final subscription = InternetConnection().onStatusChange.listen(
(InternetStatus status) {
if (status == InternetStatus.connected) {
// Connection established
} else {
// Connection lost
}
},
);
// Cancel the subscription when it is no longer needed to prevent memory leaks
subscription.cancel();
💝 Support the Project
If this package saved you from the eternal torment of "No Internet Connection"
errors, consider buying me a coffee! ☕
Advanced Configuration
Custom Endpoints and Validation
Override the default validation endpoints and acceptable HTTP status codes.
[!IMPORTANT]
Ensure your custom endpoints have no caching and aren't CORS blocked if you
intend to use them on the Web platform.
If you create custom instances of InternetConnection using createInstance(),
you should proactively free up resources when the instance is no longer needed
to prevent memory leaks (e.g., lingering timers and unclosed stream
controllers).
final customConnection = InternetConnection.createInstance();
// When done with the instance:await customConnection.dispose();
[!WARNING]
Never call dispose() on the global singleton (InternetConnection()).
The singleton is designed to live throughout the entire lifecycle of your
application. Disposing of it will permanently close its internal streams and
break any other parts of your app that rely on it.
Custom HTTP Client Implementation
Integrate existing networking clients (like dio) to maintain consistent
configurations across your application.
Use enableStrictCheck only with custom-defined URIs, not with the default
ones.
Using it with the default URIs may lead to unreliable results or service
outages, as all default endpoints must be up and reachable for a positive
result.
Pause and Resume on App Lifecycle Changes (Flutter)
For situations where you want to pause any network requests when the app goes
into the background and resume them when the app comes back into the foreground,
use AppLifecycleListener.
Because this package uses a broadcast stream, which buffers events, you should
cancel the subscription when paused and create a new one when resuming to avoid
receiving stale events (see issue #105):
If you are building a package, plugin, or library that depends on
internet_connection_checker_plus, do not use the singleton instance
(InternetConnection()).
If your package alters the singleton's configuration or accidentally calls
dispose() on it, you will introduce side effects that break the host
application using your package. Instead, always instantiate a dedicated checker
using createInstance() and manage its lifecycle entirely within your package.
classMyCustomPackageService{
finalInternetConnection _connectionChecker;
// Use createInstance() to isolate your connection checker from the host appMyCustomPackageService() : _connectionChecker = InternetConnection.createInstance();
// Safely clean up only your isolated instanceFuture<void> shutdown() async {
await _connectionChecker.dispose();
}
}
Default Endpoints
The following endpoints are checked by default (carefully selected for speed
and reliability!):