Skip to content

Commit

Permalink
Merge pull request #30 from DavidCatalano/main
Browse files Browse the repository at this point in the history
Footer sidebar items
  • Loading branch information
Frezyx committed Oct 6, 2022
2 parents df616ec + c2889b1 commit e24a771
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 43 deletions.
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
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -350,7 +350,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -399,7 +399,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
22 changes: 16 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,7 @@ class SidebarXExampleApp extends StatelessWidget {
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorite',
label: 'Favorites',
),
],
),
Expand Down Expand Up @@ -148,22 +148,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
22 changes: 16 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,7 @@ class SidebarXExampleApp extends StatelessWidget {
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorite',
label: 'Favorites',
),
],
),
Expand Down Expand Up @@ -162,22 +162,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
10 changes: 7 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,7 +154,7 @@ class ExampleSidebarX extends StatelessWidget {
),
const SidebarXItem(
icon: Icons.favorite,
label: 'Favorite',
label: 'Favorites',
),
const SidebarXItem(
iconWidget: FlutterLogo(size: 20),
Expand Down Expand Up @@ -198,7 +198,7 @@ class _ScreensExample extends StatelessWidget {
default:
return Text(
pageTitle,
style: theme.textTheme.headline5,
style: theme.textTheme.headlineSmall,
);
}
},
Expand All @@ -218,6 +218,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: 12 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,21 +21,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
version: "1.2.1"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
Expand All @@ -49,7 +42,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -80,28 +73,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.8.2"
sidebarx:
dependency: "direct main"
description:
Expand All @@ -120,7 +113,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.2"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -141,21 +134,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.9"
version: "0.4.12"
vector_math:
dependency: transitive
description:
Expand Down
41 changes: 37 additions & 4 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 @@ -133,17 +135,37 @@ class _SidebarXState extends State<SidebarX>
animationController: _animationController!,
extended: widget.controller.extended,
selected: widget.controller.selectedIndex == index,
onTap: () {
item.onTap?.call();
widget.controller.selectIndex(index);
},
onTap: () => _onItemSelected(item, index),
);
},
),
),
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,
onTap: () => _onFooterItemSelected(item, index),
);
},
),
),
if (widget.showToggleButton)
_buildToggleButton(t, widget.collapseIcon, widget.extendIcon),
],
Expand All @@ -153,6 +175,17 @@ class _SidebarXState extends State<SidebarX>
);
}

void _onFooterItemSelected(SidebarXItem item, int index) {
item.onTap?.call();
widget.controller.selectIndex(
widget.items.length + widget.footerItems.length - index - 1);
}

void _onItemSelected(SidebarXItem item, int index) {
item.onTap?.call();
widget.controller.selectIndex(index);
}

Widget _buildToggleButton(
SidebarXTheme sidebarXTheme,
IconData collapseIcon,
Expand Down

0 comments on commit e24a771

Please sign in to comment.