add dynamic hinting and latching for PMPs

This commit is contained in:
Henry Hiles 2026-11-26 16:06:08 -05:00
commit c786344bf2
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs

View file

@ -1,15 +1,21 @@
import "package:flutter_riverpod/flutter_riverpod.dart";
import "package:flutter_hooks/flutter_hooks.dart";
import "package:hooks_riverpod/hooks_riverpod.dart";
import "package:material_adaptive_sheets/material_adaptive_sheets.dart";
import "package:material_ui/material_ui.dart";
import "package:nexus/controllers/account_data.dart";
import "package:nexus/controllers/subprofiles.dart";
import "package:nexus/controllers/settings.dart";
import "package:nexus/main.dart";
import "package:nexus/models/room_subprofiles.dart";
import "package:nexus/widgets/avatars/avatar_or_hash.dart";
/// Chooses the subprofile messages are sent as in [roomId], if subprofiles are on.
class const SubprofileButton(final String roomId, {super.key})
extends ConsumerWidget {
/// Chooses the subprofile messages are sent as in [roomId], if subprofiles are
/// on. It shows the one the text in [controller] would trigger, if any.
class const SubprofileButton(
final String roomId, {
required final TextEditingController controller,
super.key,
}) extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final enabled = ref.watch(
@ -17,10 +23,14 @@ class const SubprofileButton(final String roomId, {super.key})
(settings) => settings.value?.subprofiles ?? false,
),
);
final (:profiles, :current) = ref.watch(
SubprofilesController.provider(roomId),
final subprofiles = ref.watch(SubprofilesController.provider(roomId));
final RoomSubprofiles(:profiles, :current) = subprofiles;
final triggered = useListenableSelector(
controller,
() => subprofiles.triggeredBy(controller.text),
);
if (!enabled || profiles.isEmpty) return const SizedBox.shrink();
final shown = triggered ?? current;
Future<void> choose(String profileId) => ref
.read(AccountDataController.provider.notifier)
@ -45,14 +55,17 @@ class const SubprofileButton(final String roomId, {super.key})
}
return AdaptiveMenuButton<void>(
tooltip: switch (current) {
final current? => "Sending as ${current.displayName ?? current.id}",
null => "Choose subprofile",
tooltip: switch ((triggered, current)) {
(final triggered?, _) =>
"Sending this message as ${triggered.displayName ?? triggered.id}",
(null, final current?) =>
"Sending as ${current.displayName ?? current.id}",
(null, null) => "Choose subprofile",
},
icon: switch (current) {
final current? => AvatarOrHash(
current.avatarUrl,
current.displayName ?? current.id,
icon: switch (shown) {
final shown? => AvatarOrHash(
shown.avatarUrl,
shown.displayName ?? shown.id,
),
null => Icon(Icons.person),
},