A framework for building convergent cross-platform Nextcloud clients using Flutter.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

142 lines
4.8 KiB

part of '../neon_spreed.dart';
class SpreedCreateRoomDialog extends StatefulWidget {
const SpreedCreateRoomDialog({
super.key,
});
@override
State<SpreedCreateRoomDialog> createState() => _SpreedCreateRoomDialogState();
}
class _SpreedCreateRoomDialogState extends State<SpreedCreateRoomDialog> {
late final values = {
spreed.RoomType.oneToOne: SpreedLocalizations.of(context).roomTypeOneToOne,
spreed.RoomType.group: SpreedLocalizations.of(context).roomTypeGroup,
spreed.RoomType.public: SpreedLocalizations.of(context).roomTypePublic,
};
final formKey = GlobalKey<FormState>();
final controller = TextEditingController();
final focusNode = FocusNode();
spreed.RoomType? selectedType;
core.AutocompleteResult? selectedAutocompleteEntry;
void changeType(final spreed.RoomType? type) {
controller.clear();
setState(() {
selectedType = type;
});
}
void submit() {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop(
SpreedCreateRoomDetails(
selectedType!,
selectedType! == spreed.RoomType.public ? controller.text : null,
selectedType! != spreed.RoomType.public ? selectedAutocompleteEntry : null,
),
);
}
}
@override
Widget build(final BuildContext context) => NeonDialog(
title: Text(SpreedLocalizations.of(context).roomCreate),
children: [
Form(
key: formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
for (final type in values.keys) ...[
ListTile(
title: Text(values[type]!),
leading: Icon(
type == spreed.RoomType.oneToOne
? Icons.person
: type == spreed.RoomType.group
? Icons.group
: Icons.public,
),
trailing: Radio(
value: type,
groupValue: selectedType,
onChanged: changeType,
),
onTap: () {
changeType(type);
},
),
],
if (selectedType == spreed.RoomType.oneToOne || selectedType == spreed.RoomType.group) ...[
NeonAutocomplete(
key: Key(selectedType!.index.toString()),
account: NeonProvider.of<AccountsBloc>(context).activeAccount.value!,
itemType: 'call',
itemId: 'new',
shareTypes: [
if (selectedType == spreed.RoomType.oneToOne) ...[
core.ShareType.user.index,
] else if (selectedType == spreed.RoomType.group) ...[
core.ShareType.group.index,
],
],
validator: (final input) => validateNotEmpty(context, input),
decoration: InputDecoration(
hintText: selectedType == spreed.RoomType.oneToOne
? SpreedLocalizations.of(context).roomCreateUserName
: SpreedLocalizations.of(context).roomCreateGroupName,
),
onSelected: (final entry) {
setState(() {
selectedAutocompleteEntry = entry;
});
},
onFieldSubmitted: (final _) {
submit();
},
),
],
if (selectedType == spreed.RoomType.public) ...[
TextFormField(
controller: controller,
focusNode: focusNode,
validator: (final input) => validateNotEmpty(context, input),
decoration: InputDecoration(
hintText: SpreedLocalizations.of(context).roomCreateRoomName,
),
onFieldSubmitted: (final _) {
submit();
},
),
],
const SizedBox(
height: 10,
),
ElevatedButton(
onPressed: selectedType == null ? null : submit,
child: Text(SpreedLocalizations.of(context).roomCreate),
),
],
),
),
],
);
}
class SpreedCreateRoomDetails {
SpreedCreateRoomDetails(
this.type,
this.roomName,
this.invite,
);
final spreed.RoomType type;
final String? roomName;
final core.AutocompleteResult? invite;
}