fluffychat/lib/pages/new_private_chat/new_private_chat_view.dart

125 lines
4.5 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-11-09 20:32:16 +00:00
import 'package:fluffychat/pages/new_private_chat/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;
2022-01-29 11:35:03 +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(),
2022-01-29 11:35:03 +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
actions: [
2022-12-30 13:37:13 +00: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 07:05:41 +00:00
),
)
],
),
2022-12-30 15:27:44 +00: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,
size: min(MediaQuery.of(context).size.width - 16, 200),
),
TextButton.icon(
icon: Icon(Icons.adaptive.share_outlined),
label: Text(L10n.of(context)!.shareYourInviteLink),
onPressed: controller.inviteAction,
),
const SizedBox(height: 8),
],
),
2021-04-15 07:05:41 +00:00
),
2022-12-30 15:27:44 +00:00
),
2021-04-15 07:05:41 +00:00
),
2022-12-30 13:37:13 +00:00
),
2022-12-30 15:27:44 +00: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 15:27:44 +00:00
hintText: '@username',
prefixText: NewPrivateChatController.prefixNoProtocol,
suffixIcon: IconButton(
icon: const Icon(Icons.send_outlined),
onPressed: controller.submitAction,
),
),
2022-12-30 07:39:58 +00:00
),
),
),
2022-12-30 13:37:13 +00:00
),
2022-12-30 15:27:44 +00:00
],
2021-04-15 07:05:41 +00:00
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
2022-12-30 16:45:58 +00:00
floatingActionButton: PlatformInfos.isMobile
2022-12-30 15:27:44 +00:00
? Padding(
padding: const EdgeInsets.only(bottom: 64.0),
child: FloatingActionButton.extended(
onPressed: controller.openScannerAction,
label: Text(L10n.of(context)!.scanQrCode),
icon: const Icon(Icons.camera_alt_outlined),
),
2021-08-22 19:19:22 +00:00
)
: null,
2021-04-15 07:05:41 +00:00
);
}
}