From 3fa68ec6da9a57f52eda633d4d3be2cf2f3f4540 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 10:27:04 +1000 Subject: [PATCH 01/10] The "search" window is now a tab on the main screen --- lib/api.dart | 3 ++ lib/l10n/app_en.arb | 6 +++ lib/widget/category_display.dart | 1 - lib/widget/home.dart | 84 ++++++++++++++++++++++---------- lib/widget/search.dart | 4 +- 5 files changed, 70 insertions(+), 28 deletions(-) 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( From b6a5af08d8ff0ec37669504b0c556d13cf779a7a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 10:29:44 +1000 Subject: [PATCH 02/10] Fix title for stock items list --- lib/widget/stock_list.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widget/stock_list.dart b/lib/widget/stock_list.dart index b78cdf18..09d0dc3a 100644 --- a/lib/widget/stock_list.dart +++ b/lib/widget/stock_list.dart @@ -28,7 +28,7 @@ class _StockListState extends RefreshableState { final Map filters; @override - String getAppBarTitle(BuildContext context) => L10().purchaseOrders; + String getAppBarTitle(BuildContext context) => L10().stockItems; @override Widget getBody(BuildContext context) { From a3597c5d617f45a1ebe206136536356cba8e38c3 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 10:42:33 +1000 Subject: [PATCH 03/10] Allow search widget to be constructed with or without an app bar --- lib/widget/drawer.dart | 2 +- lib/widget/home.dart | 3 +-- lib/widget/refreshable_state.dart | 14 +++++++++----- lib/widget/search.dart | 23 ++++++++++++++++++++--- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/widget/drawer.dart b/lib/widget/drawer.dart index 871b5112..85a30259 100644 --- a/lib/widget/drawer.dart +++ b/lib/widget/drawer.dart @@ -41,7 +41,7 @@ class InvenTreeDrawer extends StatelessWidget { Navigator.push( context, MaterialPageRoute( - builder: (context) => SearchWidget() + builder: (context) => SearchWidget(true) ) ); } diff --git a/lib/widget/home.dart b/lib/widget/home.dart index f8c4c6d3..04cc0df3 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -55,7 +55,6 @@ class _InvenTreeHomePageState extends State { // Selected user profile UserProfile? _profile; - void _scan(BuildContext context) { if (!InvenTreeAPI().checkConnection(context)) return; @@ -316,7 +315,7 @@ class _InvenTreeHomePageState extends State { Widget getBody(BuildContext context) { switch (_tabIndex) { case 1: // Search widget - return SearchWidget(); + return SearchWidget(false); case 2: // Notification widget case 0: // Home widget default: diff --git a/lib/widget/refreshable_state.dart b/lib/widget/refreshable_state.dart index fe318caa..35185690 100644 --- a/lib/widget/refreshable_state.dart +++ b/lib/widget/refreshable_state.dart @@ -80,6 +80,14 @@ abstract class RefreshableState extends State { return null; } + AppBar? buildAppBar(BuildContext context) { + return AppBar( + title: Text(getAppBarTitle(context)), + actions: getAppBarActions(context), + leading: backButton(context, refreshableKey), + ); + } + @override Widget build(BuildContext context) { @@ -88,11 +96,7 @@ abstract class RefreshableState extends State { return Scaffold( key: refreshableKey, - appBar: AppBar( - title: Text(getAppBarTitle(context)), - actions: getAppBarActions(context), - leading: backButton(context, refreshableKey), - ), + appBar: buildAppBar(context), drawer: getDrawer(context), floatingActionButton: getFab(context), body: Builder( diff --git a/lib/widget/search.dart b/lib/widget/search.dart index d0fadae4..0705ea5c 100644 --- a/lib/widget/search.dart +++ b/lib/widget/search.dart @@ -21,16 +21,33 @@ import "package:inventree/widget/location_list.dart"; // Widget for performing database-wide search class SearchWidget extends StatefulWidget { + SearchWidget(this.hasAppbar); + + final bool hasAppbar; + @override - _SearchDisplayState createState() => _SearchDisplayState(); + _SearchDisplayState createState() => _SearchDisplayState(hasAppbar); } -class _SearchDisplayState extends State { +class _SearchDisplayState extends RefreshableState { + + _SearchDisplayState(this.hasAppBar) : super(); + + final bool hasAppBar; @override String getAppBarTitle(BuildContext context) => L10().search; + @override + AppBar? buildAppBar(BuildContext context) { + if (hasAppBar) { + return super.buildAppBar(context); + } else { + return null; + } + } + final TextEditingController searchController = TextEditingController(); Timer? debounceTimer; @@ -333,7 +350,7 @@ class _SearchDisplayState extends State { } @override - Widget build(BuildContext context) { + Widget getBody(BuildContext context) { return Center( child: ListView( children: ListTile.divideTiles( From b8857f2dbeea7c1a18e3170ca5eec6983d090964 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 10:50:51 +1000 Subject: [PATCH 04/10] Adds skeleton widget for displayign notifications --- lib/widget/home.dart | 16 +++++----- lib/widget/notifications.dart | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 lib/widget/notifications.dart diff --git a/lib/widget/home.dart b/lib/widget/home.dart index 04cc0df3..d5e7ebfb 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -2,23 +2,24 @@ import "package:flutter/material.dart"; import "package:font_awesome_flutter/font_awesome_flutter.dart"; +import "package:inventree/api.dart"; import "package:inventree/app_colors.dart"; +import "package:inventree/app_settings.dart"; +import "package:inventree/barcode.dart"; +import "package:inventree/l10.dart"; +import "package:inventree/settings/login.dart"; import "package:inventree/settings/settings.dart"; import "package:inventree/user_profile.dart"; -import "package:inventree/l10.dart"; -import "package:inventree/barcode.dart"; -import "package:inventree/api.dart"; -import "package:inventree/settings/login.dart"; + import "package:inventree/widget/category_display.dart"; import "package:inventree/widget/company_list.dart"; +import "package:inventree/widget/drawer.dart"; import "package:inventree/widget/location_display.dart"; +import "package:inventree/widget/notifications.dart"; import "package:inventree/widget/part_list.dart"; import "package:inventree/widget/purchase_order_list.dart"; import "package:inventree/widget/search.dart"; import "package:inventree/widget/snacks.dart"; -import "package:inventree/widget/drawer.dart"; - -import "package:inventree/app_settings.dart"; class InvenTreeHomePage extends StatefulWidget { @@ -317,6 +318,7 @@ class _InvenTreeHomePageState extends State { case 1: // Search widget return SearchWidget(false); case 2: // Notification widget + return NotificationWidget(); case 0: // Home widget default: return ListView( diff --git a/lib/widget/notifications.dart b/lib/widget/notifications.dart new file mode 100644 index 00000000..9db91478 --- /dev/null +++ b/lib/widget/notifications.dart @@ -0,0 +1,57 @@ + + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:inventree/widget/refreshable_state.dart'; + +class NotificationWidget extends StatefulWidget { + + @override + _NotificationState createState() => _NotificationState(); + +} + + +class _NotificationState extends RefreshableState { + + _NotificationState() : super(); + + @override + AppBar? buildAppBar(BuildContext context) { + // No app bar for the notification widget + return null; + } + + @override + Future request (BuildContext context) async { + print("requesting notifications!"); + } + + List renderNotifications(BuildContext context) { + + List tiles = []; + + tiles.add( + ListTile( + title: Text("Not"), + subtitle: Text("subtitle yatyayaya"), + ) + ); + + return tiles; + + } + + @override + Widget getBody(BuildContext context) { + return Center( + child: ListView( + children: ListTile.divideTiles( + context: context, + tiles: renderNotifications(context), + ).toList() + ) + ); + } + +} \ No newline at end of file From 6bbae67482b98626b4cdd1d26d018e4646d0ffb7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 11:11:29 +1000 Subject: [PATCH 05/10] Add model for notifications - Display a list of active notifications --- lib/inventree/notification.dart | 31 ++++++++++++++++++++++ lib/l10n/app_en.arb | 3 +++ lib/widget/notifications.dart | 47 ++++++++++++++++++++++++++++----- 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 lib/inventree/notification.dart diff --git a/lib/inventree/notification.dart b/lib/inventree/notification.dart new file mode 100644 index 00000000..2a09965e --- /dev/null +++ b/lib/inventree/notification.dart @@ -0,0 +1,31 @@ +import "package:inventree/inventree/model.dart"; + +/* + * Class representing a "notification" + */ + +class InvenTreeNotification extends InvenTreeModel { + + InvenTreeNotification() : super(); + + InvenTreeNotification.fromJson(Map json) : super.fromJson(json); + + @override + InvenTreeNotification createFromJson(Map json) { + return InvenTreeNotification.fromJson(json); + } + + @override + String get URL => "notifications/"; + + String get message => (jsondata["message"] ?? "") as String; + + DateTime? get creationDate { + if (jsondata.containsKey("creation")) { + return DateTime.tryParse((jsondata["creation"] ?? "") as String); + } else { + return null; + } + } + +} \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index cc6b2791..a21ea567 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -467,6 +467,9 @@ "notifications": "Notifications", "@notifications": {}, + "notificationsEmpty": "No unread notifications", + "@notificationsEmpty": {}, + "noResponse": "No Response from Server", "@noResponse": {}, diff --git a/lib/widget/notifications.dart b/lib/widget/notifications.dart index 9db91478..f86ed086 100644 --- a/lib/widget/notifications.dart +++ b/lib/widget/notifications.dart @@ -1,8 +1,15 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:inventree/widget/refreshable_state.dart'; +import "package:flutter/cupertino.dart"; +import "package:flutter/material.dart"; + +import "package:font_awesome_flutter/font_awesome_flutter.dart"; + +import "package:inventree/l10.dart"; +import "package:inventree/inventree/model.dart"; +import "package:inventree/inventree/notification.dart"; +import "package:inventree/widget/refreshable_state.dart"; + class NotificationWidget extends StatefulWidget { @@ -16,6 +23,8 @@ class _NotificationState extends RefreshableState { _NotificationState() : super(); + List notifications = []; + @override AppBar? buildAppBar(BuildContext context) { // No app bar for the notification widget @@ -24,7 +33,14 @@ class _NotificationState extends RefreshableState { @override Future request (BuildContext context) async { - print("requesting notifications!"); + + final results = await InvenTreeNotification().list(); + + for (InvenTreeModel n in results) { + if (n is InvenTreeNotification) { + notifications.add(n); + } + } } List renderNotifications(BuildContext context) { @@ -33,11 +49,30 @@ class _NotificationState extends RefreshableState { tiles.add( ListTile( - title: Text("Not"), - subtitle: Text("subtitle yatyayaya"), + title: Text( + L10().notifications, + ), + subtitle: notifications.isEmpty ? Text(L10().notificationsEmpty) : null, + leading: notifications.isEmpty ? FaIcon(FontAwesomeIcons.bellSlash) : FaIcon(FontAwesomeIcons.bell), + trailing: Text("${notifications.length}"), ) ); + for (var notification in notifications) { + tiles.add( + ListTile( + title: Text(notification.name), + subtitle: Text(notification.message), + trailing: IconButton( + icon: FaIcon(FontAwesomeIcons.bookmark), + onPressed: () async { + + }, + ), + ) + ); + } + return tiles; } From 020f006410651a1dc83200ac6cb280b30b25293c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 11:21:52 +1000 Subject: [PATCH 06/10] Adds ability to "dismiss" a notification --- lib/inventree/notification.dart | 20 ++++++++++++++++++++ lib/inventree/stock.dart | 4 ++-- lib/widget/notifications.dart | 12 +++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/inventree/notification.dart b/lib/inventree/notification.dart index 2a09965e..dae7e676 100644 --- a/lib/inventree/notification.dart +++ b/lib/inventree/notification.dart @@ -18,6 +18,15 @@ class InvenTreeNotification extends InvenTreeModel { @override String get URL => "notifications/"; + @override + Map defaultListFilters() { + + // By default, only return 'unread' notifications + return { + "read": "false", + }; + } + String get message => (jsondata["message"] ?? "") as String; DateTime? get creationDate { @@ -28,4 +37,15 @@ class InvenTreeNotification extends InvenTreeModel { } } + /* + * Dismiss this notification (mark as read) + */ + Future dismiss() async { + + final response = await api.post( + "${url}read/", + ); + + } + } \ No newline at end of file diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index 45808d2d..3dc4f2b1 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -533,7 +533,7 @@ class InvenTreeStockItem extends InvenTreeModel { Map data = {}; // Note: Format of adjustment API was updated in API v14 - if (InvenTreeAPI().supportModernStockTransactions()) { + if (api.supportModernStockTransactions()) { // Modern (> 14) API data = { "items": [ @@ -560,7 +560,7 @@ class InvenTreeStockItem extends InvenTreeModel { } // Expected API return code depends on server API version - final int expected_response = InvenTreeAPI().supportModernStockTransactions() ? 201 : 200; + final int expected_response = api.supportModernStockTransactions() ? 201 : 200; var response = await api.post( endpoint, diff --git a/lib/widget/notifications.dart b/lib/widget/notifications.dart index f86ed086..a37d9d3d 100644 --- a/lib/widget/notifications.dart +++ b/lib/widget/notifications.dart @@ -36,6 +36,8 @@ class _NotificationState extends RefreshableState { final results = await InvenTreeNotification().list(); + notifications.clear(); + for (InvenTreeModel n in results) { if (n is InvenTreeNotification) { notifications.add(n); @@ -43,6 +45,14 @@ class _NotificationState extends RefreshableState { } } + Future dismissNotification(BuildContext context, InvenTreeNotification notification) async { + + await notification.dismiss(); + + refresh(context); + + } + List renderNotifications(BuildContext context) { List tiles = []; @@ -66,7 +76,7 @@ class _NotificationState extends RefreshableState { trailing: IconButton( icon: FaIcon(FontAwesomeIcons.bookmark), onPressed: () async { - + dismissNotification(context, notification); }, ), ) From a36a251f239c282d35099128d8c995b81c88201f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 11:26:47 +1000 Subject: [PATCH 07/10] Remove debug message --- lib/widget/back.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/widget/back.dart b/lib/widget/back.dart index 04f03255..9797e4b7 100644 --- a/lib/widget/back.dart +++ b/lib/widget/back.dart @@ -12,7 +12,6 @@ Widget backButton(BuildContext context, GlobalKey key) { onLongPress: () { // Display the menu key.currentState!.openDrawer(); - print("hello?"); }, child: IconButton( icon: BackButtonIcon(), From 6533cc4af60fc09241ea53fbe6f34e03f5db47e7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 11:41:53 +1000 Subject: [PATCH 08/10] Display badge showing current number of unread notifications --- lib/api.dart | 1 + lib/widget/home.dart | 60 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 9c2674b2..ee8a6132 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -431,6 +431,7 @@ class InvenTreeAPI { // Return the received token _token = (data["token"] ?? "") as String; + print("Received token - $_token"); // Request user role information (async) diff --git a/lib/widget/home.dart b/lib/widget/home.dart index d5e7ebfb..f9c3c256 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -1,3 +1,5 @@ +import "dart:async"; + import "package:flutter/material.dart"; import "package:font_awesome_flutter/font_awesome_flutter.dart"; @@ -11,6 +13,9 @@ import "package:inventree/settings/login.dart"; import "package:inventree/settings/settings.dart"; import "package:inventree/user_profile.dart"; +import "package:inventree/inventree/model.dart"; +import "package:inventree/inventree/notification.dart"; + import "package:inventree/widget/category_display.dart"; import "package:inventree/widget/company_list.dart"; import "package:inventree/widget/drawer.dart"; @@ -33,18 +38,29 @@ class InvenTreeHomePage extends StatefulWidget { class _InvenTreeHomePageState extends State { _InvenTreeHomePageState() : super() { - // Load display settings _loadSettings(); // Initially load the profile and attempt server connection _loadProfile(); + _refreshNotifications(); + + // Refresh notifications every ~30 seconds + Timer.periodic( + Duration( + milliseconds: 30000, + ), (timer) { + _refreshNotifications(); + }); } // Index of bottom navigation bar int _tabIndex = 0; + // Number of outstanding notifications + int _notificationCounter = 0; + bool homeShowPo = false; bool homeShowSubscribed = false; bool homeShowManufacturers = false; @@ -160,6 +176,18 @@ class _InvenTreeHomePageState extends State { setState(() {}); } + /* + * Refresh the number of active notifications for this user + */ + Future _refreshNotifications() async { + + final notifications = await InvenTreeNotification().list(); + + setState(() { + _notificationCounter = notifications.length; + }); + } + Widget _listTile(BuildContext context, String label, IconData icon, {Function()? callback, String role = "", String permission = ""}) { @@ -347,7 +375,33 @@ class _InvenTreeHomePageState extends State { if (InvenTreeAPI().supportsNotifications) { items.add( BottomNavigationBarItem( - icon: FaIcon(FontAwesomeIcons.bell), + icon: _notificationCounter == 0 ? FaIcon(FontAwesomeIcons.bell) : Stack( + children: [ + FaIcon(FontAwesomeIcons.bell), + new Positioned( + right: 0, + child: new Container( + padding: EdgeInsets.all(2), + decoration: new BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(20), + ), + constraints: BoxConstraints( + minWidth: 12, + minHeight: 12, + ), + child: new Text( + "${_notificationCounter}", + style: new TextStyle( + color: Colors.white, + fontSize: 9, + ), + textAlign: TextAlign.center, + ), + ), + ) + ], + ), label: L10().notifications, ) ); @@ -381,6 +435,8 @@ class _InvenTreeHomePageState extends State { setState(() { _tabIndex = index; }); + + _refreshNotifications(); }, items: getNavBarItems(context), ), From 7ef7096e2654958cc4a14479e8816790a44359f1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 11:53:11 +1000 Subject: [PATCH 09/10] Updates to search controller --- lib/l10n/app_en.arb | 3 +++ lib/widget/home.dart | 10 +++++----- lib/widget/notifications.dart | 2 -- lib/widget/search.dart | 9 ++++++--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index a21ea567..cf9a2753 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -640,6 +640,9 @@ "quantityPositive": "Quantity must be positive", "@quantityPositive": {}, + "queryEmpty": "Enter search query", + "@queryEmpty": {}, + "queryNoResults": "No results for query", "@queryNoResults": {}, diff --git a/lib/widget/home.dart b/lib/widget/home.dart index f9c3c256..d526339d 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -378,11 +378,11 @@ class _InvenTreeHomePageState extends State { icon: _notificationCounter == 0 ? FaIcon(FontAwesomeIcons.bell) : Stack( children: [ FaIcon(FontAwesomeIcons.bell), - new Positioned( + Positioned( right: 0, - child: new Container( + child: Container( padding: EdgeInsets.all(2), - decoration: new BoxDecoration( + decoration: BoxDecoration( color: Colors.red, borderRadius: BorderRadius.circular(20), ), @@ -390,9 +390,9 @@ class _InvenTreeHomePageState extends State { minWidth: 12, minHeight: 12, ), - child: new Text( + child: Text( "${_notificationCounter}", - style: new TextStyle( + style: TextStyle( color: Colors.white, fontSize: 9, ), diff --git a/lib/widget/notifications.dart b/lib/widget/notifications.dart index a37d9d3d..8c03343b 100644 --- a/lib/widget/notifications.dart +++ b/lib/widget/notifications.dart @@ -1,6 +1,4 @@ - -import "package:flutter/cupertino.dart"; import "package:flutter/material.dart"; import "package:font_awesome_flutter/font_awesome_flutter.dart"; diff --git a/lib/widget/search.dart b/lib/widget/search.dart index 0705ea5c..2d21fc66 100644 --- a/lib/widget/search.dart +++ b/lib/widget/search.dart @@ -21,7 +21,7 @@ import "package:inventree/widget/location_list.dart"; // Widget for performing database-wide search class SearchWidget extends StatefulWidget { - SearchWidget(this.hasAppbar); + const SearchWidget(this.hasAppbar); final bool hasAppbar; @@ -172,12 +172,15 @@ class _SearchDisplayState extends RefreshableState { child: ListTile( title: TextField( readOnly: false, + decoration: InputDecoration( + helperText: L10().queryEmpty, + ), controller: searchController, onChanged: (String text) { onSearchTextChanged(text); }, ), - leading: IconButton( + trailing: IconButton( icon: FaIcon(FontAwesomeIcons.backspace, color: Colors.red), onPressed: () { searchController.clear(); @@ -332,7 +335,7 @@ class _SearchDisplayState extends RefreshableState { ); } - if (results.isEmpty) { + if (results.isEmpty && searchController.text.isNotEmpty) { tiles.add( ListTile( title: Text(L10().queryNoResults), From 407250c33640a10e141e8306db293deb1bad8432 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 4 May 2022 12:17:55 +1000 Subject: [PATCH 10/10] Further linting fixes --- lib/inventree/notification.dart | 2 +- lib/widget/home.dart | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/inventree/notification.dart b/lib/inventree/notification.dart index dae7e676..c6b74049 100644 --- a/lib/inventree/notification.dart +++ b/lib/inventree/notification.dart @@ -42,7 +42,7 @@ class InvenTreeNotification extends InvenTreeModel { */ Future dismiss() async { - final response = await api.post( + await api.post( "${url}read/", ); diff --git a/lib/widget/home.dart b/lib/widget/home.dart index d526339d..712b4e2e 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -13,7 +13,6 @@ import "package:inventree/settings/login.dart"; import "package:inventree/settings/settings.dart"; import "package:inventree/user_profile.dart"; -import "package:inventree/inventree/model.dart"; import "package:inventree/inventree/notification.dart"; import "package:inventree/widget/category_display.dart";