mirror of
				https://github.com/inventree/inventree-app.git
				synced 2025-10-30 21:05:42 +00:00 
			
		
		
		
	Slightly improved login info on main screen
This commit is contained in:
		| @@ -8,12 +8,14 @@ import 'package:flutter/cupertino.dart'; | |||||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||||
|  |  | ||||||
| import 'dsn.dart'; | import 'dsn.dart'; | ||||||
| import 'preferences.dart'; |  | ||||||
|  |  | ||||||
| import 'package:sentry/sentry.dart'; | import 'package:sentry/sentry.dart'; | ||||||
|  |  | ||||||
| // Use the secret app key | // 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 isInDebugMode() { | ||||||
|   bool inDebugMode = false; |   bool inDebugMode = false; | ||||||
| @@ -31,13 +33,15 @@ Future<void> _reportError(dynamic error, dynamic stackTrace) async { | |||||||
|     print(stackTrace); |     print(stackTrace); | ||||||
|     return; |     return; | ||||||
|   } else { |   } else { | ||||||
|     // Send the Exception and Stacktrace to Sentry in Production mode. |     try { | ||||||
|     _sentry.captureException( |       await _sentry.captureException( | ||||||
|       exception: error, |         error, | ||||||
|       stackTrace: stackTrace, |         stackTrace: stackTrace | ||||||
|       ); |       ); | ||||||
|  |     } catch (e) { | ||||||
|     print("Sending error to sentry.io"); |       print("Sending error report to sentry.io failed: ${e}"); | ||||||
|  |       print("Original error: ${error}"); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -47,12 +51,8 @@ void main() async { | |||||||
|  |  | ||||||
|   runZoned<Future<void>>(() async { |   runZoned<Future<void>>(() async { | ||||||
|     runApp(InvenTreeApp()); |     runApp(InvenTreeApp()); | ||||||
|   }, onError: (error, stackTrace) { |     }, onError: _reportError | ||||||
|     // 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); |  | ||||||
|   }); |  | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| class InvenTreeApp extends StatelessWidget { | class InvenTreeApp extends StatelessWidget { | ||||||
|   | |||||||
| @@ -10,12 +10,8 @@ import '../user_profile.dart'; | |||||||
|  |  | ||||||
| class InvenTreeLoginSettingsWidget extends StatefulWidget { | class InvenTreeLoginSettingsWidget extends StatefulWidget { | ||||||
|  |  | ||||||
|   final List<UserProfile> _profiles; |  | ||||||
|  |  | ||||||
|   InvenTreeLoginSettingsWidget(this._profiles) : super(); |  | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   _InvenTreeLoginSettingsState createState() => _InvenTreeLoginSettingsState(_profiles); |   _InvenTreeLoginSettingsState createState() => _InvenTreeLoginSettingsState(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -27,7 +23,9 @@ class _InvenTreeLoginSettingsState extends State<InvenTreeLoginSettingsWidget> { | |||||||
|  |  | ||||||
|   List<UserProfile> profiles; |   List<UserProfile> profiles; | ||||||
|  |  | ||||||
|   _InvenTreeLoginSettingsState(this.profiles); |   _InvenTreeLoginSettingsState() { | ||||||
|  |     _reload(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   void _reload() async { |   void _reload() async { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -72,7 +72,7 @@ class _InvenTreeSettingsState extends State<InvenTreeSettingsWidget> { | |||||||
|  |  | ||||||
|     List<UserProfile> profiles = await UserProfileDBManager().getAllProfiles(); |     List<UserProfile> profiles = await UserProfileDBManager().getAllProfiles(); | ||||||
|  |  | ||||||
|     Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget(profiles))); |     Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget())); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   void _about() async { |   void _about() async { | ||||||
|   | |||||||
| @@ -9,6 +9,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | |||||||
| import 'package:InvenTree/barcode.dart'; | import 'package:InvenTree/barcode.dart'; | ||||||
| import 'package:InvenTree/api.dart'; | import 'package:InvenTree/api.dart'; | ||||||
|  |  | ||||||
|  | import 'package:InvenTree/settings/login.dart'; | ||||||
|  |  | ||||||
| import 'package:InvenTree/widget/category_display.dart'; | import 'package:InvenTree/widget/category_display.dart'; | ||||||
| import 'package:InvenTree/widget/company_list.dart'; | import 'package:InvenTree/widget/company_list.dart'; | ||||||
| import 'package:InvenTree/widget/location_display.dart'; | import 'package:InvenTree/widget/location_display.dart'; | ||||||
| @@ -25,6 +27,8 @@ class InvenTreeHomePage extends StatefulWidget { | |||||||
| class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | ||||||
|  |  | ||||||
|   _InvenTreeHomePageState() : super() { |   _InvenTreeHomePageState() : super() { | ||||||
|  |  | ||||||
|  |     _loadProfile(); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   String _serverStatus = "Connecting to server"; |   String _serverStatus = "Connecting to server"; | ||||||
| @@ -37,6 +41,59 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | |||||||
|  |  | ||||||
|   Color _serverStatusColor = Color.fromARGB(255, 50, 50, 250); |   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 { |   void onConnectSuccess(String msg) async { | ||||||
|  |  | ||||||
|     final profile = await UserProfileDBManager().getSelectedProfile(); |     final profile = await UserProfileDBManager().getSelectedProfile(); | ||||||
| @@ -134,6 +191,10 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | |||||||
|     Navigator.push(context, MaterialPageRoute(builder: (context) => CustomerListWidget())); |     Navigator.push(context, MaterialPageRoute(builder: (context) => CustomerListWidget())); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   void _selectProfile() { | ||||||
|  |     Navigator.push(context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget())); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   void _unsupported() { |   void _unsupported() { | ||||||
|     showDialog( |     showDialog( | ||||||
|         context:  context, |         context:  context, | ||||||
| @@ -313,20 +374,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> { | |||||||
|               crossAxisAlignment: CrossAxisAlignment.center, |               crossAxisAlignment: CrossAxisAlignment.center, | ||||||
|               children: <Widget>[ |               children: <Widget>[ | ||||||
|                 Expanded( |                 Expanded( | ||||||
|                   child: ListTile( |                   child: _serverTile(), | ||||||
|                     title: Text("$_serverStatus", |  | ||||||
|                       style: TextStyle(color: _serverStatusColor), |  | ||||||
|                     ), |  | ||||||
|                     subtitle: Text("$_serverMessage", |  | ||||||
|                       style: TextStyle(color: _serverStatusColor), |  | ||||||
|                     ), |  | ||||||
|                     leading: _serverIcon, |  | ||||||
|                     onTap: () { |  | ||||||
|                       if (!_serverConnection) { |  | ||||||
|                         _checkServerConnection(context); |  | ||||||
|                       } |  | ||||||
|                     }, |  | ||||||
|                   ), |  | ||||||
|                 ), |                 ), | ||||||
|               ], |               ], | ||||||
|             ), |             ), | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user