From 18b4783c11cfb97cc1af1245523eae1ef0e7a9b9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 9 Feb 2021 09:34:04 +1100 Subject: [PATCH] Slightly improved login info on main screen --- lib/main.dart | 30 +++++++-------- lib/settings/login.dart | 10 ++--- lib/settings/settings.dart | 2 +- lib/widget/home.dart | 76 +++++++++++++++++++++++++++++++------- 4 files changed, 82 insertions(+), 36 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 2c0e410a..f0a14c94 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,12 +8,14 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'dsn.dart'; -import 'preferences.dart'; import 'package:sentry/sentry.dart'; // Use the secret app key -final SentryClient _sentry = SentryClient(dsn: SENTRY_DSN_KEY); +final SentryClient _sentry = SentryClient( + SentryOptions( + dsn: SENTRY_DSN_KEY, + )); bool isInDebugMode() { bool inDebugMode = false; @@ -31,13 +33,15 @@ Future _reportError(dynamic error, dynamic stackTrace) async { print(stackTrace); return; } else { - // Send the Exception and Stacktrace to Sentry in Production mode. - _sentry.captureException( - exception: error, - stackTrace: stackTrace, - ); - - print("Sending error to sentry.io"); + try { + await _sentry.captureException( + error, + stackTrace: stackTrace + ); + } catch (e) { + print("Sending error report to sentry.io failed: ${e}"); + print("Original error: ${error}"); + } } } @@ -47,12 +51,8 @@ void main() async { runZoned>(() async { runApp(InvenTreeApp()); - }, onError: (error, stackTrace) { - // Whenever an error occurs, call the `_reportError` function. This sends - // Dart errors to the dev console or Sentry depending on the environment. - _reportError(error, stackTrace); - }); - + }, onError: _reportError + ); } class InvenTreeApp extends StatelessWidget { diff --git a/lib/settings/login.dart b/lib/settings/login.dart index c4380b98..9ae57d34 100644 --- a/lib/settings/login.dart +++ b/lib/settings/login.dart @@ -10,12 +10,8 @@ import '../user_profile.dart'; class InvenTreeLoginSettingsWidget extends StatefulWidget { - final List _profiles; - - InvenTreeLoginSettingsWidget(this._profiles) : super(); - @override - _InvenTreeLoginSettingsState createState() => _InvenTreeLoginSettingsState(_profiles); + _InvenTreeLoginSettingsState createState() => _InvenTreeLoginSettingsState(); } @@ -27,7 +23,9 @@ class _InvenTreeLoginSettingsState extends State { List profiles; - _InvenTreeLoginSettingsState(this.profiles); + _InvenTreeLoginSettingsState() { + _reload(); + } void _reload() async { diff --git a/lib/settings/settings.dart b/lib/settings/settings.dart index 0661ddff..16604134 100644 --- a/lib/settings/settings.dart +++ b/lib/settings/settings.dart @@ -72,7 +72,7 @@ class _InvenTreeSettingsState extends State { List profiles = await UserProfileDBManager().getAllProfiles(); - Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget(profiles))); + Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget())); } void _about() async { diff --git a/lib/widget/home.dart b/lib/widget/home.dart index c1bc56c6..ae035516 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -9,6 +9,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:InvenTree/barcode.dart'; import 'package:InvenTree/api.dart'; +import 'package:InvenTree/settings/login.dart'; + import 'package:InvenTree/widget/category_display.dart'; import 'package:InvenTree/widget/company_list.dart'; import 'package:InvenTree/widget/location_display.dart'; @@ -25,6 +27,8 @@ class InvenTreeHomePage extends StatefulWidget { class _InvenTreeHomePageState extends State { _InvenTreeHomePageState() : super() { + + _loadProfile(); } String _serverStatus = "Connecting to server"; @@ -37,6 +41,59 @@ class _InvenTreeHomePageState extends State { Color _serverStatusColor = Color.fromARGB(255, 50, 50, 250); + // Selected user profile + UserProfile _profile; + + void _loadProfile() async { + + final profile = await UserProfileDBManager().getSelectedProfile(); + + print("Loaded selected profile"); + + // If a different profile is selected, re-connect + if (_profile == null || (_profile.key != profile.key)) { + // TODO + } + + _profile = profile; + + setState(() { + + }); + } + + ListTile _serverTile() { + + // No profile selected + // Tap to select / create a profile + if (_profile == null) { + return ListTile( + title: Text("No Profile Selected"), + subtitle: Text("Tap to create or select a profile"), + leading: FaIcon(FontAwesomeIcons.user), + onTap: () { + _selectProfile(); + }, + ); + } + + // Profile is selected ... + if (InvenTreeAPI().isConnected()) { + return ListTile( + title: Text("Connected to ${_profile.server}"), + ); + } else { + return ListTile( + title: Text("Could not connect to server"), + subtitle: Text("Error connecting to ${_profile.server}"), + leading: FaIcon(FontAwesomeIcons.times), + onTap: () { + _selectProfile(); + }, + ); + } + } + void onConnectSuccess(String msg) async { final profile = await UserProfileDBManager().getSelectedProfile(); @@ -134,6 +191,10 @@ class _InvenTreeHomePageState extends State { Navigator.push(context, MaterialPageRoute(builder: (context) => CustomerListWidget())); } + void _selectProfile() { + Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget())); + } + void _unsupported() { showDialog( context: context, @@ -313,20 +374,7 @@ class _InvenTreeHomePageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( - child: ListTile( - title: Text("$_serverStatus", - style: TextStyle(color: _serverStatusColor), - ), - subtitle: Text("$_serverMessage", - style: TextStyle(color: _serverStatusColor), - ), - leading: _serverIcon, - onTap: () { - if (!_serverConnection) { - _checkServerConnection(context); - } - }, - ), + child: _serverTile(), ), ], ),