Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ class _MyHomePageState extends State<MyHomePage> {
),
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(
Expand Down
22 changes: 14 additions & 8 deletions lib/src/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -302,26 +307,27 @@ class _AnimatedSidebarState extends State<AnimatedSidebar>
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,
maxLines: 1,
softWrap: false,
style: widget.headerTextStyle,
),
)
))
: const SizedBox.shrink(),
],
),
Expand Down
2 changes: 1 addition & 1 deletion test/animated_sidebar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down