2021-10-26 18:50:34 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
2021-06-18 10:29:48 +02:00
|
|
|
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 {
|
2022-01-29 12:35:03 +01:00
|
|
|
const NewGroup({Key? key}) : super(key: key);
|
2021-10-14 18:09:30 +02:00
|
|
|
|
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 {
|
2021-10-10 10:43:50 +02:00
|
|
|
final client = Matrix.of(context).client;
|
2021-04-13 16:28:27 +02:00
|
|
|
final roomID = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
2021-10-10 10:43:50 +02:00
|
|
|
future: () async {
|
2021-11-13 11:51:35 +01:00
|
|
|
final roomId = await client.createGroupChat(
|
2021-10-10 10:43:50 +02:00
|
|
|
preset: publicGroup
|
|
|
|
? sdk.CreateRoomPreset.publicChat
|
|
|
|
: sdk.CreateRoomPreset.privateChat,
|
2021-11-13 11:51:35 +01:00
|
|
|
groupName: controller.text.isNotEmpty ? controller.text : null,
|
2021-10-10 10:43:50 +02:00
|
|
|
);
|
|
|
|
return roomId;
|
|
|
|
},
|
2021-04-13 16:28:27 +02:00
|
|
|
);
|
2021-05-23 13:11:55 +02:00
|
|
|
if (roomID.error == null) {
|
2022-01-29 12:35:03 +01: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
|
|
|
}
|