Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev0.0.2

defer_pointer

Uma alternativa para o Overlay que permite renderizar e testar cliques em um widget fora dos limites do pai de forma fácil.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
80,2 mil
Curtidas
158
Pontos Pub
130

Instalar pacote

flutter pub add defer_pointer

Visão geral do pacote

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

O pacote defer_pointer fornece uma alternativa ao Overlay do Flutter, permitindo que widgets sejam renderizados e interajam fora dos limites do widget pai. Simplifica o teste de colisão para widgets posicionados dinamicamente na hierarquia da interface, tornando-o ideal para sobrecapas complexas, dicas de ferramenta ou elementos flutuantes que precisam responder a eventos de ponteiro independentemente das restrições de layout. Desenvolvido por gskinner.com, suporta todas as principais plataformas, incluindo Android, iOS, Web, macOS, Windows e Linux. O pacote aumenta a flexibilidade da interação do usuário sem exigir gerenciamento manual de camadas.

Casos de uso

  • Criando dicas flutuantes
  • Construindo sobreposições dinâmicas
  • Implementando arrastar e soltar em layouts restritos
  • Renderização de elementos interativos além dos limites do pai
  • Projetando componentes de interface personalizados sensíveis ao ponteiro

Principais recursos

  • Suporte de teste de colisão entre limites
  • Simplifica a implementação de sobreposição
  • Funciona em todas as plataformas do Flutter
  • Mínimo boilerplate necessário
  • Integra-se de forma transparente às árvores de widget existentes

Indicado para

  • Desenvolvedores construindo interações de UI complexas
  • Equipes que precisam de sobreposições responsivas
  • Aplicativos com elementos flutuantes dinâmicos
  • Bibliotecas de interface do usuário que exigem manipulação avançada de ponteiros
  • Projetos direcionados para múltiplas plataformas

Considerações

  • Pode afetar o desempenho com muitos widgets ativos
  • Requer gerenciamento cuidadoso de estado
  • Não adequado para sobreposições estáticas simples
  • Documentação limitada além do uso básico
  • Possibilidade de captura não intencional do ponteiro se não for gerenciada corretamente

README original

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

An alternative to Overlay which allows you to easily render and hit test a widget outside its parent bounds. Based on the original idea by @shrouxm here: https://github.com/flutter/flutter/issues/75747#issuecomment-907755810

Typically in Flutter, if you offset a widget outside of it's parent bounds hit-testing will break. DeferPointer works around this issue by handing off hit-testing and (optionally) rendering to an DeferredPointerHandler widget further up the tree.

While Overlay can solve this issue to some degree, using DeferPointer offers some benefits:

  • just works: no error prone and tedious layer management
  • more granular: you can set the bounds to be any ancestor widget you choose
  • more flexible: you can choose to paint the child on top, or not
  • easier to align/pin to a widget in the tree as that is the default expectation

This is useful for larger UI components like dropdown menus and sliding panels, as well as just small general styling tweaks.

🔨 Installation

dependencies:
  defer_pointer: ^0.0.2
⚙ Import
import 'package:defer_pointer/defer_pointer.dart';

🕹️ Usage

  1. Wrap a DeferredPointerHandler somewhere above the buttons that you wish to hit-test.
  2. Wrap DeferPointer around the buttons themselves.
Widget build(BuildContext context) {
    return DeferredPointerHandler(
       child: SizedBox(
           width: 100,
           height: 100,
           child: Stack(clipBehavior: Clip.none, children: [
             // Hang button off the bottom of the content
             Positioned(
               bottom: -30,
               child: DeferPointer(child: _SomeBtn(false)),
             ),
             // Content
             Positioned.fill(
               child: Container(
                 decoration: BoxDecoration(color: Colors.green, boxShadow: [
                   BoxShadow(color: Colors.black.withOpacity(1), blurRadius: 4, spreadRadius: 4),
                 ]),
               ),
             ),
           ]))));
  }

Enable paintOnTop if you need the child Widget painted on top of it's siblings. This will defer painting to the currently linked DeferredPointerHandler.

return DeferPointer(
    paintOnTop: true,
    child: TextButton(...));
Examples

There are 4 examples in this repo:

  1. A simple example of offsetting 2 buttons outside their stack: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/simple_offset_outside_parent.dart

  2. A classic desktop/web style dropdown menu: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/dropdown_menus.dart

  3. A animated menu based on the Flow widget: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/flow_menu.dart

  4. A auto-complete search field: https://github.com/gskinnerTeam/flutter-defer-pointer/blob/master/example/lib/examples/auto_complete.dart

Manual Linking

By default a DeferPointer widget will look up the closest DeferredPointerHandler using it's current context. For more complicated use cases you can manually assign a link to bind a pointer to a handler:

final _deferredPointerLink = DeferredPointerHandlerLink();
...
Widget build(){
    return DeferredPointerHandler(
      link: _deferredPointerLink,
      child: Padding(
          padding: const EdgeInsets.all(20),
          child: DeferPointer(
            link: _deferredPointerLink,
            child: ...,
          )),
    );
}

🐞 Bugs/Requests

If you encounter any problems please open an issue. If you feel the library is missing a feature, please raise a ticket on Github and we'll look into it. Pull request are welcome.

📃 License

MIT License

Categorias

Dependências

Lista de dependências 1 itens

Repositório-fonte

Projetos que usam este pacote