패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.0.2

defer_pointer

부모의 경계를 벗어난 곳에 위젯을 쉽게 렌더링하고 히트테스트할 수 있는 Overlay의 대안입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
8만
좋아요
158
Pub 점수
130

패키지 설치

flutter pub add defer_pointer

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

defer_pointer 패키지는 Flutter의 Overlay에 대한 대안을 제공하여 위젯이 부모 위젯의 경계를 벗어나 렌더링하고 상호작용할 수 있도록 합니다. UI 계층 구조 내에서 동적으로 위치한 위젯에 대한 히트 테스트를 단순화하여 복잡한 오버레이, 툴팁 또는 레이아웃 제약 조건과 관계없이 포인터 이벤트에 반응해야 하는 플로팅 요소에 적합합니다. gskinner.com에서 개발되었으며 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원합니다. 수동 레이어 관리 없이 사용자 인터랙션의 유연성을 향상시킵니다.

사용 사례

  • 부유형 툴팁 만들기
  • 동적 오버레이 구축
  • 제약된 레이아웃에서 드래그 앤 드롭 구현
  • 부모 경계를 초과하는 상호작용 요소 렌더링
  • 사용자 정의 포인터 민감한 UI 컴포넌트 설계

주요 기능

  • 경계를 넘나드는 히트 테스트를 지원합니다
  • 오버레이 구현을 간소화합니다
  • 모든 플러터 플랫폼에서 작동합니다
  • 필요한 보일러플레이트 최소화
  • 기존 위젯 트리에 원활하게 통합됩니다

적합한 대상

  • 복잡한 UI 상호작용을 구축하는 개발자
  • 반응형 오버레이가 필요한 팀
  • 동적 플로팅 요소를 가진 앱
  • 고급 포인터 처리를 요구하는 UI 라이브러리
  • 다중 플랫폼을 대상으로 하는 프로젝트

고려 사항

  • 많은 활성 위젯이 있는 경우 성능에 영향을 미칠 수 있습니다
  • 상태 관리에 신중이 필요합니다
  • 간단한 정적 오버레이에 적합하지 않음
  • 기본 사용법 외에 문서가 제한적
  • 적절히 관리되지 않으면 의도하지 않은 포인터 캡처의 가능성이 있다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

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

카테고리

의존성

의존성 목록 1 개

소스 저장소

이 패키지를 사용하는 프로젝트