fluffychat/lib/pages/new_group/new_group.dart

45 lines
1.3 KiB
Dart
Raw Normal View History

2021-10-26 18:50:34 +02:00
import 'package:flutter/material.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart' as sdk;
2021-10-26 18:50:34 +02:00
import 'package:vrouter/vrouter.dart';
2021-11-09 21:32:16 +01:00
import 'package:fluffychat/pages/new_group/new_group_view.dart';
2021-05-22 08:53:52 +02:00
import 'package:fluffychat/widgets/matrix.dart';
2021-04-13 16:28:27 +02:00
class NewGroup extends StatefulWidget {
2021-10-14 18:09:30 +02:00
const NewGroup({Key key}) : super(key: key);
2021-04-13 16:28:27 +02:00
@override
NewGroupController createState() => NewGroupController();
}
class NewGroupController extends State<NewGroup> {
TextEditingController controller = TextEditingController();
bool publicGroup = false;
void setPublicGroup(bool b) => setState(() => publicGroup = b);
void submitAction([_]) async {
final client = Matrix.of(context).client;
2021-04-13 16:28:27 +02:00
final roomID = await showFutureLoadingDialog(
context: context,
future: () async {
2021-11-13 11:51:35 +01:00
final roomId = await client.createGroupChat(
preset: publicGroup
? sdk.CreateRoomPreset.publicChat
: sdk.CreateRoomPreset.privateChat,
2021-11-13 11:51:35 +01:00
groupName: controller.text.isNotEmpty ? controller.text : null,
);
return roomId;
},
2021-04-13 16:28:27 +02:00
);
2021-05-23 13:11:55 +02:00
if (roomID.error == null) {
2021-08-15 13:26:16 +02:00
VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']);
2021-04-13 16:28:27 +02:00
}
}
@override
2021-05-22 09:13:47 +02:00
Widget build(BuildContext context) => NewGroupView(this);
2021-04-13 16:28:27 +02:00
}