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

collapsible_sidebar 封面
套件詳情v2.0.7

collapsible_sidebar

適用於 Flutter 應用的可摺疊側邊欄,實作 Material Design。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2430
喜歡數
370
Pub 分數
140

安裝套件

flutter pub add collapsible_sidebar

套件介紹

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

一個符合 Material Design 指南的可摺疊側邊欄 Flutter 套件。它支援展開與收起狀態之間的平滑過渡,非常適合用於響應式應用的導航。此側邊欄支援自訂內容、圖示、標籤,以及跨平台的適應性行為。專為需要有效利用空間同時維持直覺導航的應用所設計。僅需少量設定即可順暢整合至現有的 Flutter 專案中。

適用情境

  • 響應式儀表板介面
  • 移動和桌面應用程式導航
  • 節省空間的使用者介面佈局
  • 符合 Material Design 的側邊欄
  • 跨平台應用程式

主要特色

  • Material Design 兼容性
  • 平滑的展開/收合動畫
  • 可自定內容和樣式
  • 跨平台支援(Android、iOS、Web、macOS、Windows、Linux)
  • 與 MaterialApp 的輕鬆整合

適合對象

  • 開發響應式儀表板的開發者
  • 遵循材質設計原則的團隊
  • 需要自適應導航的應用程式
  • 跨平台 Flutter 項目
  • UI設計師優先考慮可用性

使用建議

  • 需要適當的佈局約束以實現最佳顯示
  • 可能需要為非 Material 主題添加額外的樣式
  • 大型內容列表帶來的效能影響
  • 超出基本結構的自訂功能有限
  • 最適合具有中等導航項目之應用程式

原始 README

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

collapsible_sidebar


A collapsible sidebar for Flutter apps implementing the Material Design.

responsive-ui

🌟 Version 2.0.7 ✨


Features

  • Material Design
  • Pre-built customizable tile widgets (CollapsibleItems)
  • Smooth Animation
  • Supports both LTR & RTL languages
  • Supports MULTI-LEVEL Menu
  • Alert Badges on CollapsibleItems

Supported platforms

  • Flutter Android
  • Flutter iOS
  • Flutter web
  • Flutter desktop

Contributors

A big thank you to all the contributors without whom this project would be impossible to maintain and enhance. 👏👏👏

Live preview

https://drunkonbytes.github.io/flutter_collapsible_sidebar

Note: this page is built with flutter-web. For a better user experience, please use a mobile device to open this link.

Installation

Add collapsible_sidebar: ^2.0.7 to your pubspec.yaml dependencies. And import it:

import 'package:collapsible_sidebar/collapsible_sidebar.dart';

How to use

  1. Create a list of CollapsibleItems named _items (or whatever fancy name you like)
For a collapsible item with sub-items to be the default selected item MARK ALL OF ITS SUB-ITEMS WITH THE isSelected: true property.
List<CollapsibleItem> get _items {
    return [
      CollapsibleItem(
          text: 'Shop',
          iconImage: AssetImage("assets/shop_icon.png"), //`iconImage` has priority over `icon` property
          icon: Icons.ac_unit,
          onPressed: () => setState(() => _headline = 'Shop'),
          onHold: () => ScaffoldMessenger.of(context).showSnackBar(
              SnackBar(content: const Text("Shop"))
          ),
          isSelected: true,
          subItems: [
            CollapsibleItem(
              text: 'Cart',
              icon: Icons.shopping_cart,
              onPressed: () => setState(() => _headline = 'Cart'),
              onHold: () => ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(content: const Text("Cart"))
              ),
              isSelected: true,
            )
          ]
      ),
      CollapsibleItem(
        text: 'Dashboard',
        badgeCount: 7,
        icon: Icons.assessment,
        onPressed: () => setState(() => _headline = 'DashBoard'),
        onHold: () => ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: const Text("DashBoard"))
        ),
      ),
      CollapsibleItem(
        text: 'Ice-Cream',
        icon: Icons.icecream,
        onPressed: () => setState(() => _headline = 'Ice-Cream'),
        onHold: () => ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: const Text("Ice-Cream"))
        ),
      ),
      CollapsibleItem(
        text: 'Search',
        icon: Icons.search,
        onPressed: () => setState(() => _headline = 'Search'),
        onHold: () => ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: const Text("Search"))
        ),
      ),
    ];
  }
  1. Define the body of the app (the widget where the main working of the app will be) and name it say _body.
