Merge pull request #1524 from krille-chan/krille/qr-code-sharing

feat: QR Code viewer for mxid sharing
pull/1521/head
Krille-chan 7 months ago committed by GitHub
commit 11817e6eb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,7 +5,6 @@ import 'package:flutter_linkify/flutter_linkify.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/chat_details/chat_details.dart'; import 'package:fluffychat/pages/chat_details/chat_details.dart';
import 'package:fluffychat/pages/chat_details/participant_list_item.dart'; import 'package:fluffychat/pages/chat_details/participant_list_item.dart';
import 'package:fluffychat/utils/fluffy_share.dart'; import 'package:fluffychat/utils/fluffy_share.dart';
@ -15,6 +14,7 @@ import 'package:fluffychat/widgets/chat_settings_popup_menu.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import '../../utils/url_launcher.dart'; import '../../utils/url_launcher.dart';
import '../../widgets/qr_code_viewer.dart';
class ChatDetailsView extends StatelessWidget { class ChatDetailsView extends StatelessWidget {
final ChatDetailsController controller; final ChatDetailsController controller;
@ -60,10 +60,10 @@ class ChatDetailsView extends StatelessWidget {
if (room.canonicalAlias.isNotEmpty) if (room.canonicalAlias.isNotEmpty)
IconButton( IconButton(
tooltip: L10n.of(context).share, tooltip: L10n.of(context).share,
icon: Icon(Icons.adaptive.share_outlined), icon: const Icon(Icons.qr_code_rounded),
onPressed: () => FluffyShare.share( onPressed: () => showQrCodeViewer(
AppConfig.inviteLinkPrefix + room.canonicalAlias,
context, context,
room.canonicalAlias,
), ),
), ),
if (controller.widget.embeddedCloseButton == null) if (controller.widget.embeddedCloseButton == null)

@ -14,6 +14,7 @@ import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/layouts/max_width_body.dart'; import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import '../../widgets/qr_code_viewer.dart';
class NewPrivateChatView extends StatelessWidget { class NewPrivateChatView extends StatelessWidget {
final NewPrivateChatController controller; final NewPrivateChatController controller;
@ -25,6 +26,7 @@ class NewPrivateChatView extends StatelessWidget {
final theme = Theme.of(context); final theme = Theme.of(context);
final searchResponse = controller.searchResponse; final searchResponse = controller.searchResponse;
final userId = Matrix.of(context).client.userID!;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
scrolledUnderElevation: 0, scrolledUnderElevation: 0,
@ -157,26 +159,35 @@ class NewPrivateChatView extends StatelessWidget {
), ),
Center( Center(
child: Padding( child: Padding(
padding: const EdgeInsets.all(64.0), padding: const EdgeInsets.symmetric(
child: ConstrainedBox( horizontal: 64.0,
constraints: const BoxConstraints(maxHeight: 256), vertical: 24.0,
child: Material( ),
borderRadius: BorderRadius.circular(12), child: Material(
elevation: 10, borderRadius:
color: Colors.white, BorderRadius.circular(AppConfig.borderRadius),
shadowColor: theme.appBarTheme.shadowColor, color: theme.colorScheme.primaryContainer,
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
child: InkWell(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
onTap: () => showQrCodeViewer(
context,
userId,
),
child: Padding( child: Padding(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(32.0),
child: PrettyQrView.data( child: ConstrainedBox(
data: constraints:
'https://matrix.to/#/${Matrix.of(context).client.userID}', const BoxConstraints(maxWidth: 256),
decoration: PrettyQrDecoration( child: PrettyQrView.data(
shape: PrettyQrSmoothSymbol( data: 'https://matrix.to/#/$userId',
roundFactor: 1, decoration: PrettyQrDecoration(
color: theme.brightness == Brightness.light shape: PrettyQrSmoothSymbol(
? theme.colorScheme.primary roundFactor: 1,
: theme.colorScheme.onPrimary, color:
theme.colorScheme.onPrimaryContainer,
),
), ),
), ),
), ),

@ -10,6 +10,7 @@ import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/presence_builder.dart'; import 'package:fluffychat/widgets/presence_builder.dart';
import 'package:fluffychat/widgets/qr_code_viewer.dart';
import '../../widgets/matrix.dart'; import '../../widgets/matrix.dart';
import 'user_bottom_sheet.dart'; import 'user_bottom_sheet.dart';
@ -30,348 +31,340 @@ class UserBottomSheetView extends StatelessWidget {
final client = Matrix.of(controller.widget.outerContext).client; final client = Matrix.of(controller.widget.outerContext).client;
final profileSearchError = controller.widget.profileSearchError; final profileSearchError = controller.widget.profileSearchError;
final dmRoomId = client.getDirectChatFromUserId(userId); final dmRoomId = client.getDirectChatFromUserId(userId);
return SafeArea( return Scaffold(
child: Scaffold( appBar: AppBar(
appBar: AppBar( leading: Center(
leading: Center( child: CloseButton(
child: CloseButton( onPressed: Navigator.of(context, rootNavigator: false).pop,
onPressed: Navigator.of(context, rootNavigator: false).pop,
),
), ),
centerTitle: false,
title: Text(displayname),
actions: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: IconButton(
onPressed: () => FluffyShare.share(
'https://matrix.to/#/$userId',
context,
),
icon: Icon(Icons.adaptive.share_outlined),
),
),
],
), ),
body: StreamBuilder<Object>( centerTitle: false,
stream: user?.room.client.onSync.stream.where( title: Text(displayname),
(syncUpdate) => actions: [
syncUpdate.rooms?.join?[user.room.id]?.timeline?.events?.any( Padding(
(state) => state.type == EventTypes.RoomPowerLevels, padding: const EdgeInsets.symmetric(horizontal: 8),
) ?? child: IconButton(
false, onPressed: () => showQrCodeViewer(context, userId),
icon: const Icon(Icons.qr_code_outlined),
),
), ),
builder: (context, snapshot) { ],
final theme = Theme.of(context); ),
return ListView( body: StreamBuilder<Object>(
children: [ stream: user?.room.client.onSync.stream.where(
if (user?.membership == Membership.knock) (syncUpdate) =>
Padding( syncUpdate.rooms?.join?[user.room.id]?.timeline?.events?.any(
padding: const EdgeInsets.all(12.0), (state) => state.type == EventTypes.RoomPowerLevels,
child: Material( ) ??
color: theme.colorScheme.surfaceContainerHigh, false,
borderRadius: ),
BorderRadius.circular(AppConfig.borderRadius), builder: (context, snapshot) {
child: ListTile( final theme = Theme.of(context);
minVerticalPadding: 16, return ListView(
title: Padding( children: [
padding: const EdgeInsets.only(bottom: 12.0), if (user?.membership == Membership.knock)
child: Text( Padding(
L10n.of(context) padding: const EdgeInsets.all(12.0),
.userWouldLikeToChangeTheChat(displayname), child: Material(
), color: theme.colorScheme.surfaceContainerHigh,
), borderRadius: BorderRadius.circular(AppConfig.borderRadius),
subtitle: Row( child: ListTile(
children: [ minVerticalPadding: 16,
TextButton.icon( title: Padding(
style: TextButton.styleFrom( padding: const EdgeInsets.only(bottom: 12.0),
backgroundColor: theme.colorScheme.surface, child: Text(
foregroundColor: theme.colorScheme.primary, L10n.of(context)
), .userWouldLikeToChangeTheChat(displayname),
onPressed: controller.knockAccept,
icon: const Icon(Icons.check_outlined),
label: Text(L10n.of(context).accept),
),
const SizedBox(width: 12),
TextButton.icon(
style: TextButton.styleFrom(
backgroundColor:
theme.colorScheme.errorContainer,
foregroundColor:
theme.colorScheme.onErrorContainer,
),
onPressed: controller.knockDecline,
icon: const Icon(Icons.cancel_outlined),
label: Text(L10n.of(context).decline),
),
],
), ),
), ),
), subtitle: Row(
),
Row(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Avatar(
client:
Matrix.of(controller.widget.outerContext).client,
mxContent: avatarUrl,
name: displayname,
size: Avatar.defaultSize * 2.5,
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TextButton.icon( TextButton.icon(
onPressed: () => FluffyShare.share(
userId,
context,
copyOnly: true,
),
icon: const Icon(
Icons.copy_outlined,
size: 14,
),
style: TextButton.styleFrom( style: TextButton.styleFrom(
foregroundColor: theme.colorScheme.onSurface, backgroundColor: theme.colorScheme.surface,
foregroundColor: theme.colorScheme.primary,
), ),
label: Text( onPressed: controller.knockAccept,
userId, icon: const Icon(Icons.check_outlined),
maxLines: 1, label: Text(L10n.of(context).accept),
overflow: TextOverflow.ellipsis, ),
const SizedBox(width: 12),
TextButton.icon(
style: TextButton.styleFrom(
backgroundColor: theme.colorScheme.errorContainer,
foregroundColor:
theme.colorScheme.onErrorContainer,
), ),
onPressed: controller.knockDecline,
icon: const Icon(Icons.cancel_outlined),
label: Text(L10n.of(context).decline),
),
],
),
),
),
),
Row(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Avatar(
client: Matrix.of(controller.widget.outerContext).client,
mxContent: avatarUrl,
name: displayname,
size: Avatar.defaultSize * 2.5,
),
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton.icon(
onPressed: () => FluffyShare.share(
userId,
context,
copyOnly: true,
),
icon: const Icon(
Icons.copy_outlined,
size: 14,
),
style: TextButton.styleFrom(
foregroundColor: theme.colorScheme.onSurface,
), ),
PresenceBuilder( label: Text(
userId: userId, userId,
client: client, maxLines: 1,
builder: (context, presence) { overflow: TextOverflow.ellipsis,
if (presence == null || ),
(presence.presence == PresenceType.offline && ),
presence.lastActiveTimestamp == null)) { PresenceBuilder(
return const SizedBox.shrink(); userId: userId,
} client: client,
builder: (context, presence) {
if (presence == null ||
(presence.presence == PresenceType.offline &&
presence.lastActiveTimestamp == null)) {
return const SizedBox.shrink();
}
final dotColor = presence.presence.isOnline final dotColor = presence.presence.isOnline
? Colors.green ? Colors.green
: presence.presence.isUnavailable : presence.presence.isUnavailable
? Colors.orange ? Colors.orange
: Colors.grey; : Colors.grey;
final lastActiveTimestamp = final lastActiveTimestamp =
presence.lastActiveTimestamp; presence.lastActiveTimestamp;
return Row( return Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
const SizedBox(width: 16), const SizedBox(width: 16),
Container( Container(
width: 8, width: 8,
height: 8, height: 8,
decoration: BoxDecoration( decoration: BoxDecoration(
color: dotColor, color: dotColor,
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
),
), ),
const SizedBox(width: 12), ),
if (presence.currentlyActive == true) const SizedBox(width: 12),
Text( if (presence.currentlyActive == true)
L10n.of(context).currentlyActive, Text(
overflow: TextOverflow.ellipsis, L10n.of(context).currentlyActive,
style: theme.textTheme.bodySmall, overflow: TextOverflow.ellipsis,
) style: theme.textTheme.bodySmall,
else if (lastActiveTimestamp != null) )
Text( else if (lastActiveTimestamp != null)
L10n.of(context).lastActiveAgo( Text(
lastActiveTimestamp L10n.of(context).lastActiveAgo(
.localizedTimeShort(context), lastActiveTimestamp
), .localizedTimeShort(context),
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodySmall,
), ),
], overflow: TextOverflow.ellipsis,
); style: theme.textTheme.bodySmall,
}, ),
), ],
], );
), },
),
],
),
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(
horizontal: 16.0,
vertical: 8.0,
), ),
child: ElevatedButton.icon( ),
onPressed: () => controller.participantAction( ],
UserBottomSheetAction.message, ),
), PresenceBuilder(
icon: const Icon(Icons.forum_outlined), userId: userId,
label: Text( client: client,
dmRoomId == null builder: (context, presence) {
? L10n.of(context).startConversation final status = presence?.statusMsg;
: L10n.of(context).sendAMessage, 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(
horizontal: 16.0,
vertical: 8.0,
), ),
if (controller.widget.onMention != null) child: ElevatedButton.icon(
ListTile( onPressed: () => controller.participantAction(
leading: const Icon(Icons.alternate_email_outlined), UserBottomSheetAction.message,
title: Text(L10n.of(context).mention), ),
onTap: () => controller icon: const Icon(Icons.forum_outlined),
.participantAction(UserBottomSheetAction.mention), label: Text(
dmRoomId == null
? L10n.of(context).startConversation
: L10n.of(context).sendAMessage,
),
), ),
if (user != null) ...[ ),
Divider(color: theme.dividerColor), if (controller.widget.onMention != null)
ListTile( ListTile(
title: Text(L10n.of(context).userRole), leading: const Icon(Icons.alternate_email_outlined),
leading: const Icon(Icons.admin_panel_settings_outlined), title: Text(L10n.of(context).mention),
trailing: Material( onTap: () => controller
.participantAction(UserBottomSheetAction.mention),
),
if (user != null) ...[
Divider(color: theme.dividerColor),
ListTile(
title: Text(L10n.of(context).userRole),
leading: const Icon(Icons.admin_panel_settings_outlined),
trailing: Material(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius / 2),
color: theme.colorScheme.onInverseSurface,
child: DropdownButton<int>(
onChanged: user.canChangeUserPowerLevel ||
// Workaround until https://github.com/famedly/matrix-dart-sdk/pull/1765
(user.room.canChangePowerLevel &&
user.id == user.room.client.userID)
? controller.setPowerLevel
: null,
value: {0, 50, 100}.contains(user.powerLevel)
? user.powerLevel
: null,
padding: const EdgeInsets.symmetric(horizontal: 8.0),
borderRadius: borderRadius:
BorderRadius.circular(AppConfig.borderRadius / 2), BorderRadius.circular(AppConfig.borderRadius / 2),
color: theme.colorScheme.onInverseSurface, underline: const SizedBox.shrink(),
child: DropdownButton<int>( items: [
onChanged: user.canChangeUserPowerLevel || DropdownMenuItem(
// Workaround until https://github.com/famedly/matrix-dart-sdk/pull/1765 value: 0,
(user.room.canChangePowerLevel && child: Text(
user.id == user.room.client.userID) L10n.of(context).userLevel(
? controller.setPowerLevel user.powerLevel < 50 ? user.powerLevel : 0,
: null,
value: {0, 50, 100}.contains(user.powerLevel)
? user.powerLevel
: null,
padding: const EdgeInsets.symmetric(horizontal: 8.0),
borderRadius:
BorderRadius.circular(AppConfig.borderRadius / 2),
underline: const SizedBox.shrink(),
items: [
DropdownMenuItem(
value: 0,
child: Text(
L10n.of(context).userLevel(
user.powerLevel < 50 ? user.powerLevel : 0,
),
), ),
), ),
DropdownMenuItem( ),
value: 50, DropdownMenuItem(
child: Text( value: 50,
L10n.of(context).moderatorLevel( child: Text(
user.powerLevel >= 50 && user.powerLevel < 100 L10n.of(context).moderatorLevel(
? user.powerLevel user.powerLevel >= 50 && user.powerLevel < 100
: 50, ? user.powerLevel
), : 50,
), ),
), ),
DropdownMenuItem( ),
value: 100, DropdownMenuItem(
child: Text( value: 100,
L10n.of(context).adminLevel( child: Text(
user.powerLevel >= 100 ? user.powerLevel : 100, L10n.of(context).adminLevel(
), user.powerLevel >= 100 ? user.powerLevel : 100,
), ),
), ),
DropdownMenuItem( ),
value: null, DropdownMenuItem(
child: Text(L10n.of(context).custom), value: null,
), child: Text(L10n.of(context).custom),
], ),
), ],
), ),
), ),
], ),
Divider(color: theme.dividerColor), ],
if (user != null && user.canKick) Divider(color: theme.dividerColor),
ListTile( if (user != null && user.canKick)
textColor: theme.colorScheme.error, ListTile(
iconColor: theme.colorScheme.error, textColor: theme.colorScheme.error,
title: Text(L10n.of(context).kickFromChat), iconColor: theme.colorScheme.error,
leading: const Icon(Icons.exit_to_app_outlined), title: Text(L10n.of(context).kickFromChat),
onTap: () => controller leading: const Icon(Icons.exit_to_app_outlined),
.participantAction(UserBottomSheetAction.kick), onTap: () =>
), controller.participantAction(UserBottomSheetAction.kick),
if (user != null && ),
user.canBan && if (user != null &&
user.membership != Membership.ban) user.canBan &&
ListTile( user.membership != Membership.ban)
textColor: theme.colorScheme.onErrorContainer, ListTile(
iconColor: theme.colorScheme.onErrorContainer, textColor: theme.colorScheme.onErrorContainer,
title: Text(L10n.of(context).banFromChat), iconColor: theme.colorScheme.onErrorContainer,
leading: const Icon(Icons.warning_sharp), title: Text(L10n.of(context).banFromChat),
onTap: () => leading: const Icon(Icons.warning_sharp),
controller.participantAction(UserBottomSheetAction.ban), onTap: () =>
) controller.participantAction(UserBottomSheetAction.ban),
else if (user != null && )
user.canBan && else if (user != null &&
user.membership == Membership.ban) user.canBan &&
ListTile( user.membership == Membership.ban)
title: Text(L10n.of(context).unbanFromChat), ListTile(
leading: const Icon(Icons.warning_outlined), title: Text(L10n.of(context).unbanFromChat),
onTap: () => controller leading: const Icon(Icons.warning_outlined),
.participantAction(UserBottomSheetAction.unban), onTap: () =>
), controller.participantAction(UserBottomSheetAction.unban),
if (user != null && user.id != client.userID) ),
ListTile( if (user != null && user.id != client.userID)
textColor: theme.colorScheme.onErrorContainer, ListTile(
iconColor: theme.colorScheme.onErrorContainer, textColor: theme.colorScheme.onErrorContainer,
title: Text(L10n.of(context).reportUser), iconColor: theme.colorScheme.onErrorContainer,
leading: const Icon(Icons.gavel_outlined), title: Text(L10n.of(context).reportUser),
onTap: () => controller leading: const Icon(Icons.gavel_outlined),
.participantAction(UserBottomSheetAction.report), onTap: () => controller
), .participantAction(UserBottomSheetAction.report),
if (profileSearchError != null) ),
ListTile( if (profileSearchError != null)
leading: const Icon( ListTile(
Icons.warning_outlined, leading: const Icon(
color: Colors.orange, Icons.warning_outlined,
), color: Colors.orange,
subtitle: Text(
L10n.of(context).profileNotFound,
style: const TextStyle(color: Colors.orange),
),
), ),
if (userId != client.userID && subtitle: Text(
!client.ignoredUsers.contains(userId)) L10n.of(context).profileNotFound,
ListTile( style: const TextStyle(color: Colors.orange),
textColor: theme.colorScheme.onErrorContainer,
iconColor: theme.colorScheme.onErrorContainer,
leading: const Icon(Icons.block_outlined),
title: Text(L10n.of(context).block),
onTap: () => controller
.participantAction(UserBottomSheetAction.ignore),
), ),
], ),
); if (userId != client.userID &&
}, !client.ignoredUsers.contains(userId))
), ListTile(
textColor: theme.colorScheme.onErrorContainer,
iconColor: theme.colorScheme.onErrorContainer,
leading: const Icon(Icons.block_outlined),
title: Text(L10n.of(context).block),
onTap: () => controller
.participantAction(UserBottomSheetAction.ignore),
),
],
);
},
), ),
); );
} }

@ -10,6 +10,7 @@ import 'package:fluffychat/utils/url_launcher.dart';
import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart'; import 'package:fluffychat/widgets/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart'; import 'package:fluffychat/widgets/matrix.dart';
import 'package:fluffychat/widgets/qr_code_viewer.dart';
class PublicRoomBottomSheet extends StatelessWidget { class PublicRoomBottomSheet extends StatelessWidget {
final String? roomAlias; final String? roomAlias;
@ -98,16 +99,17 @@ class PublicRoomBottomSheet extends StatelessWidget {
), ),
), ),
actions: [ actions: [
Padding( if (roomAlias != null)
padding: const EdgeInsets.symmetric(horizontal: 16.0), Padding(
child: IconButton( padding: const EdgeInsets.symmetric(horizontal: 16.0),
icon: Icon(Icons.adaptive.share_outlined), child: IconButton(
onPressed: () => FluffyShare.share( icon: Icon(Icons.adaptive.share_outlined),
'https://matrix.to/#/${roomAlias ?? chunk?.roomId}', onPressed: () => showQrCodeViewer(
context, context,
roomAlias,
),
), ),
), ),
),
], ],
), ),
body: FutureBuilder<PublicRoomsChunk>( body: FutureBuilder<PublicRoomsChunk>(

@ -0,0 +1,138 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:image/image.dart';
import 'package:matrix/matrix.dart';
import 'package:pretty_qr_code/pretty_qr_code.dart';
import 'package:qr_image/qr_image.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/utils/fluffy_share.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
import 'package:fluffychat/widgets/future_loading_dialog.dart';
import '../config/themes.dart';
Future<void> showQrCodeViewer(
BuildContext context,
String content,
) =>
showDialog(
context: context,
builder: (context) => QrCodeViewer(content: content),
);
class QrCodeViewer extends StatelessWidget {
final String content;
const QrCodeViewer({required this.content, super.key});
void _save(BuildContext context) async {
final imageResult = await showFutureLoadingDialog(
context: context,
future: () async {
final inviteLink = 'https://matrix.to/#/$content';
final image = QRImage(
inviteLink,
size: 256,
radius: 1,
).generate();
return compute(encodePng, image);
},
);
final bytes = imageResult.result;
if (bytes == null) return;
if (!context.mounted) return;
MatrixImageFile(
bytes: bytes,
name: 'QR_Code_$content.png',
mimeType: 'image/png',
).save(context);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final inviteLink = 'https://matrix.to/#/$content';
return Scaffold(
backgroundColor: Colors.black.withOpacity(0.5),
extendBodyBehindAppBar: true,
appBar: AppBar(
elevation: 0,
leading: IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
),
icon: const Icon(Icons.close),
onPressed: Navigator.of(context).pop,
color: Colors.white,
tooltip: L10n.of(context).close,
),
backgroundColor: Colors.transparent,
actions: [
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
),
icon: Icon(Icons.adaptive.share_outlined),
onPressed: () => FluffyShare.share(
inviteLink,
context,
),
color: Colors.white,
tooltip: L10n.of(context).share,
),
const SizedBox(width: 8),
IconButton(
style: IconButton.styleFrom(
backgroundColor: Colors.black.withOpacity(0.5),
),
icon: const Icon(Icons.download_outlined),
onPressed: () => _save(context),
color: Colors.white,
tooltip: L10n.of(context).downloadFile,
),
const SizedBox(width: 8),
],
),
body: Center(
child: Container(
margin: const EdgeInsets.all(32.0),
padding: const EdgeInsets.all(32.0),
decoration: BoxDecoration(
color: theme.colorScheme.primaryContainer,
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ConstrainedBox(
constraints:
const BoxConstraints(maxWidth: FluffyThemes.columnWidth),
child: PrettyQrView.data(
data: inviteLink,
decoration: PrettyQrDecoration(
shape: PrettyQrSmoothSymbol(
roundFactor: 1,
color: theme.colorScheme.onPrimaryContainer,
),
),
),
),
const SizedBox(height: 8.0),
SelectableText(
content,
textAlign: TextAlign.center,
style: TextStyle(
color: theme.colorScheme.onPrimaryContainer,
fontSize: 12,
),
),
],
),
),
),
);
}
}

@ -1554,6 +1554,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.1" version: "1.0.1"
qr_image:
dependency: "direct main"
description:
name: qr_image
sha256: c3cd2ac2c6cd6b14604c97b45c477b18988b6518f72120fa04418fc54e3b0d76
url: "https://pub.dev"
source: hosted
version: "1.0.0"
quiver: quiver:
dependency: transitive dependency: transitive
description: description:

@ -76,6 +76,7 @@ dependencies:
provider: ^6.0.2 provider: ^6.0.2
punycode: ^1.0.0 punycode: ^1.0.0
qr_code_scanner: ^1.0.1 qr_code_scanner: ^1.0.1
qr_image: ^1.0.0
receive_sharing_intent: ^1.8.1 receive_sharing_intent: ^1.8.1
record: ^5.1.2 record: ^5.1.2
scroll_to_index: ^3.0.1 scroll_to_index: ^3.0.1

Loading…
Cancel
Save