treewide: small refactors
This commit is contained in:
parent
9117663c48
commit
8d944831f5
10 changed files with 63 additions and 63 deletions
|
|
@ -41,7 +41,7 @@ extension BuildEventOptions on Event {
|
|||
.read(PinnedIdsController.provider(roomId))
|
||||
.contains(eventId);
|
||||
|
||||
void showReasonDialog({
|
||||
void showReasonSheet({
|
||||
required String title,
|
||||
required String description,
|
||||
required String action,
|
||||
|
|
@ -235,7 +235,7 @@ extension BuildEventOptions on Event {
|
|||
) &&
|
||||
!eventId.isFake)
|
||||
PopupMenuItem(
|
||||
onTap: () => showReasonDialog(
|
||||
onTap: () => showReasonSheet(
|
||||
title: "Delete Message",
|
||||
description:
|
||||
"Are you sure you want to delete this message? "
|
||||
|
|
@ -260,7 +260,7 @@ extension BuildEventOptions on Event {
|
|||
),
|
||||
|
||||
PopupMenuItem(
|
||||
onTap: () => showReasonDialog(
|
||||
onTap: () => showReasonSheet(
|
||||
title: "Report",
|
||||
description:
|
||||
"Report this event to your server administrators, "
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
extension GetLocalpart on String {
|
||||
String get localpart => length > 1 ? substring(1).split(":").first : "?";
|
||||
|
||||
/// Whether this looks like a valid Matrix user ID, e.g. `@user:example.com`.
|
||||
bool get isValidUserId => RegExp(r"^@[^:\s]+:[^\s]+$").hasMatch(this);
|
||||
|
||||
String? get serverName {
|
||||
final index = indexOf(":");
|
||||
return index == -1 ? null : substring(index + 1);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import "package:m3e_card_list/m3e_card_list.dart";
|
|||
import "package:nexus/helpers/launch_helper.dart";
|
||||
import "package:package_info_plus/package_info_plus.dart";
|
||||
|
||||
extension ShowAboutDialog on BuildContext {
|
||||
Future<void> showAboutDialog(WidgetRef ref) async {
|
||||
extension ShowAboutSheet on BuildContext {
|
||||
Future<void> showAboutSheet(WidgetRef ref) async {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
|
||||
if (mounted) {
|
||||
28
lib/helpers/extensions/show_error_snack_bar.dart
Normal file
28
lib/helpers/extensions/show_error_snack_bar.dart
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
|
||||
extension ShowErrorSnackBar on ScaffoldMessengerState {
|
||||
/// Shows [message] in a snackbar styled as an error.
|
||||
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> showErrorSnackBar(
|
||||
String message, {
|
||||
({String label, VoidCallback onPressed})? action,
|
||||
}) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
return showSnackBar(
|
||||
.new(
|
||||
backgroundColor: colorScheme.errorContainer,
|
||||
content: Text(
|
||||
message,
|
||||
style: .new(color: colorScheme.onErrorContainer),
|
||||
),
|
||||
action: action == null
|
||||
? null
|
||||
: .new(
|
||||
label: action.label,
|
||||
onPressed: action.onPressed,
|
||||
textColor: colorScheme.onErrorContainer,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import "package:material_ui/material_ui.dart";
|
||||
import "package:nexus/helpers/extensions/show_error_snack_bar.dart";
|
||||
|
||||
extension WithProgressSnackbar on BuildContext {
|
||||
/// Shows [progress] in a snackbar while [action] runs, and shows any error
|
||||
|
|
@ -10,8 +11,6 @@ extension WithProgressSnackbar on BuildContext {
|
|||
Future<T> Function() action,
|
||||
) async {
|
||||
final messenger = ScaffoldMessenger.of(this);
|
||||
final colorScheme = Theme.of(this).colorScheme;
|
||||
|
||||
final snackbar = messenger.showSnackBar(
|
||||
.new(content: Text(progress), duration: const .new(days: 1)),
|
||||
);
|
||||
|
|
@ -19,15 +18,7 @@ extension WithProgressSnackbar on BuildContext {
|
|||
try {
|
||||
return await action();
|
||||
} catch (error) {
|
||||
messenger.showSnackBar(
|
||||
.new(
|
||||
backgroundColor: colorScheme.errorContainer,
|
||||
content: Text(
|
||||
error.toString(),
|
||||
style: .new(color: colorScheme.onErrorContainer),
|
||||
),
|
||||
),
|
||||
);
|
||||
messenger.showErrorSnackBar(error.toString());
|
||||
|
||||
return null;
|
||||
} finally {
|
||||
|
|
|
|||
Loading…
Reference in a new issue