fluffychat/lib/pages/new_private_chat/new_private_chat_view.dart

135 lines
5.0 KiB
Dart
Raw Normal View History

2021-08-22 21:09:05 +02:00
import 'dart:math';
2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:qr_flutter/qr_flutter.dart';
import 'package:vrouter/vrouter.dart';
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/new_private_chat/new_private_chat.dart';
2021-08-22 21:19:22 +02:00
import 'package:fluffychat/utils/platform_infos.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-04-15 09:05:41 +02:00
2021-05-22 09:13:47 +02:00
class NewPrivateChatView extends StatelessWidget {
2021-04-15 09:05:41 +02:00
final NewPrivateChatController controller;
2022-01-29 12:35:03 +01:00
const NewPrivateChatView(this.controller, {Key? key}) : super(key: key);
2021-04-15 09:05:41 +02:00
2021-08-22 21:09:05 +02:00
static const double _qrCodePadding = 8;
2021-04-15 09:05:41 +02:00
@override
Widget build(BuildContext context) {
2023-02-26 21:13:56 +01:00
final qrCodeSize =
2023-03-12 17:39:04 +01:00
min(MediaQuery.of(context).size.width - 16, 256).toDouble();
2021-04-15 09:05:41 +02:00
return Scaffold(
appBar: AppBar(
2021-10-14 18:09:30 +02:00
leading: const BackButton(),
2022-01-29 12:35:03 +01:00
title: Text(L10n.of(context)!.newChat),
2021-08-22 21:50:19 +02:00
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
2021-04-15 09:05:41 +02:00
actions: [
2022-12-30 14:37:13 +01:00
Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
onPressed: () => VRouter.of(context).to('/newgroup'),
child: Text(
L10n.of(context)!.createNewGroup,
style:
TextStyle(color: Theme.of(context).colorScheme.secondary),
),
2021-04-15 09:05:41 +02:00
),
)
],
),
2022-12-30 16:27:44 +01:00
body: Column(
children: [
Expanded(
child: MaxWidthBody(
withScrolling: true,
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: [
QrImage(
data:
'https://matrix.to/#/${Matrix.of(context).client.userID}',
version: QrVersions.auto,
2023-02-26 21:13:56 +01:00
size: qrCodeSize,
2022-12-30 16:27:44 +01:00
),
TextButton.icon(
2023-02-26 21:13:56 +01:00
style: TextButton.styleFrom(
fixedSize:
Size.fromWidth(qrCodeSize - (2 * _qrCodePadding)),
),
2022-12-30 16:27:44 +01:00
icon: Icon(Icons.adaptive.share_outlined),
label: Text(L10n.of(context)!.shareYourInviteLink),
onPressed: controller.inviteAction,
),
const SizedBox(height: 8),
2023-02-26 21:13:56 +01:00
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,
),
const SizedBox(height: 8),
],
2022-12-30 16:27:44 +01:00
],
),
2021-04-15 09:05:41 +02:00
),
2022-12-30 16:27:44 +01:00
),
2021-04-15 09:05:41 +02:00
),
2022-12-30 14:37:13 +01:00
),
2022-12-30 16:27:44 +01:00
MaxWidthBody(
withScrolling: false,
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,
),
labelText: L10n.of(context)!.enterInviteLinkOrMatrixId,
2022-12-30 16:27:44 +01:00
hintText: '@username',
prefixText: NewPrivateChatController.prefixNoProtocol,
suffixIcon: IconButton(
icon: const Icon(Icons.send_outlined),
onPressed: controller.submitAction,
),
),
2022-12-30 08:39:58 +01:00
),
),
),
2022-12-30 14:37:13 +01:00
),
2022-12-30 16:27:44 +01:00
],
2021-04-15 09:05:41 +02:00
),
);
}
}