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

套件詳情v0.0.5+1

overlay_container

一個 Flutter 小部件,用於將其子元件渲染到原始小部件層次結構之外。

近 30 天下載
3
喜歡數
50
Pub 分數
40

安裝套件

flutter pub add overlay_container

套件介紹

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

OverlayContainer 是一個 Flutter 小部件,會將其子組件渲染在原始小部件層次結構之外,讓元素能獨立於其父佈局進行定位。這特別適用於建立覆蓋層、工具提示或浮動 UI 組件,這些組件需要顯示在其他小部件之上,而不受其容器邊界限制。它利用 Flutter 的 Overlay 機制來實現此行為,提供一種乾淨且高效的方式來管理分層 UI 元素。該套件輕量且設計簡單,非常適合希望在複雜佈局中精確控制小部件定位的開發者。

適用情境

  • 建立浮動操作按鈕
  • 顯示工具提示或彈出框
  • 實現自定義模態對話框
  • 建構疊加選單
  • 將UI元素定位在父級約束之外

主要特色

  • 將子組件渲染到父組件層級之外
  • 使用 Flutter 的 Overlay 來實現高效渲染
  • 簡單的 API,設定簡單
  • 支援絕對定位
  • 可與現有的 widget 樹無縫配合

適合對象

  • 需要進階覆蓋功能的開發者
  • UI 設計師實作層疊介面
  • 需要動態浮動元素的專案
  • 具有複雜互動疊加層的應用程式
  • 重視程式碼潔淨與可維護性的團隊

使用建議

  • 可能需要仔細處理焦點和手勢
  • 不適用於靜態佈局結構
  • 大量覆蓋層可能帶來的效能影響
  • 需要正確釋放覆蓋項目
  • 有限的平台特定優化

原始 README

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

overlay_container

Pub Package License

A flutter widget which renders its child outside the original widget hierarchy.

Demo.

Demo

This demo is present as an example here. You can also checkout the examples folder.

Description.

The child passed to this widget is rendered outside the widget hierarchy as an overlay to the exisiting widget tree. As a result this widget is highly suitable for building custom dropdown options, autocomplete suggestions, dialogs, etc. Think of it as widget placed absolutely and having a positive z-index over the rest of the widget tree. It is actually a friendly wrapper over the Flutter's Overlay and OverlayEntry APIs.

If you've ever used react, this tries to do what React Portal does, in a way.

Example.

import 'package:flutter/material.dart';
import 'package:overlay_container/overlay_container.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Overlay Container Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  // Need to maintain a "show" state either locally or inside
  // a bloc.
  bool _dropdownShown = false;

  void _toggleDropdown() {
    setState(() {
      _dropdownShown = !_dropdownShown;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Overlay Container Demo Page'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            RaisedButton(
              onPressed: _toggleDropdown,
              child: Column(
                children: <Widget>[
                  Text("Dropdown button"),
                ],
              ),
            ),
            // By default the overlay (since this is a Column) will
            // be added right below the raised button
            // but outside the widget tree.
            // We can change that by supplying a "position".
            OverlayContainer(
              show: _dropdownShown,
              // Let's position this overlay to the right of the button.
              position: OverlayContainerPosition(
                // Left position.
                150,
                // Bottom position.
                45,
              ),
              // The content inside the overlay.
              child: Container(
                height: 70,
                padding: const EdgeInsets.all(20),
                margin: const EdgeInsets.only(top: 5),
                decoration: BoxDecoration(
                  color: Colors.white,
                  boxShadow: <BoxShadow>[
                    BoxShadow(
                      color: Colors.grey[300],
                      blurRadius: 3,
                      spreadRadius: 6,
                    )
                  ],
                ),
                child: Text("I render outside the \nwidget hierarchy."),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

A more elaborate example is found here.

Installation.

  • Instructions are here.

Inspiration

License.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。