treewide: small refactors

This commit is contained in:
Henry Hiles 2026-10-15 20:10:44 -04:00
commit 8d944831f5
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
10 changed files with 63 additions and 63 deletions

View file

@ -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, "

View file

@ -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);

View file

@ -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) {

View 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,
),
),
);
}
}

View file

@ -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 {