From 347d2175be26e6d1ab1f5cd7ca1b68a6312d7477 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 9 May 2022 20:37:57 +1000 Subject: [PATCH] Display a "launch" screen if server is not connected --- lib/api.dart | 4 ++++ lib/l10n/app_en.arb | 3 +++ lib/widget/home.dart | 43 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index ee8a6132..aa9b73b6 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -193,6 +193,7 @@ class InvenTreeAPI { UserProfile? profile; + // Available user roles (permissions) are loaded when connecting to the server Map roles = {}; // Authentication token (initially empty, must be requested) @@ -454,6 +455,9 @@ class InvenTreeAPI { profile = null; } + /* + * Public facing connection function + */ Future connectToServer() async { // Ensure server is first disconnected diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index cf9a2753..56371b44 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -608,6 +608,9 @@ "profileSelect": "Select InvenTree Server", "@profileSelect": {}, + "profileSelectOrCreate": "Select server or create a new profile", + "@profileSelectOrCreate": {}, + "profileTapToCreate": "Tap to create or select a profile", "@profileTapToCreate": {}, diff --git a/lib/widget/home.dart b/lib/widget/home.dart index 712b4e2e..eefd9c64 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -229,6 +229,9 @@ class _InvenTreeHomePageState extends State { ); } + /* + * Constructs a list of tiles for the main screen + */ List getListTiles(BuildContext context) { List tiles = []; @@ -336,11 +339,43 @@ class _InvenTreeHomePageState extends State { return tiles; } + /* + * If the app is not connected to an InvenTree server, + * display a connection status widget + */ + Widget _connectionStatusWidget(BuildContext context) { + return Center( + child: Column( + children: [ + Image.asset( + "assets/image/icon.png", + color: Colors.white.withOpacity(0.2), + colorBlendMode: BlendMode.modulate, + scale: 0.5, + ), + Spacer(), + ListTile( + title: Text(L10().serverNotConnected), + subtitle: Text(L10().profileSelectOrCreate), + trailing: FaIcon(FontAwesomeIcons.server, color: COLOR_CLICK), + leading: FaIcon(FontAwesomeIcons.exclamationCircle, color: COLOR_DANGER), + onTap: _selectProfile, + ) + ] + ), + ); + } + /* * Return the main body widget for display. * This depends on the current value of _tabIndex */ Widget getBody(BuildContext context) { + + if (!InvenTreeAPI().isConnected()) { + return _connectionStatusWidget(context); + } + switch (_tabIndex) { case 1: // Search widget return SearchWidget(false); @@ -412,6 +447,8 @@ class _InvenTreeHomePageState extends State { @override Widget build(BuildContext context) { + var connected = InvenTreeAPI().isConnected(); + return Scaffold( key: _homeKey, appBar: AppBar( @@ -420,7 +457,7 @@ class _InvenTreeHomePageState extends State { IconButton( icon: FaIcon( FontAwesomeIcons.server, - color: InvenTreeAPI().isConnected() ? COLOR_SUCCESS : COLOR_DANGER, + color: connected ? COLOR_SUCCESS : COLOR_DANGER, ), onPressed: _selectProfile, ) @@ -428,7 +465,7 @@ class _InvenTreeHomePageState extends State { ), drawer: InvenTreeDrawer(context), body: getBody(context), - bottomNavigationBar: BottomNavigationBar( + bottomNavigationBar: connected ? BottomNavigationBar( currentIndex: _tabIndex, onTap: (int index) { setState(() { @@ -438,7 +475,7 @@ class _InvenTreeHomePageState extends State { _refreshNotifications(); }, items: getNavBarItems(context), - ), + ) : null, ); } }