Files
maps_bookmarks/lib/service/notifying.dart
2026-01-23 16:41:16 +01:00

65 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import '../l10n/app_localizations.dart';
import 'url_launcher.dart' show UrlLaunchErrorCode;
class Notifying {
static void showSnackbar(
BuildContext context, {
required String text,
bool isError = false,
}) {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: isError ? Theme.of(context).colorScheme.error : null,
content: SizedBox(
height: 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
text,
style: isError
? TextStyle(color: Theme.of(context).colorScheme.onError)
: null,
),
IconButton(
onPressed: () =>
ScaffoldMessenger.of(context).hideCurrentSnackBar(),
icon: Icon(
Icons.close_rounded,
color: isError ? Theme.of(context).colorScheme.onError : null,
),
),
],
),
),
),
);
}
static void showUrlErrorSnackbar(
BuildContext context,
UrlLaunchErrorCode errorCode,
) {
String errorText = '';
if (errorCode == UrlLaunchErrorCode.none) {
return;
} else if (errorCode == UrlLaunchErrorCode.couldNotLaunch) {
errorText = AppLocalizations.of(context)!.errorCouldNotLaunchUrl;
} else {
errorText = AppLocalizations.of(context)!.errorInvalidUrl;
}
showSnackbar(context, text: errorText, isError: true);
}
static void showErrorSnackbar(BuildContext context, String message) {
showSnackbar(context, text: message, isError: true);
}
static void showMessageSnackbar(BuildContext context, String message) {
showSnackbar(context, text: message, isError: false);
}
}