2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 02:05:29 +00:00

API refactoring:

- Error if the server version is *older* than the min required version
- Display dialog boxes for different server errors
This commit is contained in:
Oliver Walters
2021-02-02 20:37:54 +11:00
parent cfb3dd6506
commit b69762ff15
8 changed files with 133 additions and 76 deletions

View File

@ -2,6 +2,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
void showMessage(BuildContext context, String message) {
Scaffold.of(context).showSnackBar(SnackBar(
@ -9,7 +10,12 @@ void showMessage(BuildContext context, String message) {
));
}
Future<void> showInfoDialog(BuildContext context, String title, String description, {IconData icon = FontAwesomeIcons.info, String info = "Info", Function onDismissed}) async {
Future<void> showInfoDialog(BuildContext context, String title, String description, {IconData icon = FontAwesomeIcons.info, String info, Function onDismissed}) async {
if (info == null || info.isEmpty) {
info = I18N.of(context).info;
}
showDialog(
context: context,
child: SimpleDialog(
@ -31,7 +37,12 @@ Future<void> showInfoDialog(BuildContext context, String title, String descripti
});
}
Future<void> showErrorDialog(BuildContext context, String title, String description, {IconData icon = FontAwesomeIcons.exclamationCircle, String error = "Error", Function onDismissed}) async {
Future<void> showErrorDialog(BuildContext context, String title, String description, {IconData icon = FontAwesomeIcons.exclamationCircle, String error, Function onDismissed}) async {
if (error == null || error.isEmpty) {
error = I18N.of(context).error;
}
showDialog(
context: context,
child: SimpleDialog(

View File

@ -25,7 +25,6 @@ class InvenTreeHomePage extends StatefulWidget {
class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
_InvenTreeHomePageState() : super() {
_checkServerConnection();
}
String _serverAddress = "";
@ -63,7 +62,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
/*
* Test the server connection
*/
void _checkServerConnection() async {
void _checkServerConnection(BuildContext context) async {
var prefs = await SharedPreferences.getInstance();
@ -76,7 +75,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
_serverIcon = new FaIcon(FontAwesomeIcons.spinner);
_serverStatusColor = Color.fromARGB(255, 50, 50, 250);
InvenTreeAPI().connect().then((bool result) {
InvenTreeAPI().connect(context).then((bool result) {
if (result) {
onConnectSuccess("");
@ -322,7 +321,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> {
leading: _serverIcon,
onTap: () {
if (!_serverConnection) {
_checkServerConnection();
_checkServerConnection(context);
}
},
),