Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Footer sidebar items #30

Merged
merged 4 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Follow these steps to use this package

```yaml
dependencies:
sidebarx: ^0.12.0
sidebarx: ^0.13.0
```

### Add import package
Expand Down
32 changes: 26 additions & 6 deletions example/lib/desktop_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SidebarXExampleApp extends StatelessWidget {
canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor,
textTheme: const TextTheme(
headline5: TextStyle(
headlineSmall: TextStyle(
color: Colors.white,
fontSize: 46,
fontWeight: FontWeight.w800,
Expand Down Expand Up @@ -100,7 +100,17 @@ class SidebarXExampleApp extends StatelessWidget {
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorite',
label: 'Favorites',
),
],
footerItems: const [
SidebarXItem(
icon: Icons.person,
label: 'Profile',
),
SidebarXItem(
icon: Icons.settings,
label: 'Settings',
),
],
),
Expand Down Expand Up @@ -148,22 +158,32 @@ class _ScreensExample extends StatelessWidget {
case 1:
return Text(
'Search',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
case 2:
return Text(
'People',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
case 3:
return Text(
'Favorites',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
case 4:
return Text(
'Profile',
style: theme.textTheme.headlineSmall,
);
case 5:
return Text(
'Settings',
style: theme.textTheme.headlineSmall,
);
default:
return Text(
'Not found page',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
}
},
Expand Down
32 changes: 26 additions & 6 deletions example/lib/example_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SidebarXExampleApp extends StatelessWidget {
canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor,
textTheme: const TextTheme(
headline5: TextStyle(
headlineSmall: TextStyle(
color: Colors.white,
fontSize: 46,
fontWeight: FontWeight.w800,
Expand Down Expand Up @@ -102,7 +102,17 @@ class SidebarXExampleApp extends StatelessWidget {
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorite',
label: 'Favorites',
),
],
footerItems: const [
SidebarXItem(
icon: Icons.person,
label: 'Profile',
),
SidebarXItem(
icon: Icons.settings,
label: 'Settings',
),
],
),
Expand Down Expand Up @@ -162,22 +172,32 @@ class _ScreensExample extends StatelessWidget {
case 1:
return Text(
'Search',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
case 2:
return Text(
'People',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
case 3:
return Text(
'Favorites',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
case 4:
return Text(
'Profile',
style: theme.textTheme.headlineSmall,
);
case 5:
return Text(
'Settings',
style: theme.textTheme.headlineSmall,
);
default:
return Text(
'Not found page',
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
}
},
Expand Down
20 changes: 17 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SidebarXExampleApp extends StatelessWidget {
canvasColor: canvasColor,
scaffoldBackgroundColor: scaffoldBackgroundColor,
textTheme: const TextTheme(
headline5: TextStyle(
headlineSmall: TextStyle(
color: Colors.white,
fontSize: 46,
fontWeight: FontWeight.w800,
Expand Down Expand Up @@ -154,13 +154,23 @@ class ExampleSidebarX extends StatelessWidget {
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorite',
label: 'Favorites',
),
const SidebarXItem(
iconWidget: FlutterLogo(size: 20),
label: 'Flutter',
),
],
footerItems: const [
SidebarXItem(
icon: Icons.person,
label: 'Profile',
),
SidebarXItem(
icon: Icons.settings,
label: 'Settings',
),
],
);
}
}
Expand Down Expand Up @@ -198,7 +208,7 @@ class _ScreensExample extends StatelessWidget {
default:
return Text(
pageTitle,
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
}
},
Expand All @@ -218,6 +228,10 @@ String _getTitleByIndex(int index) {
return 'Favorites';
case 4:
return 'Custom iconWidget';
case 5:
return 'Profile';
case 6:
return 'Settings';
default:
return 'Not found page';
}
Expand Down
31 changes: 31 additions & 0 deletions lib/src/sidebarx_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SidebarX extends StatefulWidget {
Key? key,
required this.controller,
this.items = const [],
this.footerItems = const [],
this.theme = const SidebarXTheme(),
this.extendedTheme,
this.headerBuilder,
Expand All @@ -29,6 +30,7 @@ class SidebarX extends StatefulWidget {
final SidebarXTheme? extendedTheme;

final List<SidebarXItem> items;
final List<SidebarXItem> footerItems;

/// Controller to interact with Sidebar from code
final SidebarXController controller;
Expand Down Expand Up @@ -144,6 +146,35 @@ class _SidebarXState extends State<SidebarX>
widget.footerDivider ?? const SizedBox(),
widget.footerBuilder?.call(context, widget.controller.extended) ??
const SizedBox(),
Expanded(
child: ListView.separated(
reverse: true,
itemCount: widget.footerItems.length,
separatorBuilder: widget.separatorBuilder ??
(_, __) => const SizedBox(height: 8),
itemBuilder: (context, index) {
final item = widget.footerItems.reversed.toList()[index];
return SidebarXCell(
item: item,
theme: t,
animationController: _animationController!,
extended: widget.controller.extended,
selected: widget.controller.selectedIndex ==
widget.items.length +
widget.footerItems.length -
index -
1,
Comment on lines +159 to +163
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part same

onTap: () {
item.onTap?.call();
widget.controller.selectIndex(widget.items.length +
widget.footerItems.length -
index -
1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part can be extracted

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract this code in method

},
);
},
),
),
if (widget.showToggleButton)
_buildToggleButton(t, widget.collapseIcon, widget.extendIcon),
],
Expand Down