fluffychat/lib/pages/new_private_chat/new_private_chat_view.dart

115 lines
4.1 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) {
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: [
TextButton(
2021-07-08 17:10:20 +02:00
onPressed: () => VRouter.of(context).to('/newgroup'),
2021-04-15 09:05:41 +02:00
child: Text(
2022-01-29 12:35:03 +01:00
L10n.of(context)!.createNewGroup,
2021-05-24 10:59:00 +02:00
style: TextStyle(color: Theme.of(context).colorScheme.secondary),
2021-04-15 09:05:41 +02:00
),
)
],
),
body: MaxWidthBody(
2021-11-13 20:37:51 +01:00
withScrolling: true,
child: Column(
2021-08-22 21:09:05 +02:00
children: [
Container(
2021-10-14 18:09:30 +02:00
margin: const EdgeInsets.all(_qrCodePadding),
2021-08-22 21:09:05 +02:00
alignment: Alignment.center,
2021-10-14 18:09:30 +02:00
padding: const EdgeInsets.all(_qrCodePadding * 2),
2021-10-08 07:30:41 +02:00
child: InkWell(
onTap: controller.inviteAction,
2021-08-22 21:09:05 +02:00
borderRadius: BorderRadius.circular(12),
2021-10-08 07:30:41 +02:00
child: Material(
borderRadius: BorderRadius.circular(12),
2022-06-04 20:06:57 +02:00
elevation: 6,
2021-10-08 07:30:41 +02:00
color: Colors.white,
2022-06-04 20:06:57 +02:00
shadowColor: const Color(0x44000000),
clipBehavior: Clip.hardEdge,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
QrImage(
data:
'https://matrix.to/#/${Matrix.of(context).client.userID}',
version: QrVersions.auto,
size: min(MediaQuery.of(context).size.width - 16, 200),
),
Image.asset('assets/share.png', width: 48, height: 48),
],
2021-10-08 07:30:41 +02:00
),
2021-08-22 21:09:05 +02:00
),
),
),
ListTile(
subtitle: Text(
L10n.of(context)!.createNewChatExplaination,
textAlign: TextAlign.center,
),
2021-08-22 21:09:05 +02:00
),
2021-04-15 09:05:41 +02:00
Padding(
2021-10-14 18:09:30 +02:00
padding: const EdgeInsets.all(12),
2021-04-15 09:05:41 +02:00
child: Form(
key: controller.formKey,
child: TextFormField(
controller: controller.controller,
autocorrect: false,
autofocus: !PlatformInfos.isMobile,
2021-04-15 09:05:41 +02:00
textInputAction: TextInputAction.go,
focusNode: controller.textFieldFocus,
2021-04-15 09:05:41 +02:00
onFieldSubmitted: controller.submitAction,
validator: controller.validateForm,
inputFormatters: controller.removeMatrixToFormatters,
2021-04-15 09:05:41 +02:00
decoration: InputDecoration(
2022-01-29 12:35:03 +01:00
labelText: L10n.of(context)!.typeInInviteLinkManually,
2021-08-22 21:09:05 +02:00
hintText: '@username',
prefixText: NewPrivateChatController.prefixNoProtocol,
2021-04-15 09:05:41 +02:00
suffixIcon: IconButton(
2021-10-14 18:09:30 +02:00
icon: const Icon(Icons.send_outlined),
2021-04-15 09:05:41 +02:00
onPressed: controller.submitAction,
),
),
),
),
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: PlatformInfos.isMobile && !controller.hideFab
2021-08-22 21:19:22 +02:00
? FloatingActionButton.extended(
onPressed: controller.openScannerAction,
2022-01-29 12:35:03 +01:00
label: Text(L10n.of(context)!.scanQrCode),
2021-10-14 18:09:30 +02:00
icon: const Icon(Icons.camera_alt_outlined),
2021-08-22 21:19:22 +02:00
)
: null,
2021-04-15 09:05:41 +02:00
);
}
}