Widget _body(Size size, BuildContext context) {
    return Container(
      height: double.infinity,
      width: double.infinity,
      color: Colors.blueGrey[50],
      child: .........,
    );
  }
  1. Finally completely define the CollapsibleSidebar widget by adding the list of CollapsibleItems named _items, the body of the app named _body and the customizable parameters as needed:
CollapsibleSidebar(
  items: _items,
  avatarImg: _avatarImg,
  title: 'John Smith',
  body: _body(size, context),
)

Also you can use the isCollapsed condition depending how you want the state of the sidebar to change (collapsed/expanded) for example [size.width]

CollapsibleSidebar(
  isCollapsed: MediaQuery.of(context).size.width <= 800,
  items: _items,
  avatarImg: _avatarImg,
  title: 'John Smith',
  body: _body(size, context),
)

Parameters (customizable attributes)

Name Data Type Default Value Description
isCollapsed bool true can set condition to control state of sidebar (collapsed/expanded) on some property change
collapseOnBodyTap bool true flag to enable/disable tapping on the body of the app (area other than the sidebar) to collapse the sidebar
items List<CollapsibleItems> --- List of CollapsibleItems
showTitle bool true can set to false to hide title and avatar Image
title String --- Title of the Collapsible Sidebar
titleBack bool false set to 'true' to use a back icon instead of avatar picture
titleBackIcon Icons Icons.arrow_back the back icon is 'arrow_back' by default (customizable)
onTitleTap Function --- custom callback function called when title avatar or back icon is pressed
onHoverPointer SystemMouseCursors SystemMouseCursors.click the default hover mouse pointer is set to 'click' type by default (customizable)
textStyle TextStyle --- custom style for sidebar title
titleStyle TextStyle --- custom style for collapsible items text
toggleTitleStyle TextStyle --- custom style for toggle button title
avatarImg Image --- Image to be displayed
body Widget --- The main body of the app (the underlying main widget other than the sidebar)
height double double.infinity height of the Sidebar
minWidth double 80 Width of Sidebar when Collapsed
maxWidth double 270 Width of Sidebar when Expanded
borderRadius double 15 Radius of the borders
iconSize double 40 Size of the icons
customContentPaddingLeft double -1 Padding to the left of CollapsibleItems (keep value less than 0 for default padding)
toggleTitle String 'Collapse' title text of Toggle Button
toggleButtonIcon Icons Icons.chevron_right Icon of the Toggle button
backgroundColor Color Color(0xff2B3138) The background color
avatarBackgroundColor Color Color(0xff6A7886) The avatar background color
selectedIconBox Color Color(0xff2F4047) Color of Icon Box when selected
selectedIconColor Color Color(0xff4AC6EA) Color of Icon when selected
selectedTextColor Color Color(0xffF3F7F7) Color of text when selected
unselectedIconColor Color Color(0xff6A7886) Color of Icon when not selected
unselectedTextColor Color Color(0xffC0C7D0) Color of text when not selected
badgeBackgroundColor Color Color(0xffFF6767) Background color of badges on Collapsible Items
badgeTextColor Color Color(0xffF3F7F7) Badge Text color of badges on Collapsible Items
duration Duration Duration(milliseconds: 500) Animation duration for collapsed->expanded & vice-versa
curve Curves Curves.fastLinearToSlowEaseIn Animation curve for collapsed->expanded & vice-versa
screenPadding double 4 Padding to the screen
topPadding double 0 space between image avatar and icons
bottomPadding double 0 space between icons and toggle button
itemPadding double 10 space between collapsible items
customItemOffsetX double -1 X axis offset for collapsible items (keep value less than 0 for default offset)
fitItemsToBottom bool true fit all icons to the end of the space between image avatar and toggle button
showToggleButton bool true flag to enable/disable showing the toggle button
sidebarBoxShadow List<BoxShadow> [BoxShadow(color: Colors.blue, blurRadius: 10, spreadRadius: 0.01, offset: Offset(3, 3),),] Just like the "BoxDecoration" parameter of a "Container"

License


Apache 2.0

所屬分類

原始碼儲存庫

使用此套件的專案