|
|
|
@ -4,10 +4,15 @@ import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
|
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
|
|
|
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
|
|
|
|
import 'package:fluffychat/config/themes.dart';
|
|
|
|
|
import 'package:fluffychat/pages/new_private_chat/new_private_chat.dart';
|
|
|
|
|
import 'package:fluffychat/utils/platform_infos.dart';
|
|
|
|
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
|
|
|
|
import 'package:fluffychat/utils/url_launcher.dart';
|
|
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
|
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
|
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
|
|
|
|
|
@ -16,10 +21,9 @@ class NewPrivateChatView extends StatelessWidget {
|
|
|
|
|
|
|
|
|
|
const NewPrivateChatView(this.controller, {super.key});
|
|
|
|
|
|
|
|
|
|
static const double _qrCodePadding = 8;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final searchResponse = controller.searchResponse;
|
|
|
|
|
final qrCodeSize =
|
|
|
|
|
min(MediaQuery.of(context).size.width - 16, 256).toDouble();
|
|
|
|
|
return Scaffold(
|
|
|
|
@ -28,106 +32,221 @@ class NewPrivateChatView extends StatelessWidget {
|
|
|
|
|
title: Text(L10n.of(context)!.newChat),
|
|
|
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
|
|
|
actions: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: TextButton(
|
|
|
|
|
onPressed: () => context.go('/rooms/newgroup'),
|
|
|
|
|
child: Text(
|
|
|
|
|
L10n.of(context)!.createGroup,
|
|
|
|
|
style:
|
|
|
|
|
TextStyle(color: Theme.of(context).colorScheme.secondary),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed:
|
|
|
|
|
UrlLauncher(context, AppConfig.startChatTutorial).launchUrl,
|
|
|
|
|
icon: const Icon(Icons.info_outlined),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: MaxWidthBody(
|
|
|
|
|
withFrame: false,
|
|
|
|
|
child: Container(
|
|
|
|
|
margin: const EdgeInsets.all(_qrCodePadding),
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
padding: const EdgeInsets.all(_qrCodePadding * 2),
|
|
|
|
|
child: Material(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
elevation: 10,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
shadowColor: Theme.of(context).appBarTheme.shadowColor,
|
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
QrImageView(
|
|
|
|
|
data:
|
|
|
|
|
'https://matrix.to/#/${Matrix.of(context).client.userID}',
|
|
|
|
|
version: QrVersions.auto,
|
|
|
|
|
size: qrCodeSize,
|
|
|
|
|
),
|
|
|
|
|
TextButton.icon(
|
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
|
fixedSize:
|
|
|
|
|
Size.fromWidth(qrCodeSize - (2 * _qrCodePadding)),
|
|
|
|
|
foregroundColor: Colors.black,
|
|
|
|
|
body: MaxWidthBody(
|
|
|
|
|
withScrolling: false,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
|
|
|
|
child: TextField(
|
|
|
|
|
controller: controller.controller,
|
|
|
|
|
onChanged: controller.searchUsers,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: 'Search for @users...',
|
|
|
|
|
prefixIcon: searchResponse == null
|
|
|
|
|
? const Icon(Icons.search_outlined)
|
|
|
|
|
: FutureBuilder(
|
|
|
|
|
future: searchResponse,
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
if (snapshot.connectionState !=
|
|
|
|
|
ConnectionState.done) {
|
|
|
|
|
return const Padding(
|
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
|
child: SizedBox.square(
|
|
|
|
|
dimension: 24,
|
|
|
|
|
child: CircularProgressIndicator.adaptive(
|
|
|
|
|
strokeWidth: 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return const Icon(Icons.search_outlined);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
icon: Icon(Icons.adaptive.share_outlined),
|
|
|
|
|
label: Text(L10n.of(context)!.shareInviteLink),
|
|
|
|
|
onPressed: controller.inviteAction,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
if (PlatformInfos.isMobile) ...[
|
|
|
|
|
OutlinedButton.icon(
|
|
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
|
backgroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.primaryContainer,
|
|
|
|
|
fixedSize: Size.fromWidth(
|
|
|
|
|
qrCodeSize - (2 * _qrCodePadding),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
icon: const Icon(Icons.qr_code_scanner_outlined),
|
|
|
|
|
label: Text(L10n.of(context)!.scanQrCode),
|
|
|
|
|
onPressed: controller.openScannerAction,
|
|
|
|
|
suffixIcon: controller.controller.text.isEmpty
|
|
|
|
|
? null
|
|
|
|
|
: IconButton(
|
|
|
|
|
icon: const Icon(Icons.clear_outlined),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
controller.controller.clear();
|
|
|
|
|
controller.searchUsers();
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
MaxWidthBody(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(12.0),
|
|
|
|
|
child: Form(
|
|
|
|
|
key: controller.formKey,
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: controller.controller,
|
|
|
|
|
autocorrect: false,
|
|
|
|
|
textInputAction: TextInputAction.go,
|
|
|
|
|
focusNode: controller.textFieldFocus,
|
|
|
|
|
onFieldSubmitted: controller.submitAction,
|
|
|
|
|
validator: controller.validateForm,
|
|
|
|
|
inputFormatters: controller.removeMatrixToFormatters,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 12,
|
|
|
|
|
vertical: 6,
|
|
|
|
|
Expanded(
|
|
|
|
|
child: AnimatedCrossFade(
|
|
|
|
|
duration: FluffyThemes.animationDuration,
|
|
|
|
|
crossFadeState: searchResponse == null
|
|
|
|
|
? CrossFadeState.showFirst
|
|
|
|
|
: CrossFadeState.showSecond,
|
|
|
|
|
firstChild: ListView(
|
|
|
|
|
children: [
|
|
|
|
|
ListTile(
|
|
|
|
|
title: SelectableText.rich(
|
|
|
|
|
TextSpan(
|
|
|
|
|
children: [
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: L10n.of(context)!.yourGlobalUserIdIs,
|
|
|
|
|
),
|
|
|
|
|
TextSpan(
|
|
|
|
|
text: Matrix.of(context).client.userID,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color:
|
|
|
|
|
Theme.of(context).colorScheme.onPrimaryContainer,
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
trailing: IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.copy_outlined,
|
|
|
|
|
size: 16,
|
|
|
|
|
color:
|
|
|
|
|
Theme.of(context).colorScheme.onPrimaryContainer,
|
|
|
|
|
),
|
|
|
|
|
onPressed: controller.copyUserId,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
//if (PlatformInfos.isMobile)
|
|
|
|
|
ListTile(
|
|
|
|
|
leading: CircleAvatar(
|
|
|
|
|
backgroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.primaryContainer,
|
|
|
|
|
foregroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.onPrimaryContainer,
|
|
|
|
|
child: const Icon(Icons.qr_code_scanner_outlined),
|
|
|
|
|
),
|
|
|
|
|
title: Text(L10n.of(context)!.scanQrCode),
|
|
|
|
|
onTap: controller.openScannerAction,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
leading: CircleAvatar(
|
|
|
|
|
backgroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
|
foregroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.onSecondaryContainer,
|
|
|
|
|
child: Icon(Icons.adaptive.share_outlined),
|
|
|
|
|
),
|
|
|
|
|
title: Text(L10n.of(context)!.shareInviteLink),
|
|
|
|
|
onTap: controller.inviteAction,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
leading: CircleAvatar(
|
|
|
|
|
backgroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.tertiaryContainer,
|
|
|
|
|
foregroundColor:
|
|
|
|
|
Theme.of(context).colorScheme.onTertiaryContainer,
|
|
|
|
|
child: const Icon(Icons.group_add_outlined),
|
|
|
|
|
),
|
|
|
|
|
title: Text(L10n.of(context)!.createGroup),
|
|
|
|
|
onTap: () => context.go('/rooms/newgroup'),
|
|
|
|
|
),
|
|
|
|
|
labelText: L10n.of(context)!.enterInviteLinkOrMatrixId,
|
|
|
|
|
hintText: '@username',
|
|
|
|
|
prefixText: NewPrivateChatController.prefixNoProtocol,
|
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
|
icon: const Icon(Icons.send_outlined),
|
|
|
|
|
onPressed: controller.submitAction,
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
Center(
|
|
|
|
|
child: Material(
|
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
|
elevation: 10,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
shadowColor: Theme.of(context).appBarTheme.shadowColor,
|
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
|
child: QrImageView(
|
|
|
|
|
data:
|
|
|
|
|
'https://matrix.to/#/${Matrix.of(context).client.userID}',
|
|
|
|
|
version: QrVersions.auto,
|
|
|
|
|
size: qrCodeSize,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
secondChild: FutureBuilder(
|
|
|
|
|
future: searchResponse,
|
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
|
final result = snapshot.data;
|
|
|
|
|
final error = snapshot.error;
|
|
|
|
|
if (error != null) {
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
error.toLocalizedString(context),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Theme.of(context).colorScheme.error,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
OutlinedButton.icon(
|
|
|
|
|
onPressed: controller.searchUsers,
|
|
|
|
|
icon: const Icon(Icons.refresh_outlined),
|
|
|
|
|
label: Text(L10n.of(context)!.tryAgain),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (result == null) {
|
|
|
|
|
return const Center(
|
|
|
|
|
child: CircularProgressIndicator.adaptive(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (result.results.isEmpty) {
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
const Icon(Icons.search_outlined, size: 86),
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
|
child: Text(
|
|
|
|
|
L10n.of(context)!.noUsersFoundWithQuery(
|
|
|
|
|
controller.controller.text,
|
|
|
|
|
),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
|
),
|
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: result.results.length,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
final contact = result.results[i];
|
|
|
|
|
final displayname = contact.displayName ??
|
|
|
|
|
contact.userId.localpart ??
|
|
|
|
|
contact.userId;
|
|
|
|
|
return ListTile(
|
|
|
|
|
leading: Avatar(
|
|
|
|
|
name: displayname,
|
|
|
|
|
mxContent: contact.avatarUrl,
|
|
|
|
|
),
|
|
|
|
|
title: Text(displayname),
|
|
|
|
|
subtitle: Text(contact.userId),
|
|
|
|
|
onTap: () => controller.openUserModal(contact),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|