diff --git a/lib/constants/snackbars.dart b/lib/constants/snackbars.dart index d09ccb6..3a8556c 100644 --- a/lib/constants/snackbars.dart +++ b/lib/constants/snackbars.dart @@ -1,106 +1,31 @@ import 'package:flutter/material.dart'; -const invalidJsonSnackBar = SnackBar( - content: Text('File contains invalid JSON'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const invalidConfigSnackBar = SnackBar( - content: Text('File contains invalid workout configuration'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const invalidJsonMultipleSnackBar = SnackBar( - content: Text('Not all files imported, found invalid JSON'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const invalidConfigMultipleSnackBar = SnackBar( - content: Text('Not all files imported, found invalid workout configuration'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const successfulImportSnackBar = SnackBar( - content: Text('Import successful!'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const successfulShareSnackBar = SnackBar( - content: Text('Share successful!'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const errorShareSnackBar = SnackBar( - backgroundColor: Color.fromARGB(255, 132, 19, 11), - content: Text('Share not completed', style: TextStyle(color: Colors.white)), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const successfulShareMultipleSnackBar = SnackBar( - content: Text('Files shared successfully!'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const successfulSaveMultipleToDeviceSnackBar = SnackBar( - content: Text('Files successfully saved to device!'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const successfulSaveToDeviceSnackBar = SnackBar( - content: Text('Saved file to device!'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const errorTimerExists = SnackBar( - content: Text('Could not import, timer with same ID exists'), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const errorMultipleTimerExists = SnackBar( - content: Text( - 'Not all files imported, timer with same ID exists', - style: TextStyle(color: Colors.white), - ), - backgroundColor: Color.fromARGB(255, 132, 19, 11), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const errorShareMultipleSnackBar = SnackBar( - content: Text('Share not completed', style: TextStyle(color: Colors.white)), - backgroundColor: Color.fromARGB(255, 132, 19, 11), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); - -const errorSaveMultipleSnackBar = SnackBar( - content: Text('Save not completed', style: TextStyle(color: Colors.white)), - backgroundColor: Color.fromARGB(255, 132, 19, 11), - behavior: SnackBarBehavior.fixed, - duration: Duration(seconds: 4), - showCloseIcon: true, -); +SnackBar createErrorSnackBar(String errorMessage) { + return SnackBar( + backgroundColor: Colors.red, + content: Text(errorMessage, style: const TextStyle(color: Colors.white)), + behavior: SnackBarBehavior.fixed, + duration: const Duration(seconds: 4), + showCloseIcon: true, + ); +} + +SnackBar createInfoSnackBar(String message) { + return SnackBar( + backgroundColor: Colors.blue, + content: Text(message, style: const TextStyle(color: Colors.white)), + behavior: SnackBarBehavior.fixed, + duration: const Duration(seconds: 4), + showCloseIcon: true, + ); +} + +SnackBar createSuccessSnackBar(String message) { + return SnackBar( + backgroundColor: Colors.green, + content: Text(message, style: const TextStyle(color: Colors.white)), + behavior: SnackBarBehavior.fixed, + duration: const Duration(seconds: 4), + showCloseIcon: true, + ); +} diff --git a/lib/helper_widgets/export_bottom_sheet.dart b/lib/helper_widgets/export_bottom_sheet.dart index 51b9703..698e613 100644 --- a/lib/helper_widgets/export_bottom_sheet.dart +++ b/lib/helper_widgets/export_bottom_sheet.dart @@ -43,8 +43,8 @@ class ExportBottomSheet extends StatelessWidget { if (context.mounted) { Navigator.pop(context); - ScaffoldMessenger.of(context) - .showSnackBar(successfulSaveToDeviceSnackBar); + ScaffoldMessenger.of(context).showSnackBar( + createSuccessSnackBar("Saved to device!")); } } : save, @@ -80,8 +80,8 @@ class ExportBottomSheet extends StatelessWidget { Navigator.pop(context); ScaffoldMessenger.of(context).showSnackBar( result!.status == ShareResultStatus.success - ? successfulShareSnackBar - : errorShareSnackBar); + ? createSuccessSnackBar("Shared successfully!") + : createErrorSnackBar("Share not completed")); } } : share, diff --git a/lib/main.dart b/lib/main.dart index 806f6fd..e366552 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -320,7 +320,7 @@ class _MyHomePageState extends State { if (mounted) { Navigator.pop(context); ScaffoldMessenger.of(context) - .showSnackBar(successfulSaveMultipleToDeviceSnackBar); + .showSnackBar(createSuccessSnackBar("Saved to device!")); } } else { setState(() { @@ -330,7 +330,8 @@ class _MyHomePageState extends State { if (mounted) { Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar(errorSaveMultipleSnackBar); + ScaffoldMessenger.of(context) + .showSnackBar(createErrorSnackBar("Save not completed")); } } } @@ -369,7 +370,7 @@ class _MyHomePageState extends State { if (mounted) { Navigator.pop(context); ScaffoldMessenger.of(context) - .showSnackBar(errorShareMultipleSnackBar); + .showSnackBar(createErrorSnackBar("Share not completed")); } } else { setState(() { @@ -380,7 +381,7 @@ class _MyHomePageState extends State { if (mounted) { Navigator.pop(context); ScaffoldMessenger.of(context) - .showSnackBar(successfulShareMultipleSnackBar); + .showSnackBar(createSuccessSnackBar("Shared successfully!")); } } }