Small fixes

This commit is contained in:
Arseni
2026-01-27 18:41:14 +03:00
parent be1d678c42
commit 6a3a60ef19
4 changed files with 30 additions and 23 deletions

View File

@@ -81,17 +81,17 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
return;
}
_stateNotifier.value = EditState.saving;
final sms = ScaffoldMessenger.of(context);
final scaffoldMessenger = ScaffoldMessenger.of(context);
final locs = AppLocalizations.of(context)!;
try {
await widget.delegate.valueSetter(newValue);
sms.showSnackBar(SnackBar(
scaffoldMessenger.showSnackBar(SnackBar(
content: Text(locs.settingsSuccessfullyUpdated),
duration: const Duration(milliseconds: 1200),
));
} catch (e) {
notifyUserOfErrorX(
context: context,
showErrorSnackBar(
scaffoldMessenger: scaffoldMessenger,
errorSituation: widget.delegate.errorSituation,
appLocalizations: locs,
exception: e,
@@ -123,6 +123,7 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
);
},
);
if (!mounted) return;
if (result != null) await _performSave(result);
}

View File

@@ -41,6 +41,7 @@ class ImageTile extends AbstractSettingsTile {
Future<void> _pickImage(BuildContext context) async {
final picker = ImagePicker();
final scaffoldMessenger = ScaffoldMessenger.of(context);
final locs = AppLocalizations.of(context)!;
final picked = await picker.pickImage(
source: ImageSource.gallery,
@@ -55,8 +56,8 @@ class ImageTile extends AbstractSettingsTile {
CachedNetworkImage.evictFromCache(imageUrl!);
}
} catch (e) {
notifyUserOfErrorX(
context: context,
showErrorSnackBar(
scaffoldMessenger: scaffoldMessenger,
errorSituation: imageUpdateError ?? locs.settingsImageUpdateError,
exception: e,
appLocalizations: locs,

View File

@@ -1,5 +1,3 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pweb/utils/error/handler.dart';
@@ -41,6 +39,26 @@ Future<void> notifyUserOfErrorX({
);
}
void showErrorSnackBar({
required ScaffoldMessengerState scaffoldMessenger,
required String errorSituation,
required Object exception,
required AppLocalizations appLocalizations,
int delaySeconds = 3,
}) {
final localizedError = ErrorHandler.handleErrorLocs(appLocalizations, exception);
final technicalDetails = exception.toString();
final snackBar = _buildMainErrorSnackBar(
errorSituation: errorSituation,
localizedError: localizedError,
technicalDetails: technicalDetails,
loc: appLocalizations,
scaffoldMessenger: scaffoldMessenger,
delaySeconds: delaySeconds,
);
scaffoldMessenger.showSnackBar(snackBar);
}
Future<void> notifyUserOfError({
required BuildContext context,
required String errorSituation,
@@ -88,26 +106,14 @@ Future<void> postNotifyUserOfError({
required Object exception,
required AppLocalizations appLocalizations,
int delaySeconds = 3,
}) {
final completer = Completer<void>();
WidgetsBinding.instance.addPostFrameCallback((_) async {
if (!context.mounted) {
completer.complete();
return;
}
await notifyUserOfErrorX(
}) =>
notifyUserOfErrorX(
context: context,
errorSituation: errorSituation,
exception: exception,
appLocalizations: appLocalizations,
delaySeconds: delaySeconds,
);
completer.complete();
});
return completer.future;
}
Future<void> postNotifyUserOfErrorX({
required BuildContext context,

View File

@@ -10,7 +10,6 @@ Future<void> notifyUserX(
String message, {
int delaySeconds = 3,
}) async {
if (!context.mounted) return;
final scaffoldMessenger = ScaffoldMessenger.maybeOf(context);
if (scaffoldMessenger != null) {
scaffoldMessenger.showSnackBar(