diff --git a/example/lib/main.dart b/example/lib/main.dart index 28572e0..be4534e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -123,7 +123,9 @@ class _MyHomePageState extends State { ), itemMargin: 16, itemSpaceBetween: 10, - headerIcon: Icons.ac_unit_sharp, + headerIcon: const CircleAvatar( + child: Icon(Icons.hive_sharp), + ), headerIconSize: 30, headerIconColor: Colors.amberAccent, headerTextStyle: const TextStyle( diff --git a/lib/src/sidebar.dart b/lib/src/sidebar.dart index c58553b..884ccce 100644 --- a/lib/src/sidebar.dart +++ b/lib/src/sidebar.dart @@ -109,7 +109,7 @@ class AnimatedSidebar extends StatefulWidget { /// The [headerIcon] is displayed on the top of the sidebar. /// /// if null, only the [headerText] will be displayed. - final IconData? headerIcon; + final Widget? headerIcon; /// the size of the [headerIcon]. final double? headerIconSize; @@ -125,6 +125,10 @@ class AnimatedSidebar extends StatefulWidget { /// The [headerText] is displayed on the top of the sidebar. final String? headerText; + /// The [textCallback] is a callback function that can be passed + /// to the sidebar to be called when [headerText] is pressed + final VoidCallback? textCallback; + const AnimatedSidebar({ Key? key, required this.items, @@ -169,6 +173,7 @@ class AnimatedSidebar extends StatefulWidget { this.headerTextStyle = const TextStyle( fontSize: 22, fontWeight: FontWeight.w500, color: Colors.white), this.headerText, + this.textCallback, }) : assert((headerIcon != null && headerText != null) ^ (header != null)), super(key: key); @@ -302,18 +307,19 @@ class _AnimatedSidebarState extends State Widget _buildIconTextHeader() { return Container( padding: EdgeInsets.symmetric(horizontal: _calculateHeaderItemOffset()), - height: 64, - child: Row( + child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ - Icon( - widget.headerIcon, - color: widget.headerIconColor, - size: widget.headerIconSize, + SizedBox( + height: widget.headerIconSize, + width: widget.headerIconSize, + child: widget.headerIcon, ), _expanded || _inAnimation ? Flexible( + child: TextButton( + onPressed: widget.textCallback, child: Text( widget.headerText ?? 'missing', overflow: TextOverflow.fade, @@ -321,7 +327,7 @@ class _AnimatedSidebarState extends State softWrap: false, style: widget.headerTextStyle, ), - ) + )) : const SizedBox.shrink(), ], ), diff --git a/test/animated_sidebar_test.dart b/test/animated_sidebar_test.dart index 30108a8..3a3b419 100644 --- a/test/animated_sidebar_test.dart +++ b/test/animated_sidebar_test.dart @@ -54,7 +54,7 @@ void main() { ), itemMargin: 16, itemSpaceBetween: 10, - headerIcon: Icons.menu, + headerIcon: const CircleAvatar(child: Icon(Icons.adb_sharp)), headerIconSize: 30, headerIconColor: Colors.deepPurple, headerTextStyle: const TextStyle(