2021-08-01 06:05:40 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-10-26 16:50:34 +00:00
|
|
|
|
|
|
|
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|
|
|
import 'package:matrix/matrix.dart' as sdk;
|
2021-08-01 06:05:40 +00:00
|
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:vrouter/vrouter.dart';
|
|
|
|
|
2021-10-26 16:50:34 +00:00
|
|
|
import 'package:fluffychat/pages/views/new_space_view.dart';
|
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
|
|
|
|
2021-08-01 06:05:40 +00:00
|
|
|
class NewSpace extends StatefulWidget {
|
2021-10-14 16:09:30 +00:00
|
|
|
const NewSpace({Key key}) : super(key: key);
|
|
|
|
|
2021-08-01 06:05:40 +00:00
|
|
|
@override
|
|
|
|
NewSpaceController createState() => NewSpaceController();
|
|
|
|
}
|
|
|
|
|
|
|
|
class NewSpaceController extends State<NewSpace> {
|
|
|
|
TextEditingController controller = TextEditingController();
|
|
|
|
bool publicGroup = false;
|
|
|
|
|
|
|
|
void setPublicGroup(bool b) => setState(() => publicGroup = b);
|
|
|
|
|
|
|
|
void submitAction([_]) async {
|
|
|
|
final matrix = Matrix.of(context);
|
|
|
|
final roomID = await showFutureLoadingDialog(
|
|
|
|
context: context,
|
|
|
|
future: () => matrix.client.createRoom(
|
|
|
|
preset: publicGroup
|
2021-08-18 15:24:59 +00:00
|
|
|
? sdk.CreateRoomPreset.publicChat
|
|
|
|
: sdk.CreateRoomPreset.privateChat,
|
2021-08-01 06:05:40 +00:00
|
|
|
creationContent: {'type': RoomCreationTypes.mSpace},
|
|
|
|
visibility: publicGroup ? sdk.Visibility.public : null,
|
|
|
|
roomAliasName: publicGroup && controller.text.isNotEmpty
|
|
|
|
? controller.text.trim().toLowerCase().replaceAll(' ', '_')
|
|
|
|
: null,
|
|
|
|
name: controller.text.isNotEmpty ? controller.text : null,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
if (roomID.error == null) {
|
2021-08-15 11:26:16 +00:00
|
|
|
VRouter.of(context).toSegments(['rooms', roomID.result, 'details']);
|
2021-08-01 06:05:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) => NewSpaceView(this);
|
|
|
|
}
|