alterações em telas
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:tatchat/config/app_config.dart';
|
||||
import 'package:tatchat/l10n/l10n.dart';
|
||||
import 'package:tatchat/pages/new_group/new_group_view.dart';
|
||||
import 'package:tatchat/utils/file_selector.dart';
|
||||
@@ -127,6 +128,75 @@ class NewGroupController extends State<NewGroup> {
|
||||
context.pop<String>(spaceId);
|
||||
}
|
||||
|
||||
Future<void> _createCanal() async {
|
||||
if (!mounted) return;
|
||||
final client = Matrix.of(context).client;
|
||||
|
||||
final roomId = await client.createGroupChat(
|
||||
visibility: groupCanBeFound
|
||||
? sdk.Visibility.public
|
||||
: sdk.Visibility.private,
|
||||
preset: publicGroup
|
||||
? sdk.CreateRoomPreset.publicChat
|
||||
: sdk.CreateRoomPreset.privateChat,
|
||||
groupName: nameController.text.isNotEmpty ? nameController.text : null,
|
||||
powerLevelContentOverride: {
|
||||
// Only admins (power level 100) are allowed to post in a canal.
|
||||
'events_default': 100,
|
||||
},
|
||||
initialState: [
|
||||
if (avatar != null)
|
||||
sdk.StateEvent(
|
||||
type: sdk.EventTypes.RoomAvatar,
|
||||
content: {'url': avatarUrl.toString()},
|
||||
),
|
||||
],
|
||||
);
|
||||
final canal = client.getRoomById(roomId);
|
||||
if (canal != null) {
|
||||
await canal.addTag(AppConfig.canalTag);
|
||||
}
|
||||
await _addToSpace(roomId);
|
||||
if (!mounted) return;
|
||||
|
||||
context.go('/rooms/$roomId/invite');
|
||||
}
|
||||
|
||||
Future<void> _createMural() async {
|
||||
if (!mounted) return;
|
||||
final client = Matrix.of(context).client;
|
||||
|
||||
final roomId = await client.createGroupChat(
|
||||
visibility: groupCanBeFound
|
||||
? sdk.Visibility.public
|
||||
: sdk.Visibility.private,
|
||||
preset: publicGroup
|
||||
? sdk.CreateRoomPreset.publicChat
|
||||
: sdk.CreateRoomPreset.privateChat,
|
||||
groupName: nameController.text.isNotEmpty ? nameController.text : null,
|
||||
powerLevelContentOverride: publicGroup
|
||||
? null
|
||||
: {
|
||||
'events': {MatrixRtcCallMember.eventType: 0},
|
||||
},
|
||||
initialState: [
|
||||
if (avatar != null)
|
||||
sdk.StateEvent(
|
||||
type: sdk.EventTypes.RoomAvatar,
|
||||
content: {'url': avatarUrl.toString()},
|
||||
),
|
||||
],
|
||||
);
|
||||
final mural = client.getRoomById(roomId);
|
||||
if (mural != null) {
|
||||
await mural.addTag(AppConfig.muralTag);
|
||||
}
|
||||
await _addToSpace(roomId);
|
||||
if (!mounted) return;
|
||||
|
||||
context.go('/rooms/$roomId/invite');
|
||||
}
|
||||
|
||||
Future<void> _addToSpace(String roomId) async {
|
||||
final spaceId = widget.spaceId;
|
||||
if (spaceId != null) {
|
||||
@@ -164,6 +234,10 @@ class NewGroupController extends State<NewGroup> {
|
||||
await _createGroup();
|
||||
case CreateGroupType.space:
|
||||
await _createSpace();
|
||||
case CreateGroupType.canal:
|
||||
await _createCanal();
|
||||
case CreateGroupType.mural:
|
||||
await _createMural();
|
||||
}
|
||||
} catch (e, s) {
|
||||
sdk.Logs().d('Unable to create group', e, s);
|
||||
@@ -194,4 +268,4 @@ class NewGroupController extends State<NewGroup> {
|
||||
Widget build(BuildContext context) => NewGroupView(this);
|
||||
}
|
||||
|
||||
enum CreateGroupType { group, space }
|
||||
enum CreateGroupType { group, space, canal, mural }
|
||||
|
||||
@@ -16,6 +16,14 @@ class NewGroupView extends StatelessWidget {
|
||||
|
||||
const NewGroupView(this.controller, {super.key});
|
||||
|
||||
bool get isGroup => controller.createGroupType == CreateGroupType.group;
|
||||
|
||||
bool get isSpace => controller.createGroupType == CreateGroupType.space;
|
||||
|
||||
bool get isCanal => controller.createGroupType == CreateGroupType.canal;
|
||||
|
||||
bool get isMural => controller.createGroupType == CreateGroupType.mural;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -30,9 +38,13 @@ class NewGroupView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
controller.createGroupType == CreateGroupType.space
|
||||
isSpace
|
||||
? L10n.of(context).newSpace
|
||||
: L10n.of(context).createGroup,
|
||||
: isCanal
|
||||
? L10n.of(context).newCanal
|
||||
: isMural
|
||||
? L10n.of(context).newMural
|
||||
: L10n.of(context).createGroup,
|
||||
),
|
||||
),
|
||||
body: MaxWidthBody(
|
||||
@@ -41,19 +53,30 @@ class NewGroupView extends StatelessWidget {
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: SegmentedButton<CreateGroupType>(
|
||||
selected: {controller.createGroupType},
|
||||
onSelectionChanged: controller.setCreateGroupType,
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: CreateGroupType.group,
|
||||
label: Text(L10n.of(context).group),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: CreateGroupType.space,
|
||||
label: Text(L10n.of(context).space),
|
||||
),
|
||||
],
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: SegmentedButton<CreateGroupType>(
|
||||
selected: {controller.createGroupType},
|
||||
onSelectionChanged: controller.setCreateGroupType,
|
||||
segments: [
|
||||
ButtonSegment(
|
||||
value: CreateGroupType.group,
|
||||
label: Text(L10n.of(context).group),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: CreateGroupType.space,
|
||||
label: Text(L10n.of(context).space),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: CreateGroupType.canal,
|
||||
label: Text(L10n.of(context).canal),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: CreateGroupType.mural,
|
||||
label: Text(L10n.of(context).mural),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -85,9 +108,13 @@ class NewGroupView extends StatelessWidget {
|
||||
readOnly: controller.loading,
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.people_outlined),
|
||||
labelText: controller.createGroupType == CreateGroupType.space
|
||||
labelText: isSpace
|
||||
? L10n.of(context).spaceName
|
||||
: L10n.of(context).groupName,
|
||||
: isCanal
|
||||
? L10n.of(context).canalName
|
||||
: isMural
|
||||
? L10n.of(context).muralName
|
||||
: L10n.of(context).groupName,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -95,11 +122,15 @@ class NewGroupView extends StatelessWidget {
|
||||
SwitchListTile.adaptive(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 32),
|
||||
secondary: const Icon(Icons.public_outlined),
|
||||
title: Text(
|
||||
controller.createGroupType == CreateGroupType.space
|
||||
? L10n.of(context).spaceIsPublic
|
||||
: L10n.of(context).groupIsPublic,
|
||||
),
|
||||
title: Text(
|
||||
isSpace
|
||||
? L10n.of(context).spaceIsPublic
|
||||
: isCanal
|
||||
? L10n.of(context).canalIsPublic
|
||||
: isMural
|
||||
? L10n.of(context).muralIsPublic
|
||||
: L10n.of(context).groupIsPublic,
|
||||
),
|
||||
value: controller.publicGroup,
|
||||
onChanged: controller.loading ? null : controller.setPublicGroup,
|
||||
),
|
||||
@@ -144,7 +175,7 @@ class NewGroupView extends StatelessWidget {
|
||||
AnimatedSize(
|
||||
duration: FluffyThemes.animationDuration,
|
||||
curve: FluffyThemes.animationCurve,
|
||||
child: controller.createGroupType == CreateGroupType.space
|
||||
child: !isGroup
|
||||
? ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
@@ -153,7 +184,29 @@ class NewGroupView extends StatelessWidget {
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: Icon(Icons.info_outlined),
|
||||
),
|
||||
subtitle: Text(L10n.of(context).newSpaceDescription),
|
||||
subtitle: Text(
|
||||
isSpace
|
||||
? L10n.of(context).newSpaceDescription
|
||||
: isCanal
|
||||
? L10n.of(context).newCanalDescription
|
||||
: L10n.of(context).newMuralDescription,
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
AnimatedSize(
|
||||
duration: FluffyThemes.animationDuration,
|
||||
curve: FluffyThemes.animationCurve,
|
||||
child: isCanal
|
||||
? ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
),
|
||||
leading: Icon(
|
||||
Icons.admin_panel_settings_outlined,
|
||||
color: theme.colorScheme.onSurface,
|
||||
),
|
||||
subtitle: Text(L10n.of(context).canalOnlyAdminCanPost),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
@@ -168,9 +221,15 @@ class NewGroupView extends StatelessWidget {
|
||||
child: controller.loading
|
||||
? const LinearProgressIndicator()
|
||||
: Text(
|
||||
controller.createGroupType == CreateGroupType.space
|
||||
isSpace
|
||||
? L10n.of(context).createNewSpace
|
||||
: L10n.of(context).createGroupAndInviteUsers,
|
||||
: isCanal
|
||||
? L10n.of(context).createCanalAndInviteUsers
|
||||
: isMural
|
||||
? L10n.of(context)
|
||||
.createMuralAndInviteUsers
|
||||
: L10n.of(context)
|
||||
.createGroupAndInviteUsers,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user