2020-01-27 10:14:38 +01:00
|
|
|
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
2020-04-27 13:36:39 +02:00
|
|
|
import 'package:fluffychat/components/dialogs/simple_dialogs.dart';
|
2020-01-27 10:14:38 +01:00
|
|
|
import 'package:fluffychat/components/matrix.dart';
|
2020-05-07 07:52:40 +02:00
|
|
|
import 'package:fluffychat/l10n/l10n.dart';
|
2020-02-23 08:49:58 +01:00
|
|
|
import 'package:fluffychat/utils/app_route.dart';
|
2020-01-27 10:14:38 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:pedantic/pedantic.dart';
|
|
|
|
|
|
|
|
import 'chat.dart';
|
|
|
|
import 'chat_list.dart';
|
|
|
|
import 'invitation_selection.dart';
|
|
|
|
|
|
|
|
class NewGroupView extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AdaptivePageLayout(
|
|
|
|
primaryPage: FocusPage.SECOND,
|
|
|
|
firstScaffold: ChatList(),
|
|
|
|
secondScaffold: _NewGroup(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NewGroup extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_NewGroupState createState() => _NewGroupState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NewGroupState extends State<_NewGroup> {
|
|
|
|
TextEditingController controller = TextEditingController();
|
|
|
|
bool publicGroup = false;
|
|
|
|
|
|
|
|
void submitAction(BuildContext context) async {
|
2020-05-13 15:58:59 +02:00
|
|
|
final matrix = Matrix.of(context);
|
|
|
|
var params = <String, dynamic>{};
|
2020-01-27 10:14:38 +01:00
|
|
|
if (publicGroup) {
|
2020-05-13 15:58:59 +02:00
|
|
|
params['preset'] = 'public_chat';
|
|
|
|
params['visibility'] = 'public';
|
2020-01-27 10:14:38 +01:00
|
|
|
if (controller.text.isNotEmpty) {
|
2020-05-13 15:58:59 +02:00
|
|
|
params['room_alias_name'] = controller.text;
|
2020-01-27 10:14:38 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-05-13 15:58:59 +02:00
|
|
|
params['preset'] = 'private_chat';
|
2020-01-27 10:14:38 +01:00
|
|
|
}
|
2020-05-13 15:58:59 +02:00
|
|
|
if (controller.text.isNotEmpty) params['name'] = controller.text;
|
2020-04-27 13:36:39 +02:00
|
|
|
final String roomID =
|
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(
|
2020-01-27 10:14:38 +01:00
|
|
|
matrix.client.createRoom(params: params),
|
|
|
|
);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
if (roomID != null) {
|
|
|
|
unawaited(
|
2020-02-23 08:49:58 +01:00
|
|
|
Navigator.of(context).push(
|
|
|
|
AppRoute.defaultRoute(
|
|
|
|
context,
|
|
|
|
ChatView(roomID),
|
|
|
|
),
|
2020-01-27 10:14:38 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
await Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => InvitationSelection(
|
|
|
|
matrix.client.getRoomById(roomID),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).createNewGroup),
|
2020-01-27 10:14:38 +01:00
|
|
|
elevation: 0,
|
|
|
|
),
|
|
|
|
body: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(16.0),
|
|
|
|
child: TextField(
|
|
|
|
controller: controller,
|
|
|
|
autofocus: true,
|
|
|
|
autocorrect: false,
|
|
|
|
textInputAction: TextInputAction.go,
|
|
|
|
onSubmitted: (s) => submitAction(context),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: OutlineInputBorder(),
|
2020-05-07 07:52:40 +02:00
|
|
|
labelText: L10n.of(context).optionalGroupName,
|
2020-01-27 10:14:38 +01:00
|
|
|
prefixIcon: Icon(Icons.people),
|
2020-05-07 07:52:40 +02:00
|
|
|
hintText: L10n.of(context).enterAGroupName),
|
2020-01-27 10:14:38 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
SwitchListTile(
|
2020-05-07 07:52:40 +02:00
|
|
|
title: Text(L10n.of(context).groupIsPublic),
|
2020-01-27 10:14:38 +01:00
|
|
|
value: publicGroup,
|
|
|
|
onChanged: (bool b) => setState(() => publicGroup = b),
|
|
|
|
),
|
2020-02-09 17:19:07 +01:00
|
|
|
Expanded(
|
2020-05-13 15:58:59 +02:00
|
|
|
child: Image.asset('assets/new_group_wallpaper.png'),
|
2020-02-09 17:19:07 +01:00
|
|
|
),
|
2020-01-27 10:14:38 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton(
|
2020-02-16 20:13:55 +01:00
|
|
|
foregroundColor: Colors.white,
|
2020-01-27 10:14:38 +01:00
|
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
|
|
onPressed: () => submitAction(context),
|
|
|
|
child: Icon(Icons.arrow_forward),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|