fluffychat/lib/views/new_group.dart

81 lines
2.7 KiB
Dart
Raw Normal View History

2021-01-16 12:46:38 +01:00
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
import 'package:famedlysdk/famedlysdk.dart' as sdk;
2020-12-25 09:58:34 +01:00
import 'package:future_loading_dialog/future_loading_dialog.dart';
2021-04-09 16:15:03 +02:00
import 'package:fluffychat/views/widgets/matrix.dart';
2020-01-27 10:14:38 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
2020-01-27 10:14:38 +01:00
2021-01-16 12:46:38 +01:00
class NewGroup extends StatefulWidget {
2020-01-27 10:14:38 +01:00
@override
_NewGroupState createState() => _NewGroupState();
}
2021-01-16 12:46:38 +01:00
class _NewGroupState extends State<NewGroup> {
2020-01-27 10:14:38 +01:00
TextEditingController controller = TextEditingController();
bool publicGroup = false;
void submitAction(BuildContext context) async {
2020-05-13 15:58:59 +02:00
final matrix = Matrix.of(context);
2020-12-25 09:58:34 +01:00
final roomID = await showFutureLoadingDialog(
context: context,
future: () => matrix.client.createRoom(
2020-06-10 10:07:01 +02:00
preset: publicGroup
? sdk.CreateRoomPreset.public_chat
: sdk.CreateRoomPreset.private_chat,
visibility: publicGroup ? sdk.Visibility.public : null,
2020-06-10 10:07:01 +02:00
roomAliasName:
publicGroup && controller.text.isNotEmpty ? controller.text : null,
name: controller.text.isNotEmpty ? controller.text : null,
),
2020-01-27 10:14:38 +01:00
);
2021-01-16 12:46:38 +01:00
AdaptivePageLayout.of(context).popUntilIsFirst();
2020-01-27 10:14:38 +01:00
if (roomID != null) {
2021-01-16 12:46:38 +01:00
await AdaptivePageLayout.of(context).pushNamed('/rooms/${roomID.result}');
await AdaptivePageLayout.of(context)
.pushNamed('/rooms/${roomID.result}/invite');
2020-01-27 10:14:38 +01:00
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
2021-01-16 14:24:52 +01:00
leading: BackButton(),
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(
2021-01-24 17:26:59 +01:00
padding: const EdgeInsets.all(12.0),
2020-01-27 10:14:38 +01:00
child: TextField(
controller: controller,
autofocus: true,
autocorrect: false,
textInputAction: TextInputAction.go,
onSubmitted: (s) => submitAction(context),
decoration: InputDecoration(
2020-05-07 07:52:40 +02:00
labelText: L10n.of(context).optionalGroupName,
2020-12-06 10:31:35 +01:00
prefixIcon: Icon(Icons.people_outlined),
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(
onPressed: () => submitAction(context),
2020-12-06 10:31:35 +01:00
child: Icon(Icons.arrow_forward_outlined),
2020-01-27 10:14:38 +01:00
),
);
}
}