mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +00:00
Add a connection checker
This commit is contained in:
parent
0e35c370ba
commit
37cdf23ae1
35
lib/api.dart
35
lib/api.dart
@ -72,6 +72,41 @@ class InvenTreeAPI {
|
||||
// Authentication token (initially empty, must be requested)
|
||||
String _token = "";
|
||||
|
||||
bool isConnected() {
|
||||
return _token.isNotEmpty;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check server connection and display messages if not connected.
|
||||
* Useful as a precursor check before performing operations.
|
||||
*/
|
||||
bool checkConnection(BuildContext context) {
|
||||
|
||||
// Firstly, is the server connected?
|
||||
if (!isConnected()) {
|
||||
showDialog(
|
||||
context: context,
|
||||
child: new SimpleDialog(
|
||||
title: new Text("Not Connected"),
|
||||
children: <Widget> [
|
||||
ListTile(
|
||||
title: Text("Server not connected"),
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the server version too old?
|
||||
// TODO
|
||||
|
||||
// Finally
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// Server instance information
|
||||
String instance = '';
|
||||
|
||||
|
@ -179,18 +179,27 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
}
|
||||
|
||||
void _search() {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
// TODO
|
||||
}
|
||||
|
||||
void _scan() {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
scanQrCode(context);
|
||||
}
|
||||
|
||||
void _parts() {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
|
||||
}
|
||||
|
||||
void _stock() {
|
||||
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
import 'package:InvenTree/api.dart';
|
||||
import 'package:InvenTree/barcode.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:InvenTree/api.dart';
|
||||
|
||||
import 'package:InvenTree/widget/category_display.dart';
|
||||
import 'package:InvenTree/widget/location_display.dart';
|
||||
|
||||
@ -33,6 +36,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
||||
* Upon successful scan, data are passed off to be decoded.
|
||||
*/
|
||||
void _scan() async {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
_closeDrawer();
|
||||
scanQrCode(context);
|
||||
@ -42,6 +46,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
||||
* Display the top-level PartCategory list
|
||||
*/
|
||||
void _showParts() {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
|
||||
_closeDrawer();
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null)));
|
||||
@ -51,6 +56,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
||||
* Display the top-level StockLocation list
|
||||
*/
|
||||
void _showStock() {
|
||||
if (!InvenTreeAPI().checkConnection(context)) return;
|
||||
_closeDrawer();
|
||||
Navigator.push(context, MaterialPageRoute(builder: (context) => LocationDisplayWidget(null)));
|
||||
}
|
||||
@ -72,6 +78,7 @@ class InvenTreeDrawer extends StatelessWidget {
|
||||
leading: new Image.asset(
|
||||
"assets/image/icon.png",
|
||||
fit: BoxFit.scaleDown,
|
||||
width: 40,
|
||||
),
|
||||
title: new Text("InvenTree"),
|
||||
onTap: _home,
|
||||
|
Loading…
x
Reference in New Issue
Block a user