Small fixes
This commit is contained in:
@@ -81,17 +81,17 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_stateNotifier.value = EditState.saving;
|
_stateNotifier.value = EditState.saving;
|
||||||
final sms = ScaffoldMessenger.of(context);
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||||
final locs = AppLocalizations.of(context)!;
|
final locs = AppLocalizations.of(context)!;
|
||||||
try {
|
try {
|
||||||
await widget.delegate.valueSetter(newValue);
|
await widget.delegate.valueSetter(newValue);
|
||||||
sms.showSnackBar(SnackBar(
|
scaffoldMessenger.showSnackBar(SnackBar(
|
||||||
content: Text(locs.settingsSuccessfullyUpdated),
|
content: Text(locs.settingsSuccessfullyUpdated),
|
||||||
duration: const Duration(milliseconds: 1200),
|
duration: const Duration(milliseconds: 1200),
|
||||||
));
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notifyUserOfErrorX(
|
showErrorSnackBar(
|
||||||
context: context,
|
scaffoldMessenger: scaffoldMessenger,
|
||||||
errorSituation: widget.delegate.errorSituation,
|
errorSituation: widget.delegate.errorSituation,
|
||||||
appLocalizations: locs,
|
appLocalizations: locs,
|
||||||
exception: e,
|
exception: e,
|
||||||
@@ -123,6 +123,7 @@ class _BaseEditTileBodyState<T> extends State<_BaseEditTileBody<T>> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
if (!mounted) return;
|
||||||
if (result != null) await _performSave(result);
|
if (result != null) await _performSave(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class ImageTile extends AbstractSettingsTile {
|
|||||||
|
|
||||||
Future<void> _pickImage(BuildContext context) async {
|
Future<void> _pickImage(BuildContext context) async {
|
||||||
final picker = ImagePicker();
|
final picker = ImagePicker();
|
||||||
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||||
final locs = AppLocalizations.of(context)!;
|
final locs = AppLocalizations.of(context)!;
|
||||||
final picked = await picker.pickImage(
|
final picked = await picker.pickImage(
|
||||||
source: ImageSource.gallery,
|
source: ImageSource.gallery,
|
||||||
@@ -55,8 +56,8 @@ class ImageTile extends AbstractSettingsTile {
|
|||||||
CachedNetworkImage.evictFromCache(imageUrl!);
|
CachedNetworkImage.evictFromCache(imageUrl!);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notifyUserOfErrorX(
|
showErrorSnackBar(
|
||||||
context: context,
|
scaffoldMessenger: scaffoldMessenger,
|
||||||
errorSituation: imageUpdateError ?? locs.settingsImageUpdateError,
|
errorSituation: imageUpdateError ?? locs.settingsImageUpdateError,
|
||||||
exception: e,
|
exception: e,
|
||||||
appLocalizations: locs,
|
appLocalizations: locs,
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:pweb/utils/error/handler.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({
|
Future<void> notifyUserOfError({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required String errorSituation,
|
required String errorSituation,
|
||||||
@@ -88,26 +106,14 @@ Future<void> postNotifyUserOfError({
|
|||||||
required Object exception,
|
required Object exception,
|
||||||
required AppLocalizations appLocalizations,
|
required AppLocalizations appLocalizations,
|
||||||
int delaySeconds = 3,
|
int delaySeconds = 3,
|
||||||
}) {
|
}) =>
|
||||||
final completer = Completer<void>();
|
notifyUserOfErrorX(
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
||||||
if (!context.mounted) {
|
|
||||||
completer.complete();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await notifyUserOfErrorX(
|
|
||||||
context: context,
|
context: context,
|
||||||
errorSituation: errorSituation,
|
errorSituation: errorSituation,
|
||||||
exception: exception,
|
exception: exception,
|
||||||
appLocalizations: appLocalizations,
|
appLocalizations: appLocalizations,
|
||||||
delaySeconds: delaySeconds,
|
delaySeconds: delaySeconds,
|
||||||
);
|
);
|
||||||
completer.complete();
|
|
||||||
});
|
|
||||||
|
|
||||||
return completer.future;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> postNotifyUserOfErrorX({
|
Future<void> postNotifyUserOfErrorX({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ Future<void> notifyUserX(
|
|||||||
String message, {
|
String message, {
|
||||||
int delaySeconds = 3,
|
int delaySeconds = 3,
|
||||||
}) async {
|
}) async {
|
||||||
if (!context.mounted) return;
|
|
||||||
final scaffoldMessenger = ScaffoldMessenger.maybeOf(context);
|
final scaffoldMessenger = ScaffoldMessenger.maybeOf(context);
|
||||||
if (scaffoldMessenger != null) {
|
if (scaffoldMessenger != null) {
|
||||||
scaffoldMessenger.showSnackBar(
|
scaffoldMessenger.showSnackBar(
|
||||||
|
|||||||
Reference in New Issue
Block a user