mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Display a "launch" screen if server is not connected
This commit is contained in:
parent
97b4eefc13
commit
347d2175be
@ -193,6 +193,7 @@ class InvenTreeAPI {
|
|||||||
|
|
||||||
UserProfile? profile;
|
UserProfile? profile;
|
||||||
|
|
||||||
|
// Available user roles (permissions) are loaded when connecting to the server
|
||||||
Map<String, dynamic> roles = {};
|
Map<String, dynamic> roles = {};
|
||||||
|
|
||||||
// Authentication token (initially empty, must be requested)
|
// Authentication token (initially empty, must be requested)
|
||||||
@ -454,6 +455,9 @@ class InvenTreeAPI {
|
|||||||
profile = null;
|
profile = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Public facing connection function
|
||||||
|
*/
|
||||||
Future<bool> connectToServer() async {
|
Future<bool> connectToServer() async {
|
||||||
|
|
||||||
// Ensure server is first disconnected
|
// Ensure server is first disconnected
|
||||||
|
@ -608,6 +608,9 @@
|
|||||||
"profileSelect": "Select InvenTree Server",
|
"profileSelect": "Select InvenTree Server",
|
||||||
"@profileSelect": {},
|
"@profileSelect": {},
|
||||||
|
|
||||||
|
"profileSelectOrCreate": "Select server or create a new profile",
|
||||||
|
"@profileSelectOrCreate": {},
|
||||||
|
|
||||||
"profileTapToCreate": "Tap to create or select a profile",
|
"profileTapToCreate": "Tap to create or select a profile",
|
||||||
"@profileTapToCreate": {},
|
"@profileTapToCreate": {},
|
||||||
|
|
||||||
|
@ -229,6 +229,9 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constructs a list of tiles for the main screen
|
||||||
|
*/
|
||||||
List<Widget> getListTiles(BuildContext context) {
|
List<Widget> getListTiles(BuildContext context) {
|
||||||
|
|
||||||
List<Widget> tiles = [];
|
List<Widget> tiles = [];
|
||||||
@ -336,11 +339,43 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
return tiles;
|
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.
|
* Return the main body widget for display.
|
||||||
* This depends on the current value of _tabIndex
|
* This depends on the current value of _tabIndex
|
||||||
*/
|
*/
|
||||||
Widget getBody(BuildContext context) {
|
Widget getBody(BuildContext context) {
|
||||||
|
|
||||||
|
if (!InvenTreeAPI().isConnected()) {
|
||||||
|
return _connectionStatusWidget(context);
|
||||||
|
}
|
||||||
|
|
||||||
switch (_tabIndex) {
|
switch (_tabIndex) {
|
||||||
case 1: // Search widget
|
case 1: // Search widget
|
||||||
return SearchWidget(false);
|
return SearchWidget(false);
|
||||||
@ -412,6 +447,8 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
var connected = InvenTreeAPI().isConnected();
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
key: _homeKey,
|
key: _homeKey,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -420,7 +457,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
IconButton(
|
IconButton(
|
||||||
icon: FaIcon(
|
icon: FaIcon(
|
||||||
FontAwesomeIcons.server,
|
FontAwesomeIcons.server,
|
||||||
color: InvenTreeAPI().isConnected() ? COLOR_SUCCESS : COLOR_DANGER,
|
color: connected ? COLOR_SUCCESS : COLOR_DANGER,
|
||||||
),
|
),
|
||||||
onPressed: _selectProfile,
|
onPressed: _selectProfile,
|
||||||
)
|
)
|
||||||
@ -428,7 +465,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
),
|
),
|
||||||
drawer: InvenTreeDrawer(context),
|
drawer: InvenTreeDrawer(context),
|
||||||
body: getBody(context),
|
body: getBody(context),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: connected ? BottomNavigationBar(
|
||||||
currentIndex: _tabIndex,
|
currentIndex: _tabIndex,
|
||||||
onTap: (int index) {
|
onTap: (int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -438,7 +475,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
|
|||||||
_refreshNotifications();
|
_refreshNotifications();
|
||||||
},
|
},
|
||||||
items: getNavBarItems(context),
|
items: getNavBarItems(context),
|
||||||
),
|
) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user