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

套件詳情v0.1.2

flutter_anywhere_menus

任意位置的選單!現在可建立浮動選單,自動根據父組件或觸控/點擊位置進行定位。

近 30 天下載
37
喜歡數
36
Pub 分數
40

安裝套件

flutter pub add flutter_anywhere_menus

套件介紹

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

Flutter Anywhere Menus 是一個輕量級套件,可讓開發者建立浮動選單,這些選單會根據父組件或使用者觸控/點擊位置動態定位。非常適合情境式動作,透過確保選單在需要的位置精確顯示,提升 UI 的互動性,無需手動定位。此套件支援響應式設計,並能順暢整合至現有的 Flutter 應用程式中。在空間有限且直覺導航至關重要的行動介面中特別實用。

適用情境

  • 上下文操作選單
  • 浮動彈出選單
  • 基於觸控的選單放置
  • 響應式 UI 組件
  • 行動應用程式導航增強

主要特色

  • 基於父級或觸控的自動定位
  • 輕量且易於整合
  • 支援動態版面調整
  • 無需複雜設定
  • 無縫的 Flutter 兼容性

適合對象

  • 移動應用開發者
  • UI/UX 設計師
  • 互動式介面建構工具
  • 頻繁上下文操作的應用程式
  • 尋求快速菜單解決方案的開發者

使用建議

  • 僅限 Flutter 平台
  • 無內建動畫
  • 需要手動處理選單項目回呼
  • 未針對大型菜單項目進行優化
  • 依賴於正確的元件層次結構進行定位

原始 README

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

Flutter Anywhere Menus (FAM) Pub Version

Menus, anywhere you want them!

Default Usage

Imgur

Menu(
  child: MaterialButton(
    child: Text('Show Basic Menu'),
  ),
  menuBar: MenuBar(),
),

Slightly Fancier Menu

Imgur

Menu(
  child: MaterialButton(
    child: Text('Dem Fancy Menus'),
  ),
  menuBar: MenuBar(
    drawArrow: true,
    itemPadding: EdgeInsets.symmetric(horizontal: 15, vertical: 4),
    menuItems: [
      MenuItem(
        child: Icon(Icons.color_lens, color: Colors.grey[600]),
        onTap: () => _incrementCounter(),
      ),
      MenuItem(
        child: Menu(
          offset: Offset(0, 20),
          child: Icon(Icons.colorize, color: Colors.grey[600]),
          menuBar: MenuBar(
              drawArrow: true,
              drawDivider: true,
              maxThickness: 68,
              orientation: MenuOrientation.vertical,
              menuItems: [MenuItem(child: Icon(Icons.add))]),
        ),
      ),
      MenuItem(
          child: Icon(Icons.content_copy, color: Colors.grey[600])),
    ],
  ),
),

Menu On Tap

Imgur

Menu(
  tapType: TapType.tap,
  child: Container(
    width: 300,
    height: 200,
    color: Colors.yellow,
    child: Center(child: Text('Show Menu Over Tap')),
  ),
  menuOverTap: true,
  menuBar: menuBar,
),

Roadmap

  • [x] Vertical menus
  • [ ] Animations
  • [ ] Fixed screen position menus (Guess that'd just be a Toast...)

Background

Why FAM? The short answer is... yak shaving. I needed a menu for a project that would pop up above a widget when I clicked on it. Simple right? Yeah... no. There were a few more requirements that made it a far more interesting problem.

  1. The menu needs to be very customizable
  2. The menu needs the ability to have child menus OR child widgets
  3. The menu (and all children) needs to be a drawn above all other widgets
  4. And this was the doozy... the menu needs to be positionable RELATIVE to its parent widget, and all child menus and child widgets need to be relative positioned to their parent

That last requirement took me down the rabbit hole of Flutter widget positioning and long story short, Flutter is one of a few (maybe the only?) rendering/UI languages I've used that simply cannot do relative positioning out of the box (pun intended). See, the box is what traps you. You can Column() and Row() all day long but you're still trapped in box. What I want is the equivalent of widget1.alignTo(widget2, fromAlignment: Alignment.topCenter, toAlignment: Alignment.bottomCenter) so that I can setup a widget and then just stick it on to another widget. A man can dream right?

Maybe Stack() and Align()? HA! Still stuck in that box, and still no way to define a solid widget-to-widget positioning.

I want my menu outside of the box MAN! And without knowing the sizes of the boxes before rendering, good luck trying to accurately position a menu over (or under, or next to) its intended target widget. So what does FAM do?

It... cheats.

FAM still doesn't know about the properties of the menu before hand, BUT what it can do is render the menu invisibly as an overlay, examine its size, then move it to where it needs to be. The result is that I can now define an absolute relationship between relevant points on a widget (say, tying the bottomCenter of one widget to the topCenter of another) without either widget having any relationship, and without any restrictions on how I draw either widget, while making sure that whatever crazy alignments I do won't mess up the positioning or size of my original widget.

OK. It ain't pretty, but the results do speak for themselves. Hope at least some of you can make use of this, and maybe Flutter will one day have relational positioning like any sensible rendering language.

Credits

This was originally a fork of https://github.com/CaiJingLong/flutter_long_tap_menu that outgrew most of the original code. Many yak were shaved in the process.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。