mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +00:00 
			
		
		
		
	Allow search widget to be constructed with or without an app bar
This commit is contained in:
		| @@ -41,7 +41,7 @@ class InvenTreeDrawer extends StatelessWidget { | |||||||
|     Navigator.push( |     Navigator.push( | ||||||
|         context, |         context, | ||||||
|         MaterialPageRoute( |         MaterialPageRoute( | ||||||
|             builder: (context) => SearchWidget() |             builder: (context) => SearchWidget(true) | ||||||
|         ) |         ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -55,7 +55,6 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | |||||||
|   // Selected user profile |   // Selected user profile | ||||||
|   UserProfile? _profile; |   UserProfile? _profile; | ||||||
|  |  | ||||||
|  |  | ||||||
|   void _scan(BuildContext context) { |   void _scan(BuildContext context) { | ||||||
|     if (!InvenTreeAPI().checkConnection(context)) return; |     if (!InvenTreeAPI().checkConnection(context)) return; | ||||||
|  |  | ||||||
| @@ -316,7 +315,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | |||||||
|   Widget getBody(BuildContext context) { |   Widget getBody(BuildContext context) { | ||||||
|     switch (_tabIndex) { |     switch (_tabIndex) { | ||||||
|       case 1: // Search widget |       case 1: // Search widget | ||||||
|         return SearchWidget(); |         return SearchWidget(false); | ||||||
|       case 2: // Notification widget |       case 2: // Notification widget | ||||||
|       case 0: // Home widget |       case 0: // Home widget | ||||||
|       default: |       default: | ||||||
|   | |||||||
| @@ -80,6 +80,14 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> { | |||||||
|     return null; |     return null; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   AppBar? buildAppBar(BuildContext context) { | ||||||
|  |     return AppBar( | ||||||
|  |       title: Text(getAppBarTitle(context)), | ||||||
|  |       actions: getAppBarActions(context), | ||||||
|  |       leading: backButton(context, refreshableKey), | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget build(BuildContext context) { | ||||||
|  |  | ||||||
| @@ -88,11 +96,7 @@ abstract class RefreshableState<T extends StatefulWidget> extends State<T> { | |||||||
|  |  | ||||||
|     return Scaffold( |     return Scaffold( | ||||||
|       key: refreshableKey, |       key: refreshableKey, | ||||||
|       appBar: AppBar( |       appBar: buildAppBar(context), | ||||||
|         title: Text(getAppBarTitle(context)), |  | ||||||
|         actions: getAppBarActions(context), |  | ||||||
|         leading: backButton(context, refreshableKey), |  | ||||||
|       ), |  | ||||||
|       drawer: getDrawer(context), |       drawer: getDrawer(context), | ||||||
|       floatingActionButton: getFab(context), |       floatingActionButton: getFab(context), | ||||||
|       body: Builder( |       body: Builder( | ||||||
|   | |||||||
| @@ -21,16 +21,33 @@ import "package:inventree/widget/location_list.dart"; | |||||||
| // Widget for performing database-wide search | // Widget for performing database-wide search | ||||||
| class SearchWidget extends StatefulWidget { | class SearchWidget extends StatefulWidget { | ||||||
|  |  | ||||||
|  |   SearchWidget(this.hasAppbar); | ||||||
|  |  | ||||||
|  |   final bool hasAppbar; | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   _SearchDisplayState createState() => _SearchDisplayState(); |   _SearchDisplayState createState() => _SearchDisplayState(hasAppbar); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| class _SearchDisplayState extends State<SearchWidget> { | class _SearchDisplayState extends RefreshableState<SearchWidget> { | ||||||
|  |  | ||||||
|  |   _SearchDisplayState(this.hasAppBar) : super(); | ||||||
|  |  | ||||||
|  |   final bool hasAppBar; | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   String getAppBarTitle(BuildContext context) => L10().search; |   String getAppBarTitle(BuildContext context) => L10().search; | ||||||
|  |  | ||||||
|  |   @override | ||||||
|  |   AppBar? buildAppBar(BuildContext context) { | ||||||
|  |     if (hasAppBar) { | ||||||
|  |       return super.buildAppBar(context); | ||||||
|  |     } else { | ||||||
|  |       return null; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   final TextEditingController searchController = TextEditingController(); |   final TextEditingController searchController = TextEditingController(); | ||||||
|  |  | ||||||
|   Timer? debounceTimer; |   Timer? debounceTimer; | ||||||
| @@ -333,7 +350,7 @@ class _SearchDisplayState extends State<SearchWidget> { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   Widget build(BuildContext context) { |   Widget getBody(BuildContext context) { | ||||||
|     return Center( |     return Center( | ||||||
|       child: ListView( |       child: ListView( | ||||||
|         children: ListTile.divideTiles( |         children: ListTile.divideTiles( | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user