diff --git a/lib/api.dart b/lib/api.dart index 71af9cbe..9c2674b2 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -230,6 +230,9 @@ class InvenTreeAPI { int get apiVersion => _apiVersion; + // Notification support requires API v25 or newer + bool get supportsNotifications => isConnected() && apiVersion >= 25; + // Are plugins enabled on the server? bool _pluginsEnabled = false; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index dc95339c..cc6b2791 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -308,6 +308,9 @@ "description": "history" }, + "home": "Home", + "@homeScreen": {}, + "homeScreen": "Home Screen", "@homeScreen": {}, @@ -461,6 +464,9 @@ "description": "Notes" }, + "notifications": "Notifications", + "@notifications": {}, + "noResponse": "No Response from Server", "@noResponse": {}, diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 8cd5081b..2ce7e02d 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -174,7 +174,6 @@ class _CategoryDisplayState extends RefreshableState { icon: FaIcon(FontAwesomeIcons.shapes), label: L10().parts, ), - // TODO - Add the "actions" item back in BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.wrench), label: L10().actions diff --git a/lib/widget/home.dart b/lib/widget/home.dart index 20349f73..f8c4c6d3 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -41,6 +41,9 @@ class _InvenTreeHomePageState extends State { } + // Index of bottom navigation bar + int _tabIndex = 0; + bool homeShowPo = false; bool homeShowSubscribed = false; bool homeShowManufacturers = false; @@ -52,17 +55,6 @@ class _InvenTreeHomePageState extends State { // Selected user profile UserProfile? _profile; - void _search(BuildContext context) { - if (!InvenTreeAPI().checkConnection(context)) return; - - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => SearchWidget() - ) - ); - - } void _scan(BuildContext context) { if (!InvenTreeAPI().checkConnection(context)) return; @@ -224,16 +216,6 @@ class _InvenTreeHomePageState extends State { } )); - // Search widget - tiles.add(_listTile( - context, - L10().search, - FontAwesomeIcons.search, - callback: () { - _search(context); - } - )); - // Parts tiles.add(_listTile( context, @@ -327,6 +309,52 @@ class _InvenTreeHomePageState extends State { return tiles; } + /* + * Return the main body widget for display. + * This depends on the current value of _tabIndex + */ + Widget getBody(BuildContext context) { + switch (_tabIndex) { + case 1: // Search widget + return SearchWidget(); + case 2: // Notification widget + case 0: // Home widget + default: + return ListView( + scrollDirection: Axis.vertical, + children: getListTiles(context), + ); + } + } + + /* + * Construct the bottom navigation bar + */ + List getNavBarItems(BuildContext context) { + + List items = [ + BottomNavigationBarItem( + icon: FaIcon(FontAwesomeIcons.home), + label: L10().home, + ), + BottomNavigationBarItem( + icon: FaIcon(FontAwesomeIcons.search), + label: L10().search, + ), + ]; + + if (InvenTreeAPI().supportsNotifications) { + items.add( + BottomNavigationBarItem( + icon: FaIcon(FontAwesomeIcons.bell), + label: L10().notifications, + ) + ); + } + + return items; + } + @override Widget build(BuildContext context) { @@ -345,10 +373,16 @@ class _InvenTreeHomePageState extends State { ], ), drawer: InvenTreeDrawer(context), - body: ListView( - scrollDirection: Axis.vertical, - children: getListTiles(context), - ) + body: getBody(context), + bottomNavigationBar: BottomNavigationBar( + currentIndex: _tabIndex, + onTap: (int index) { + setState(() { + _tabIndex = index; + }); + }, + items: getNavBarItems(context), + ), ); } } diff --git a/lib/widget/search.dart b/lib/widget/search.dart index 77258d43..d0fadae4 100644 --- a/lib/widget/search.dart +++ b/lib/widget/search.dart @@ -26,7 +26,7 @@ class SearchWidget extends StatefulWidget { } -class _SearchDisplayState extends RefreshableState { +class _SearchDisplayState extends State { @override String getAppBarTitle(BuildContext context) => L10().search; @@ -333,7 +333,7 @@ class _SearchDisplayState extends RefreshableState { } @override - Widget getBody(BuildContext context) { + Widget build(BuildContext context) { return Center( child: ListView( children: ListTile.divideTiles(