fluffychat/lib/pages/views/new_private_chat_view.dart

116 lines
4.1 KiB
Dart
Raw Normal View History

2021-08-22 21:09:05 +02:00
import 'dart:math';
import 'package:fluffychat/config/app_config.dart';
2021-05-22 08:57:49 +02:00
import 'package:fluffychat/pages/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
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2021-08-22 21:09:05 +02:00
import 'package:qr_flutter/qr_flutter.dart';
2021-05-23 13:11:55 +02:00
import 'package:vrouter/vrouter.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;
2021-05-22 09:13:47 +02: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(),
2021-04-15 09:05:41 +02: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
elevation: 0,
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(
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-08-22 21:09:05 +02:00
child: ListView(
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),
elevation: 4,
color: Colors.white,
child: QrImage(
data:
'https://matrix.to/#/${Matrix.of(context).client.userID}',
version: QrVersions.auto,
size: min(MediaQuery.of(context).size.width - 16, 200),
2021-10-14 18:09:30 +02:00
embeddedImage: const AssetImage('assets/share.png'),
2021-10-08 07:30:41 +02:00
embeddedImageStyle: QrEmbeddedImageStyle(
2021-10-14 18:09:30 +02:00
size: const Size(48, 48),
2021-10-08 07:30:41 +02:00
),
),
2021-08-22 21:09:05 +02:00
),
),
),
2021-10-14 18:09:30 +02:00
const Divider(),
2021-08-22 21:09:05 +02:00
ListTile(
2021-08-23 18:32:57 +02:00
subtitle: Text(L10n.of(context).createNewChatExplaination),
2021-10-14 18:09:30 +02:00
trailing: const Padding(
padding: EdgeInsets.all(8.0),
2021-08-23 18:32:57 +02:00
child: Icon(Icons.info_outline_rounded),
2021-08-22 21:09:05 +02:00
),
),
2021-10-14 18:09:30 +02:00
const Divider(),
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,
textInputAction: TextInputAction.go,
onFieldSubmitted: controller.submitAction,
validator: controller.validateForm,
decoration: InputDecoration(
2021-08-22 21:09:05 +02:00
labelText: L10n.of(context).typeInInviteLinkManually,
hintText: '@username',
prefixText: 'https://matrix.to/#/',
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,
),
),
),
),
),
2021-08-22 21:09:05 +02:00
Center(
child: Image.asset(
'assets/private_chat_wallpaper.png',
2021-08-23 18:32:57 +02:00
width: min(AppConfig.columnWidth - _qrCodePadding * 6,
MediaQuery.of(context).size.width - _qrCodePadding * 6),
2021-04-15 09:05:41 +02:00
),
),
],
),
),
2021-08-22 21:19:22 +02:00
floatingActionButton: PlatformInfos.isMobile
? FloatingActionButton.extended(
onPressed: controller.openScannerAction,
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
);
}
}