encapsulated snackbar call on error
This commit is contained in:
37
lib/service/notifying.dart
Normal file
37
lib/service/notifying.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'url_launcher.dart' show UrlLaunchErrorCode;
|
||||
|
||||
class Notifying {
|
||||
static void showSnackbar(
|
||||
BuildContext context, {
|
||||
required String text,
|
||||
bool isError = false,
|
||||
}) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
text,
|
||||
style: isError
|
||||
? TextStyle(color: Theme.of(context).colorScheme.error)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
static void showUrlErrorSnackbar(
|
||||
BuildContext context,
|
||||
UrlLaunchErrorCode errorCode,
|
||||
) {
|
||||
String errorText = '';
|
||||
if (errorCode == UrlLaunchErrorCode.none) {
|
||||
return;
|
||||
} else if (errorCode == UrlLaunchErrorCode.couldNotLaunch) {
|
||||
errorText = 'Could not launch Url';
|
||||
} else {
|
||||
errorText = 'Invalid Url';
|
||||
}
|
||||
showSnackbar(context, text: errorText, isError: true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user