From d71d633ccef6e86b215a011dddb7f826b2ce34a8 Mon Sep 17 00:00:00 2001 From: krille-chan Date: Fri, 26 Jul 2024 17:32:36 +0200 Subject: [PATCH] chore: nicer bottom sheets --- .../user_bottom_sheet/user_bottom_sheet.dart | 2 +- .../user_bottom_sheet_view.dart | 46 +++++++++---------- lib/utils/adaptive_bottom_sheet.dart | 7 +-- lib/widgets/public_room_bottom_sheet.dart | 10 ++-- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart index 1ae173341..45be5c975 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet.dart @@ -234,7 +234,7 @@ class UserBottomSheetController extends State { void sendAction([_]) async { final userId = widget.user?.id ?? widget.profile?.userId; - final client = Matrix.of(context).client; + final client = Matrix.of(widget.outerContext).client; if (userId == null) throw ('user or profile must not be null!'); final input = sendController.text.trim(); diff --git a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart index 8630faba0..01035bb77 100644 --- a/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart +++ b/lib/pages/user_bottom_sheet/user_bottom_sheet_view.dart @@ -207,6 +207,29 @@ class UserBottomSheetView extends StatelessWidget { ), ], ), + PresenceBuilder( + userId: userId, + client: client, + builder: (context, presence) { + final status = presence?.statusMsg; + if (status == null || status.isEmpty) { + return const SizedBox.shrink(); + } + return ListTile( + title: SelectableLinkify( + text: status, + style: const TextStyle(fontSize: 16), + options: const LinkifyOptions(humanize: false), + linkStyle: const TextStyle( + color: Colors.blueAccent, + decorationColor: Colors.blueAccent, + ), + onOpen: (url) => + UrlLauncher(context, url.url).launchUrl(), + ), + ); + }, + ), if (userId != client.userID) Padding( padding: const EdgeInsets.symmetric( @@ -250,29 +273,6 @@ class UserBottomSheetView extends StatelessWidget { ), ), ), - PresenceBuilder( - userId: userId, - client: client, - builder: (context, presence) { - final status = presence?.statusMsg; - if (status == null || status.isEmpty) { - return const SizedBox.shrink(); - } - return ListTile( - title: SelectableLinkify( - text: status, - style: const TextStyle(fontSize: 16), - options: const LinkifyOptions(humanize: false), - linkStyle: const TextStyle( - color: Colors.blueAccent, - decorationColor: Colors.blueAccent, - ), - onOpen: (url) => - UrlLauncher(context, url.url).launchUrl(), - ), - ); - }, - ), if (controller.widget.onMention != null) ListTile( leading: const Icon(Icons.alternate_email_outlined), diff --git a/lib/utils/adaptive_bottom_sheet.dart b/lib/utils/adaptive_bottom_sheet.dart index cfe487ffd..d21ca6c44 100644 --- a/lib/utils/adaptive_bottom_sheet.dart +++ b/lib/utils/adaptive_bottom_sheet.dart @@ -8,18 +8,19 @@ Future showAdaptiveBottomSheet({ required Widget Function(BuildContext) builder, bool isDismissible = true, bool isScrollControlled = true, - double maxHeight = 480.0, + double maxHeight = 512, + bool useRootNavigator = true, }) => showModalBottomSheet( context: context, builder: builder, // this sadly is ugly on desktops but otherwise breaks `.of(context)` calls - useRootNavigator: false, + useRootNavigator: useRootNavigator, isDismissible: isDismissible, isScrollControlled: isScrollControlled, constraints: BoxConstraints( maxHeight: maxHeight, - maxWidth: FluffyThemes.columnWidth * 1.5, + maxWidth: FluffyThemes.columnWidth * 1.25, ), clipBehavior: Clip.hardEdge, shape: const RoundedRectangleBorder( diff --git a/lib/widgets/public_room_bottom_sheet.dart b/lib/widgets/public_room_bottom_sheet.dart index 8bd354ef5..4f5806c2d 100644 --- a/lib/widgets/public_room_bottom_sheet.dart +++ b/lib/widgets/public_room_bottom_sheet.dart @@ -64,17 +64,17 @@ class PublicRoomBottomSheet extends StatelessWidget { bool _testRoom(PublicRoomsChunk r) => r.canonicalAlias == roomAlias; - Future _search(BuildContext context) async { + Future _search() async { final chunk = this.chunk; if (chunk != null) return chunk; - final query = await Matrix.of(context).client.queryPublicRooms( + final query = await Matrix.of(outerContext).client.queryPublicRooms( server: roomAlias!.domain, filter: PublicRoomQueryFilter( genericSearchTerm: roomAlias, ), ); if (!query.chunk.any(_testRoom)) { - throw (L10n.of(context)!.noRoomsFound); + throw (L10n.of(outerContext)!.noRoomsFound); } return query.chunk.firstWhere(_testRoom); } @@ -108,7 +108,7 @@ class PublicRoomBottomSheet extends StatelessWidget { ], ), body: FutureBuilder( - future: _search(context), + future: _search(), builder: (context, snapshot) { final profile = snapshot.data; return ListView( @@ -142,7 +142,7 @@ class PublicRoomBottomSheet extends StatelessWidget { onPressed: () => _joinRoom(context), label: Text( chunk?.joinRule == 'knock' && - Matrix.of(context) + Matrix.of(outerContext) .client .getRoomById(chunk!.roomId) == null