搜尋套件、儲存庫與 APP 分類

draggable_float_widget 封面
套件詳情v0.1.0

draggable_float_widget

這是一個可拖曳且浮動的 Flutter 小部件,可透過 ScrollView 的滾動事件來控制其可見性。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
17.7萬
喜歡數
116
Pub 分數
150

安裝套件

flutter pub add draggable_float_widget

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,提供可拖曳的浮動組件,能夠根據捲動事件自動顯示或隱藏。非常適合用來建立互動式 UI 元素,例如浮動操作按鈕或自訂覆蓋層,這些元件會跟隨使用者的捲動行為。該組件可在螢幕上自由移動,並根據捲動方向與在 ScrollView 中的位置調整其可見性。支援所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。

適用情境

  • 可滾動列表中的浮動操作按鈕
  • 可響應滾動的互動疊加層
  • 自訂可拖曳的UI元件
  • 增強移動應用導航
  • Web應用程序中的動態UI元素

主要特色

  • 可拖曳定位
  • 滾動觸發的可見性控制
  • 跨平台相容性
  • 拖曳時的平滑動畫
  • 可設定的顯示/隱藏閾值
  • 支援多個平台目標

適合對象

  • 開發滾動感知使用者介面的開發者
  • 需要動態浮動元素的行動與網頁應用
  • 實現基於手勢互動的設計人員
  • 具有複雜疊加需求的應用程式
  • 針對多平台部署的團隊

使用建議

  • 大型列表可能需要效能調校
  • 複雜的捲動行為可能需要自訂顯示邏輯
  • 有限的內建樣式選項
  • 不適合靜態浮動元素
  • 在嵌套滾動視圖中需要謹慎處理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

draggable_float_widget

This is a draggable and floating Flutter widget, which can control its visibility through the scrolling event of ScrollView.

Usage

To use this plugin, add draggable_float_widget as a dependency in your pubspec.yaml file.

constructor
  • the constructor of component

    DraggableFloatWidget({
      Key? key,
      this.width = defaultWidgetWidth,
      this.height = defaultWidgetHeight,
      this.eventStreamController,
      this.config = const DraggableFloatWidgetBaseConfig(),
      required this.child,
      this.onTap,
    }) : super(key: key);
    
  • special field instructions

    property description default
    eventStreamController The [StreamController] of [OperateEvent] null
    config the base config of [DraggableFloatWidget] DraggableFloatWidgetBaseConfig()
  • the base config of component

    DraggableFloatWidgetBaseConfig({
      this.isFullScreen = true,
      this.appBarHeight = kToolbarHeight,
      this.initPositionXInLeft = true,
      this.initPositionYInTop = true,
      this.initPositionYMarginBorder = 0,
      this.borderLeft = defaultBorderWidth,
      this.borderRight = defaultBorderWidth,
      this.borderTop = defaultBorderWidth,
      this.borderTopContainTopBar = false,
      this.borderBottom = defaultBorderWidth,
      this.exposedPartWidthWhenHidden = defaultExposedPartWidthWhenHidden,
      this.animDuration = const Duration(milliseconds: 300),
      this.delayShowDuration = const Duration(milliseconds: 500),
      this.debug = false,
    });
    
example
  • the first, add scroll listener

    ⚠️Ignore this step if the component is not affected by ScrollView scrolling, and you don't need to pass an StreamController instance into the instance.

    NotificationListener(
      onNotification: (notification) {
        if (notification is ScrollStartNotification) {
          eventStreamController.add(OperateEvent.OPERATE_HIDE);
        } else if (notification is ScrollEndNotification) {
          eventStreamController.add(OperateEvent.OPERATE_SHOW);
        }
        return true;
      },
      child: ListView(...),
    )
    
  • the first way: stack mode

    Stack(
      children: [
        listView,
        DraggableFloatWidget(
          child: child,
          eventStreamController: eventStreamController,
          config: DraggableFloatWidgetBaseConfig(
            isFullScreen: false,
            initPositionYInTop: false,
            initPositionYMarginBorder: 50,
            borderBottom: navigatorBarHeight + defaultBorderWidth,
          ),
          onTap: () => print("Drag onTap!"),
        )
      ],
    )
    

    stack mode

  • the second way: overlay mode

    _overlayEntry = OverlayEntry(builder: (context) {
      return DraggableFloatWidget(
        child: widget.child,
        eventStreamController: widget.eventStreamController,
        config: DraggableFloatWidgetBaseConfig(
          initPositionYInTop: false,
          initPositionYMarginBorder: 50,
          borderTopContainTopBar: true,
          borderBottom: widget.navigatorBarHeight + defaultBorderWidth,
        ),
        onTap: () => print("Drag onTap!"),
      );
    });
    
    /// Warning: context cannot be the context of MaterialApp
    Overlay.of(context)?.insert(_overlayEntry!);
    

    overlay mode

Contributions

If you encounter any problem or the library is missing a feature feel free to open an issue. Feel free to fork, improve the package and make pull request.

License

MIT

所屬分類

原始碼儲存庫

使用此套件的專案