Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create snackbar functions #164

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 29 additions & 104 deletions lib/constants/snackbars.dart
Original file line number Diff line number Diff line change
@@ -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,
);
}
8 changes: 4 additions & 4 deletions lib/helper_widgets/export_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class _MyHomePageState extends State<MyHomePage> {
if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context)
.showSnackBar(successfulSaveMultipleToDeviceSnackBar);
.showSnackBar(createSuccessSnackBar("Saved to device!"));
}
} else {
setState(() {
Expand All @@ -330,7 +330,8 @@ class _MyHomePageState extends State<MyHomePage> {

if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context).showSnackBar(errorSaveMultipleSnackBar);
ScaffoldMessenger.of(context)
.showSnackBar(createErrorSnackBar("Save not completed"));
}
}
}
Expand Down Expand Up @@ -369,7 +370,7 @@ class _MyHomePageState extends State<MyHomePage> {
if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context)
.showSnackBar(errorShareMultipleSnackBar);
.showSnackBar(createErrorSnackBar("Share not completed"));
}
} else {
setState(() {
Expand All @@ -380,7 +381,7 @@ class _MyHomePageState extends State<MyHomePage> {
if (mounted) {
Navigator.pop(context);
ScaffoldMessenger.of(context)
.showSnackBar(successfulShareMultipleSnackBar);
.showSnackBar(createSuccessSnackBar("Shared successfully!"));
}
}
}
Expand Down