fluffychat/lib/pages/new_group/new_group_view.dart

168 lines
6.2 KiB
Dart
Raw Normal View History

2021-04-13 14:28:27 +00:00
import 'package:flutter/material.dart';
2021-10-26 16:50:34 +00:00
2021-04-13 14:28:27 +00:00
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/config/themes.dart';
2021-11-09 20:32:16 +00:00
import 'package:fluffychat/pages/new_group/new_group.dart';
import 'package:fluffychat/utils/localized_exception_extension.dart';
import 'package:fluffychat/widgets/avatar.dart';
2021-10-26 16:50:34 +00:00
import 'package:fluffychat/widgets/layouts/max_width_body.dart';
2021-05-22 07:13:47 +00:00
class NewGroupView extends StatelessWidget {
2021-04-13 14:28:27 +00:00
final NewGroupController controller;
const NewGroupView(this.controller, {super.key});
2021-04-13 14:28:27 +00:00
@override
Widget build(BuildContext context) {
final avatar = controller.avatar;
final error = controller.error;
2021-04-13 14:28:27 +00:00
return Scaffold(
appBar: AppBar(
leading: Center(
child: BackButton(
onPressed: controller.loading ? null : Navigator.of(context).pop,
),
),
2023-08-11 12:07:51 +00:00
title: Text(L10n.of(context)!.createGroup),
2021-04-13 14:28:27 +00:00
),
body: MaxWidthBody(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
children: [
InkWell(
borderRadius: BorderRadius.circular(90),
onTap: controller.loading ? null : controller.selectPhoto,
child: CircleAvatar(
radius: Avatar.defaultSize / 2,
child: avatar == null
? const Icon(Icons.camera_alt_outlined)
2023-11-19 13:29:04 +00:00
: ClipRRect(
borderRadius: BorderRadius.circular(90),
child: Image.memory(
avatar,
width: Avatar.defaultSize,
height: Avatar.defaultSize,
fit: BoxFit.cover,
),
),
),
),
const SizedBox(width: 16),
Expanded(
child: TextField(
controller: controller.nameController,
autocorrect: false,
readOnly: controller.loading,
decoration: InputDecoration(
prefixIcon: const Icon(Icons.people_outlined),
hintText: L10n.of(context)!.groupName,
),
),
),
],
),
),
const SizedBox(height: 16),
2021-04-13 14:28:27 +00:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
2021-04-13 14:28:27 +00:00
child: TextField(
controller: controller.topicController,
minLines: 4,
maxLines: 4,
maxLength: 255,
readOnly: controller.loading,
2021-04-13 14:28:27 +00:00
decoration: InputDecoration(
hintText: L10n.of(context)!.addChatDescription,
),
2021-04-13 14:28:27 +00:00
),
),
const SizedBox(height: 16),
2021-11-27 09:10:29 +00:00
SwitchListTile.adaptive(
2022-12-25 09:45:13 +00:00
secondary: const Icon(Icons.public_outlined),
2022-01-29 11:35:03 +00:00
title: Text(L10n.of(context)!.groupIsPublic),
2021-04-13 14:28:27 +00:00
value: controller.publicGroup,
onChanged: controller.loading ? null : controller.setPublicGroup,
),
AnimatedSize(
duration: FluffyThemes.animationDuration,
child: controller.publicGroup
? SwitchListTile.adaptive(
secondary: const Icon(Icons.search_outlined),
title: Text(L10n.of(context)!.groupCanBeFoundViaSearch),
value: controller.groupCanBeFound,
onChanged: controller.loading
? null
: controller.setGroupCanBeFound,
)
: const SizedBox.shrink(),
2021-04-13 14:28:27 +00:00
),
2022-12-25 09:45:13 +00:00
SwitchListTile.adaptive(
secondary: Icon(
Icons.lock_outlined,
2024-05-16 07:05:04 +00:00
color: Theme.of(context).colorScheme.onSurface,
),
title: Text(
L10n.of(context)!.enableEncryption,
style: TextStyle(
2024-05-16 07:05:04 +00:00
color: Theme.of(context).colorScheme.onSurface,
),
),
2022-12-25 09:45:13 +00:00
value: !controller.publicGroup,
onChanged: null,
2021-04-13 14:28:27 +00:00
),
Padding(
padding: const EdgeInsets.all(16.0),
child: SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
foregroundColor: Theme.of(context).colorScheme.onPrimary,
backgroundColor: Theme.of(context).colorScheme.primary,
),
onPressed:
controller.loading ? null : controller.submitAction,
child: controller.loading
? const LinearProgressIndicator()
: Row(
children: [
Expanded(
child: Text(
L10n.of(context)!.createGroupAndInviteUsers,
),
),
Icon(Icons.adaptive.arrow_forward_outlined),
],
),
),
),
),
AnimatedSize(
duration: FluffyThemes.animationDuration,
child: error == null
? const SizedBox.shrink()
: ListTile(
leading: Icon(
Icons.warning_outlined,
color: Theme.of(context).colorScheme.error,
),
title: Text(
error.toLocalizedString(context),
style: TextStyle(
color: Theme.of(context).colorScheme.error,
),
),
),
),
2021-04-13 14:28:27 +00:00
],
),
),
);
}
}