Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev1.0.2

internet_connectivity_checker

O pacote Flutter que ajuda você a gerenciar widgets dinamicamente com base na conexão de internet do dispositivo.

AndroidiOSmacOSWindowsLinux
Downloads em 30 dias
458
Curtidas
38
Pontos Pub
160

Instalar pacote

flutter pub add internet_connectivity_checker

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Um pacote Flutter que permite o gerenciamento dinâmico de widgets com base no status atual de conectividade da internet do dispositivo. Ele fornece monitoramento em tempo real da disponibilidade da rede em múltiplas plataformas, permitindo que os desenvolvedores exibam conteúdo condicionalmente, mostrem indicadores de carregamento ou acionem interfaces alternativas quando offline. O pacote se integra perfeitamente em aplicativos que exigem comportamento responsivo sob diferentes condições de rede. Com uma API simples e suporte multiplataforma, ele garante uma experiência consistente para o usuário, independentemente do estado da conexão.

Casos de uso

  • Exibindo banners offline
  • Renderização condicional de widgets dependentes da rede
  • Mostrar botões de tentar novamente quando offline
  • Espaços reservados de carregamento durante perda de conectividade
  • Manipulação de solicitações de API com consciência de rede
  • Atualizando a interface do usuário com base em alterações de conectividade em tempo real

Principais recursos

  • Monitoramento de conectividade em tempo real
  • Compatibilidade multiplataforma
  • API simples para controle de widget
  • Atualizações automáticas de estado
  • Suporta todas as principais plataformas desktop e móveis
  • Leve e fácil de integrar

Indicado para

  • Aplicativos que precisam de suporte a modo offline
  • aplicações sensíveis à rede
  • Interfaces de usuário que exigem feedback dinâmico
  • Desenvolvedores construindo recursos responsivos e conscientes de rede
  • Projetos direcionados para Android, iOS, macOS, Windows e Linux

Considerações

  • Requer permissões adequadas em algumas plataformas
  • Pode ser necessário um tratamento adicional de erros para casos extremos
  • Não adequado para cenários de sondagem de alta frequência
  • Limitado ao status de conectividade (não à largura de banda)
  • Depende de APIs de detecção de rede em nível do sistema

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

internet_connectivity_checker

The connectivity package and other similar packages only provides information if there is a network connection, but not if the network is connected to the Internet. That's why the internet_connectivity_checker package helps you easily manage widgets dynamically based on the device's internet access.


Demo


🧑‍💻 Getting started

flutter pub add internet_connectivity_checker

🛠️ Usage

Simply import package:internet_connectivity_checker/internet_connectivity_checker.dart' and use the ConnectivityBuilder widget. It takes a builder and an optional parameter, interval(Duration object) which is the time interval to wait between each internet connectivity verification; default is 5 seconds.




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

  @override
  Widget build(BuildContext context) {
    return ConnectivityBuilder(
      builder: (status) {
        bool connected = status == ConnectivityStatus.online;
        return Text(connected ? "Online" : "Offline");
      },
    );
  }
}

A more complete example.

ConnectivityBuilder(
  builder: (ConnectivityStatus status) {
    if (status == ConnectivityStatus.online) {
      return Container(
        decoration: BoxDecoration(
          color: Colors.green,
          borderRadius: BorderRadius.circular(15),
        ),
        child: Center(child: Text("Online", style: kTextStyle)),
      );
    } else if (status == ConnectivityStatus.offline) {
      return Container(
        decoration: BoxDecoration(
          color: Colors.red,
          borderRadius: BorderRadius.circular(15),
        ),
        child: Center(child: Text("Offline", style: kTextStyle)),
      );
    } else { // status == ConnectivityStatus.checking
      return const Center(
        child: SizedBox(
          width: 25,
          height: 25,
          child: CircularProgressIndicator(strokeWidth: 2),
        ),
      );
    }
  },
),

You can also use the ConnectivityChecker().stream stream, provided be the package, to handle the logic yourself.

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

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: ConnectivityChecker(interval: const Duration(seconds: 10)).stream,
      builder: (context, snapshot) {
        if (snapshot.hasData && (snapshot.data as bool) == true) {
          return const Text("Online");
        } else if (snapshot.connectionState == ConnectionState.waiting) {
          return const Center(child: CircularProgressIndicator());
        } else {
          return const Text("Offline");
        }
      },
    );
  }
}

ℹ️ Additional Information

Contribute to this project by making a PR ⬆️ or creating a new issue 🐞 on GitHub.
Do not hesitate to let a 🌟 on the repo if you find it useful.

👷 Maintainers

Created & maintained with 💖 by moustapha.dev.

📄 License

MIT License

Copyright (c) Moustapha Ndoye (@csof3cen), 2023.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Categorias

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.