diff --git a/lib/admin/pm_check.dart b/lib/admin/pm_check.dart index c5ec7b9..30cf5ca 100644 --- a/lib/admin/pm_check.dart +++ b/lib/admin/pm_check.dart @@ -285,6 +285,8 @@ class _PmCheckPageState extends State { } Future pickTemplates(BuildContext context) async { + final template = context.read(); + final maximo = context.read(); Stopwatch stopwatch = Stopwatch()..start(); FilePickerResult? result = await FilePicker.platform .pickFiles(allowMultiple: true, withData: true); @@ -309,8 +311,6 @@ class _PmCheckPageState extends State { setState(() { debugPrint('Processing files...'); }); - final template = context.read(); - final maximo = context.read(); processAllTemplates(template, files, maximo.maximoServerSelected); } } diff --git a/lib/admin/pm_meter_update_functions.dart b/lib/admin/pm_meter_update_functions.dart index 1ecfa63..ddfea67 100644 --- a/lib/admin/pm_meter_update_functions.dart +++ b/lib/admin/pm_meter_update_functions.dart @@ -1,6 +1,3 @@ -import 'package:iko_reliability_flutter/admin/generate_uploads.dart'; - -import '../bin/db_drift.dart'; import 'upload_maximo.dart'; class AssetMeterMaximo { @@ -72,21 +69,3 @@ List assetMeterPairs( } return result; } - -List jobTaskUpdates( - List jobplans, Meter meterDetails) { - List result = []; - final details = jobTaskFormat(meterDetails.description); - for (final jobplan in jobplans) { - if (details != jobplan.details) { - result.add(jobplan); - continue; - } - // TODO more comparisons - // description - // metercode - // ignore CBM for now - } - - return result; -} diff --git a/lib/bin/end_drawer.dart b/lib/bin/end_drawer.dart index 32ba5ff..4797bca 100644 --- a/lib/bin/end_drawer.dart +++ b/lib/bin/end_drawer.dart @@ -168,7 +168,7 @@ class _EndDrawerState extends State { passwordController.text, maximo.maximoServerSelected); } finally { - ScaffoldMessenger.of(context) + ScaffoldMessenger.of(navigatorKey.currentContext!) .hideCurrentSnackBar(); //hide snackbar once process is complete processNotifier.setProcessState( ProcessStates.loginState, false); @@ -226,7 +226,8 @@ class _EndDrawerState extends State { )); List messages = await maximoAssetCaller( siteid, maximo.maximoServerSelected, context); - processNotifier.popProcessingDialog(context); + processNotifier.popProcessingDialog( + navigatorKey.currentContext!); if (messages.isNotEmpty) { showDataAlert(messages, 'Site Assets Loaded'); } @@ -341,7 +342,7 @@ class _EndDrawerState extends State { context.read().selectedSite, )), )); - Navigator.of(context).pop(); + Navigator.of(navigatorKey.currentContext!).pop(); }), ), ListTile( @@ -354,7 +355,7 @@ class _EndDrawerState extends State { database!, )), )); - Navigator.of(context).pop(); + Navigator.of(navigatorKey.currentContext!).pop(); }), ), ]), @@ -390,6 +391,8 @@ class _EndDrawerState extends State { trailing: ElevatedButton( child: const Text('Export'), onPressed: () async { + PlutoGridStateManager? stateManager = + context.read().stateManager; if (!context .read() .priorityRangesUpToDate) { @@ -399,9 +402,6 @@ class _EndDrawerState extends State { return; } } - PlutoGridStateManager? stateManager = - context.read().stateManager; - //export as csv if (stateManager != null) { exportAssetCriticalityAsCSV( @@ -422,7 +422,7 @@ class _EndDrawerState extends State { context.read().selectedSite, )), )); - Navigator.of(context).pop(); + Navigator.of(navigatorKey.currentContext!).pop(); }), ), ListTile( @@ -435,7 +435,7 @@ class _EndDrawerState extends State { database!, )), )); - Navigator.of(context).pop(); + Navigator.of(navigatorKey.currentContext!).pop(); }), ), ], diff --git a/lib/creation/asset.dart b/lib/creation/asset.dart index 8ea7bf5..73b1157 100644 --- a/lib/creation/asset.dart +++ b/lib/creation/asset.dart @@ -209,9 +209,10 @@ class _AssetCreationGridState extends State { context.read().selectedSite); stateManager .removeRows([rendererContext.row], notify: true); - toast(context, 'Deleted Asset $assetNum'); + toast(navigatorKey.currentContext!, + 'Deleted Asset $assetNum'); } catch (err) { - toast(context, '$err'); + toast(navigatorKey.currentContext!, '$err'); } }, iconSize: 18, @@ -257,12 +258,12 @@ class _AssetCreationGridState extends State { } Future _loadGrid(String site) async { + final assetCreationNotifier = + Provider.of(context, listen: false); await context .read() .setSite(context.read().selectedSite); - print('load grid'); - final assetCreationNotifier = - Provider.of(context, listen: false); + debugPrint('load grid'); var fetchedRows = _getChildRows('Top', assetCreationNotifier.parentAssets); var value = @@ -604,12 +605,13 @@ class _AssetCreationDialogState extends State { context .read() .setSite(context.read().selectedSite); - toast(context, 'Created Asset $assetNum, id: $id'); + toast(navigatorKey.currentContext!, + 'Created Asset $assetNum, id: $id'); } catch (err) { - toast(context, '$err'); + toast(navigatorKey.currentContext!, '$err'); } - Navigator.pop(context, 'OK'); + Navigator.pop(navigatorKey.currentContext!, 'OK'); }, child: const Text('OK'), ), @@ -665,9 +667,10 @@ class _AssetUploadGridState extends State { context.read().selectedSite); stateManager .removeRows([rendererContext.row], notify: true); - toast(context, 'Deleted Asset $assetNum'); + toast(navigatorKey.currentContext!, + 'Deleted Asset $assetNum'); } catch (err) { - toast(context, '$err'); + toast(navigatorKey.currentContext!, '$err'); } }, iconSize: 18, diff --git a/lib/creation/asset_creation_notifier.dart b/lib/creation/asset_creation_notifier.dart index 4b2d01d..a0b05fe 100644 --- a/lib/creation/asset_creation_notifier.dart +++ b/lib/creation/asset_creation_notifier.dart @@ -103,7 +103,7 @@ class AssetCreationNotifier extends ChangeNotifier { pendingAssets.remove(assetNum); var parent = siteAssets[assetNum]!.asset.parent; - parentAssets[parent]!.remove(siteAssets[assetNum]!); + parentAssets[parent]!.remove(siteAssets[assetNum]!.asset); if (parentAssets[parent]!.isEmpty) { parentAssets.remove(parent); } diff --git a/lib/criticality/asset_criticality.dart b/lib/criticality/asset_criticality.dart index 5b2cdfb..47c8b23 100644 --- a/lib/criticality/asset_criticality.dart +++ b/lib/criticality/asset_criticality.dart @@ -285,10 +285,13 @@ class _AssetCriticalityPageState extends State { downtime: rendererContext.row.cells['downtime']!.value, system: rendererContext.row.cells['system']!.value, ); - context.read().updateAssetOverride( - assets: [rendererContext.row.cells['assetnum']!.value], - status: AssetOverride.breakdowns, - ); + + if (context.mounted) { + context.read().updateAssetOverride( + assets: [rendererContext.row.cells['assetnum']!.value], + status: AssetOverride.breakdowns, + ); + } setState(() { stateManager.changeCellValue(rendererContext.cell, value); }); @@ -325,10 +328,12 @@ class _AssetCriticalityPageState extends State { frequency: rendererContext.row.cells['frequency']!.value, system: rendererContext.row.cells['system']!.value, ); - context.read().updateAssetOverride( - assets: [rendererContext.row.cells['assetnum']!.value], - status: AssetOverride.breakdowns, - ); + if (context.mounted) { + context.read().updateAssetOverride( + assets: [rendererContext.row.cells['assetnum']!.value], + status: AssetOverride.breakdowns, + ); + } setState(() { stateManager.changeCellValue(rendererContext.cell, value); }); @@ -374,10 +379,12 @@ class _AssetCriticalityPageState extends State { system: rendererContext.row.cells['system']!.value, frequency: rendererContext.row.cells['frequency']!.value, ); - context.read().updateAssetOverride( - assets: [rendererContext.row.cells['assetnum']!.value], - status: AssetOverride.priority, - ); + if (context.mounted) { + context.read().updateAssetOverride( + assets: [rendererContext.row.cells['assetnum']!.value], + status: AssetOverride.priority, + ); + } setState(() { stateManager.changeCellValue(rendererContext.cell, value); }); @@ -543,6 +550,8 @@ class _AssetCriticalityPageState extends State { assets: [assetnum], status: AssetStatus.refreshingWorkOrders, ); + AssetCriticalitySettingsNotifier assetCriticalitySettings = + context.read(); // get all WOs from Maximo try { await database!.getWorkOrderMaximo( @@ -551,22 +560,23 @@ class _AssetCriticalityPageState extends State { ); } catch (e) { previousStatus = AssetStatus.refreshError; - ScaffoldMessenger.of(context).showSnackBar(SnackBar( + ScaffoldMessenger.of(navigatorKey.currentContext!).showSnackBar(SnackBar( content: Text( 'Error retriving Work Orders from Maximo for: $assetnum \n ${e.toString()}'), )); return; } // bring back previous status Icon - context.read().updateAssetStatus( - assets: [assetnum], - status: previousStatus, - ); + if (context.mounted) { + context.read().updateAssetStatus( + assets: [assetnum], + status: previousStatus, + ); + } var wos = await database!.getAssetWorkorders(assetnum); double downtime = 0; double dtEvents = 0; - AssetCriticalitySettingsNotifier assetCriticalitySettings = - context.read(); + for (var wo in wos) { if (!isWorkOrderInRange(wo)) { continue; diff --git a/lib/criticality/criticality_settings_notifier.dart b/lib/criticality/criticality_settings_notifier.dart index aed8cec..8a54cda 100644 --- a/lib/criticality/criticality_settings_notifier.dart +++ b/lib/criticality/criticality_settings_notifier.dart @@ -295,9 +295,9 @@ List calculateSingleCutoff({ int i = 1; double currentPercent = 0; double previousPercent = 0; + int sumRPNs = 0; // calculation for very low while (i <= sortedUniqueRPNs.length) { - int sumRPNs = 0; sortedUniqueRPNs.sublist(0, i).forEach((element) { sumRPNs = sumRPNs + frequencyOfRPNs[element]!; }); diff --git a/lib/criticality/file_export.dart b/lib/criticality/file_export.dart index 795b551..6d39bab 100644 --- a/lib/criticality/file_export.dart +++ b/lib/criticality/file_export.dart @@ -9,6 +9,8 @@ import 'package:pluto_grid/pluto_grid.dart'; import '../admin/generate_uploads.dart'; import 'package:csv/csv.dart'; +import '../main.dart'; + ///Saves string contents into a file selected by the user. Shows a file picker dialog. ///Returns [true] if file is saved, [false] if canceled, and an exception object if there was an error. ///Saves file in utf-8 with BOM encoding @@ -45,7 +47,7 @@ Future saveFileFromString(String contents, debugPrint('File type not supported'); if (context != null) { await showDialog( - context: context, + context: navigatorKey.currentContext!, builder: (context) => AlertDialog( title: const Text('Unsupported File Type'), content: Text( diff --git a/lib/criticality/spare_criticality.dart b/lib/criticality/spare_criticality.dart index 64cc448..e5c1402 100644 --- a/lib/criticality/spare_criticality.dart +++ b/lib/criticality/spare_criticality.dart @@ -135,7 +135,7 @@ class _SpareCriticalityPageState extends State { ])) .toList(); showDialog( - context: context, + context: navigatorKey.currentContext!, builder: (BuildContext context) { return Dialog( child: DataTable(columns: const [ @@ -538,14 +538,16 @@ class _SpareCriticalityPageState extends State { spareid: event.row.cells['id']!.value, ); event.row.cells['rpn']!.value = newRpn; - final newPriority = context - .read() - .rpnFindDistribution(newRpn); - if (event.row.cells['override']!.value != - AssetOverride.priority) { - event.row.cells['newPriority']!.value = newPriority; - event.row.cells['override']!.value = - AssetOverride.breakdowns; + if (context.mounted) { + final newPriority = context + .read() + .rpnFindDistribution(newRpn); + if (event.row.cells['override']!.value != + AssetOverride.priority) { + event.row.cells['newPriority']!.value = newPriority; + event.row.cells['override']!.value = + AssetOverride.breakdowns; + } } } }, @@ -756,9 +758,9 @@ class _SparePartsLoadingIndicatorState return; } } - Navigator.pop(context); - context.router.pushNamed("/criticality/spare"); - Navigator.pop(context); // close the drawer + Navigator.pop(navigatorKey.currentContext!); + navigatorKey.currentContext!.router.pushNamed("/criticality/spare"); + Navigator.pop(navigatorKey.currentContext!); // close the drawer } } @@ -920,6 +922,7 @@ Future calculateRPNDistributionSpares(BuildContext context) async { return 'Duplicate values in RPN cutoffs\nIncrease percentage of duplicate value, Or ensure RPN values are more spread out'; } spareCritifcalityNotifier.updateGrid = true; + debugPrint(spareCritifcalityNotifier.updateGrid.toString()); } catch (e) { debugPrint(e.toString()); return e.toString(); diff --git a/lib/criticality/system_criticality.dart b/lib/criticality/system_criticality.dart index 86a3630..b0bfc4b 100644 --- a/lib/criticality/system_criticality.dart +++ b/lib/criticality/system_criticality.dart @@ -569,10 +569,11 @@ class _NewSystemFormState extends State { newRow.cells['line']!.value = row.line; newRow.cells['description']!.value = row.description; stateManager.appendRows([newRow]); - ScaffoldMessenger.of(context).showSnackBar( + ScaffoldMessenger.of(navigatorKey.currentContext!) + .showSnackBar( const SnackBar(content: Text('Adding New System')), ); - Navigator.of(context).pop(); + Navigator.of(navigatorKey.currentContext!).pop(); } }, child: const Text('Submit'), diff --git a/lib/main.dart b/lib/main.dart index 9d12528..b418abe 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -128,7 +128,7 @@ class MyApp extends StatelessWidget { Future loadAppSettings(SelectedSiteNotifier selectedSiteNotifier, ThemeManager themeManager, SettingsNotifier settingsNotifier) async { - print('running load app'); + debugPrint('running load app'); final settings = await database!.getSettings(); final selectedSite = settings .firstWhere( diff --git a/lib/settings/settings_notifier.dart b/lib/settings/settings_notifier.dart index b49b454..e89d557 100644 --- a/lib/settings/settings_notifier.dart +++ b/lib/settings/settings_notifier.dart @@ -157,11 +157,6 @@ class SettingsNotifier extends ChangeNotifier { return currentSettings[settingKey]; } - ///Gets an int list of the rpn percent distributions from very low to very high - List getRpnPercentDists() { - return List.from(criticalityStrings.map((e) => currentSettings[e])); - } - void addLoadedSites(List sites, {bool notify = false}) { Set newSet = (currentSettings[ApplicationSetting.loadedSites] as Set)