fluffychat/lib/pages/views/new_private_chat_view.dart

118 lines
4.1 KiB
Dart
Raw Normal View History

2021-08-22 19:09:05 +00:00
import 'dart:math';
2021-10-26 16:50:34 +00: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-08-22 19:09:05 +00:00
import 'package:fluffychat/config/app_config.dart';
2021-05-22 06:57:49 +00:00
import 'package:fluffychat/pages/new_private_chat.dart';
2021-08-22 19:19:22 +00:00
import 'package:fluffychat/utils/platform_infos.dart';
2021-05-22 06:53:52 +00:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
import 'package:fluffychat/widgets/matrix.dart';
2021-04-15 07:05:41 +00:00
2021-05-22 07:13:47 +00:00
class NewPrivateChatView extends StatelessWidget {
2021-04-15 07:05:41 +00:00
final NewPrivateChatController controller;
2021-05-22 07:13:47 +00:00
const NewPrivateChatView(this.controller, {Key key}) : super(key: key);
2021-04-15 07:05:41 +00:00
2021-08-22 19:09:05 +00:00
static const double _qrCodePadding = 8;
2021-04-15 07:05:41 +00:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-10-14 16:09:30 +00:00
leading: const BackButton(),
2021-04-15 07:05:41 +00:00
title: Text(L10n.of(context).newChat),
2021-08-22 19:50:19 +00:00
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
2021-04-15 07:05:41 +00:00
elevation: 0,
actions: [
TextButton(
2021-07-08 15:10:20 +00:00
onPressed: () => VRouter.of(context).to('/newgroup'),
2021-04-15 07:05:41 +00:00
child: Text(
L10n.of(context).createNewGroup,
2021-05-24 08:59:00 +00:00
style: TextStyle(color: Theme.of(context).colorScheme.secondary),
2021-04-15 07:05:41 +00:00
),
)
],
),
body: MaxWidthBody(
2021-08-22 19:09:05 +00:00
child: ListView(
children: [
Container(
2021-10-14 16:09:30 +00:00
margin: const EdgeInsets.all(_qrCodePadding),
2021-08-22 19:09:05 +00:00
alignment: Alignment.center,
2021-10-14 16:09:30 +00:00
padding: const EdgeInsets.all(_qrCodePadding * 2),
2021-10-08 05:30:41 +00:00
child: InkWell(
onTap: controller.inviteAction,
2021-08-22 19:09:05 +00:00
borderRadius: BorderRadius.circular(12),
2021-10-08 05:30:41 +00: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 16:09:30 +00:00
embeddedImage: const AssetImage('assets/share.png'),
2021-10-08 05:30:41 +00:00
embeddedImageStyle: QrEmbeddedImageStyle(
2021-10-14 16:09:30 +00:00
size: const Size(48, 48),
2021-10-08 05:30:41 +00:00
),
),
2021-08-22 19:09:05 +00:00
),
),
),
2021-10-14 16:09:30 +00:00
const Divider(),
2021-08-22 19:09:05 +00:00
ListTile(
2021-08-23 16:32:57 +00:00
subtitle: Text(L10n.of(context).createNewChatExplaination),
2021-10-14 16:09:30 +00:00
trailing: const Padding(
padding: EdgeInsets.all(8.0),
2021-08-23 16:32:57 +00:00
child: Icon(Icons.info_outline_rounded),
2021-08-22 19:09:05 +00:00
),
),
2021-10-14 16:09:30 +00:00
const Divider(),
2021-04-15 07:05:41 +00:00
Padding(
2021-10-14 16:09:30 +00:00
padding: const EdgeInsets.all(12),
2021-04-15 07:05:41 +00: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 19:09:05 +00:00
labelText: L10n.of(context).typeInInviteLinkManually,
hintText: '@username',
prefixText: 'https://matrix.to/#/',
2021-04-15 07:05:41 +00:00
suffixIcon: IconButton(
2021-10-14 16:09:30 +00:00
icon: const Icon(Icons.send_outlined),
2021-04-15 07:05:41 +00:00
onPressed: controller.submitAction,
),
),
),
),
),
2021-08-22 19:09:05 +00:00
Center(
child: Image.asset(
'assets/private_chat_wallpaper.png',
2021-08-23 16:32:57 +00:00
width: min(AppConfig.columnWidth - _qrCodePadding * 6,
MediaQuery.of(context).size.width - _qrCodePadding * 6),
2021-04-15 07:05:41 +00:00
),
),
],
),
),
2021-08-22 19:19:22 +00:00
floatingActionButton: PlatformInfos.isMobile
? FloatingActionButton.extended(
onPressed: controller.openScannerAction,
label: Text(L10n.of(context).scanQrCode),
2021-10-14 16:09:30 +00:00
icon: const Icon(Icons.camera_alt_outlined),
2021-08-22 19:19:22 +00:00
)
: null,
2021-04-15 07:05:41 +00:00
);
}
}