fluffychat/lib/pages/new_group.dart
Krille Fear e05a99293a Merge branch 'soru/escape-routes' into 'main'
fix: Properly encode and decode vRouter paths

See merge request famedly/fluffychat!487
2021-08-22 10:05:30 +00:00

42 lines
1.4 KiB
Dart

import 'package:matrix/matrix.dart' as sdk;
import 'package:fluffychat/pages/views/new_group_view.dart';
import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/material.dart';
import 'package:vrouter/vrouter.dart';
class NewGroup extends StatefulWidget {
@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 matrix = Matrix.of(context);
final roomID = await showFutureLoadingDialog(
context: context,
future: () => matrix.client.createRoom(
preset: publicGroup
? sdk.CreateRoomPreset.publicChat
: sdk.CreateRoomPreset.privateChat,
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) {
VRouter.of(context).toSegments(['rooms', roomID.result, 'invite']);
}
}
@override
Widget build(BuildContext context) => NewGroupView(this);
}