collapsible_sidebar 2.0.5%2B1

SDKflutter
Platformandroidioswindowslinuxmacosweb

A collapsible sidebar for Flutter apps implementing the Material Design.

collapsible_sidebar


A collapsible sidebar for Flutter apps implementing the Material Design.

responsive-ui

🌟 Version 2.0.5+1 ✨


Features

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

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.5+1 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',
        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)

NameData TypeDefault ValueDescription
isCollapsedbooltruecan set condition to control state of sidebar (collapsed/expanded) on some property change
collapseOnBodyTapbooltrueflag to enable/disable tapping on the body of the app (area other than the sidebar) to collapse the sidebar
itemsList<CollapsibleItems>---List of CollapsibleItems
showTitlebooltruecan set to false to hide title and avatar Image
titleString---Title of the Collapsible Sidebar
titleBackboolfalseset to 'true' to use a back icon instead of avatar picture
titleBackIconIconsIcons.arrow_backthe back icon is 'arrow_back' by default (customizable)
onTitleTapFunction---custom callback function called when title avatar or back icon is pressed
onHoverPointerSystemMouseCursorsSystemMouseCursors.clickthe default hover mouse pointer is set to 'click' type by default (customizable)
textStyleTextStyle---custom style for sidebar title
titleStyleTextStyle---custom style for collapsible items text
toggleTitleStyleTextStyle---custom style for toggle button title
avatarImgImage---Image to be displayed
bodyWidget---The main body of the app (the underlying main widget other than the sidebar)
heightdoubledouble.infinityheight of the Sidebar
minWidthdouble80Width of Sidebar when Collapsed
maxWidthdouble270Width of Sidebar when Expanded
borderRadiusdouble15Radius of the borders
iconSizedouble40Size of the icons
toggleTitleString'Collapse'title text of Toggle Button
toggleButtonIconIconsIcons.chevron_rightIcon of the Toggle button
backgroundColorColorColor(0xff2B3138)The background color
selectedIconBoxColorColor(0xff2F4047)Color of Icon Box when selected
selectedIconColorColorColor(0xff4AC6EA)Color of Icon when selected
selectedTextColorColorColor(0xffF3F7F7)Color of text when selected
unselectedIconColorColorColor(0xff6A7886)Color of Icon when not selected
unselectedTextColorColorColor(0xffC0C7D0)Color of text when not selected
durationDurationDuration(milliseconds: 500)Animation duration for collapsed->expanded & vice-versa
curveCurvesCurves.fastLinearToSlowEaseInAnimation curve for collapsed->expanded & vice-versa
screenPaddingdouble4Padding to the screen
topPaddingdouble0space between image avatar and icons
bottomPaddingdouble0space between icons and toggle button
itemPaddingdouble10space between collapsible items
fitItemsToBottombooltruefit all icons to the end of the space between image avatar and toggle button
showToggleButtonbooltrueflag to enable/disable showing the toggle button
sidebarBoxShadowList<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