part of '../neon_spreed.dart'; class SpreedCreateRoomDialog extends StatefulWidget { const SpreedCreateRoomDialog({ super.key, }); @override State createState() => _SpreedCreateRoomDialogState(); } class _SpreedCreateRoomDialogState extends State { 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(); 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(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; }