Git Product home page Git Product logo

kesimo / animated_sidebar Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 5.0 2.02 MB

A Responsive Sidebar optimized for Flutter Web and Desktop

Home Page: https://pub.dev/packages/animated_sidebar

License: MIT License

Kotlin 0.18% Swift 1.08% Dart 37.29% CMake 26.80% C++ 30.00% C 2.04% HTML 2.61%
dart flutter flutter-appbar flutter-package sidebar flutter-web responsive sidebar-menu sidebar-navigation widget

animated_sidebar's Introduction

Animated Sidebar

pub package Libraries.io for GitHub License

A highly customizable and styleable collapsable sidebar plugin for Flutter, optimized for web and desktop applications.

Example

example-ui

Installation

Add the following to your pubspec.yaml file:

dependencies:  
 animated_sidebar: ^1.0.0   

or use the following command:

flutter pub add animated_sidebar  

Add the following import to your dart file:

import 'package:animated_sidebar/animated_sidebar.dart';  

Usage

Sidebar Items

define a list of SidebarItem objects:

import 'package:animated_sidebar/animated_sidebar.dart';  
  
final List<SidebarItem> items = [  
  SidebarItem(icon: Icons.home, text: 'Home'),  
  SidebarItem(icon: Icons.notifications, text: 'Notifications'),  
  SidebarItem(icon: Icons.person, text: 'Management'),  
];  

Child Items

it is also possible to define multiple SidebarChildItem for every SidebarItem.

import 'package:animated_sidebar/animated_sidebar.dart';  
  
final List<SidebarItem> items = [  
  SidebarItem(icon: Icons.home, text: 'Home'),  
  SidebarItem(  
    icon: Icons.person,  
    text: 'Management',  
    children: [  
	  SidebarChildItem(icon: Icons.person, text: 'Users'),  
	  SidebarChildItem(icon: Icons.verified_user, text: 'Roles'),  
    ],  
  ),
];  

The Item Containing the Children is Collapsed and expand only on tap. If the Current selected item is a SidebarChildItem the overlying Item keeps expanded

Default usage of AnimatedSidebar

import 'package:animated_sidebar/animated_sidebar.dart';

@override
Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Theme.of(context).scaffoldBackgroundColor,
    body: Row(
      children: [
        AnimatedSidebar(
          expanded: MediaQuery.of(context).size.width > 600,
          items: items,
          selectedIndex: 0,
          onItemSelected: (index) => print(index),
          headerIcon: Icons.ac_unit_sharp,
          headerIconColor: Colors.amberAccent,
          headerText: 'Example',
        ),
        Center(
          child: Text(
            'Page: $activeTab',
            style: Theme.of(context).textTheme.headline3,
          ),
        ),
      ],
    ),
  );
}

Use the AnimatedSidebar widget and handle state external :

import 'package:animated_sidebar/animated_sidebar.dart';

int activeTab = 0;

@override
Widget build(BuildContext context) {
  return Scaffold(
    backgroundColor: Theme.of(context).scaffoldBackgroundColor,
    body: Row(
      children: [
        AnimatedSidebar(
          expanded: MediaQuery.of(context).size.width > 600,
          items: items,
          selectedIndex: activeTab,
          autoSelectedIndex: false, // must be false if you want to handle state external
          onItemSelected: (index) =>
              setState(() => activeTab = index),
          headerIcon: Icons.ac_unit_sharp,
          headerIconColor: Colors.amberAccent,
          headerText: 'Example',
        ),
        Center(
          child: Text(
            'Page: $activeTab',
            style: Theme.of(context).textTheme.headline3,
          ),
        ),
      ],
    ),
  );
}

animated_sidebar's People

Contributors

definejh avatar kesimo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

animated_sidebar's Issues

Index out of range error on collapse

Description
When the bar has more than one SideItem with children, a "RangeError" is displayed when the bar is in collapsed mode.

To Reproduce

  1. Create a 'AnimatedSideBar'
  2. Add at least 2 'SideBarItem' with at least 2 'SideBarChildItem' each
  3. Run on Web (I checked on chrome)
  4. Collapse the sideBar
  5. Error displayed within the sideBar
  6. Sometimes if the SIdebarItems with children are opened before collapsing the sidebar, the error does not occur

Expected behavior
No errors must be displayed. Must support multiple items with multiple sub-Items within.

Screenshots
image
image

Desktop:

  • OS: Windows 11
  • Browser: Chrome
  • Version: Chrome version - (Version 115.0.5790.171 (Official Build) (32-bit))

Event onCollapse

Hi,

I think your component is perfect, but if it had the onCollapse event it was be perfect.
This is a great feature if we want to resize the Header Widget, for example.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.