2020-01-01 19:10:13 +01:00
|
|
|
import 'package:fluffychat/views/chat.dart';
|
2020-01-19 16:56:13 +01:00
|
|
|
import 'package:fluffychat/views/invitation_selection.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-01-19 16:56:13 +01:00
|
|
|
import 'package:pedantic/pedantic.dart';
|
2020-01-01 19:10:13 +01:00
|
|
|
|
|
|
|
import '../matrix.dart';
|
|
|
|
|
2020-01-19 16:56:13 +01:00
|
|
|
class NewGroupDialog extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_NewGroupDialogState createState() => _NewGroupDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NewGroupDialogState extends State<NewGroupDialog> {
|
|
|
|
TextEditingController controller = TextEditingController();
|
|
|
|
bool publicGroup = false;
|
2020-01-01 19:10:13 +01:00
|
|
|
|
|
|
|
void submitAction(BuildContext context) async {
|
|
|
|
final MatrixState matrix = Matrix.of(context);
|
|
|
|
Map<String, dynamic> params = {};
|
2020-01-19 16:56:13 +01:00
|
|
|
if (publicGroup) {
|
|
|
|
params["preset"] = "public_chat";
|
|
|
|
params["visibility"] = "public";
|
|
|
|
if (controller.text.isNotEmpty) {
|
|
|
|
params["room_alias_name"] = controller.text;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
params["preset"] = "private_chat";
|
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
if (controller.text.isNotEmpty) params["name"] = controller.text;
|
|
|
|
final String roomID = await matrix.tryRequestWithLoadingDialog(
|
|
|
|
matrix.client.createRoom(params: params),
|
|
|
|
);
|
|
|
|
Navigator.of(context).pop();
|
2020-01-02 22:31:39 +01:00
|
|
|
if (roomID != null) {
|
2020-01-19 16:56:13 +01:00
|
|
|
unawaited(
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return Chat(roomID);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
await Navigator.push(
|
2020-01-01 19:10:13 +01:00
|
|
|
context,
|
2020-01-19 16:56:13 +01:00
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => InvitationSelection(
|
|
|
|
matrix.client.getRoomById(roomID),
|
|
|
|
),
|
|
|
|
),
|
2020-01-01 19:10:13 +01:00
|
|
|
);
|
2020-01-02 22:31:39 +01:00
|
|
|
}
|
2020-01-01 19:10:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text("Create new group"),
|
|
|
|
content: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
TextField(
|
|
|
|
controller: controller,
|
|
|
|
autocorrect: false,
|
2020-01-19 17:12:03 +01:00
|
|
|
autofocus: true,
|
2020-01-01 19:10:13 +01:00
|
|
|
textInputAction: TextInputAction.go,
|
|
|
|
onSubmitted: (s) => submitAction(context),
|
|
|
|
decoration: InputDecoration(
|
2020-01-19 16:56:13 +01:00
|
|
|
labelText: "(Optional) Group name",
|
2020-01-01 19:10:13 +01:00
|
|
|
icon: Icon(Icons.people),
|
|
|
|
hintText: "Enter a group name"),
|
|
|
|
),
|
2020-01-19 16:56:13 +01:00
|
|
|
SwitchListTile(
|
|
|
|
title: Text("Group is public"),
|
|
|
|
value: publicGroup,
|
|
|
|
onChanged: (bool b) => setState(() => publicGroup = b),
|
|
|
|
),
|
2020-01-01 19:10:13 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
|
|
|
child: Text("Close".toUpperCase(),
|
|
|
|
style: TextStyle(color: Colors.blueGrey)),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text("Create".toUpperCase()),
|
|
|
|
onPressed: () => submitAction(context),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|