ae208699d8
Keep the Material-only session UI and narrow its tests to the supported host. Preserve public Cupertino parameters for callers while removing unreachable Cupertino widgets and variants.
118 lines
3.4 KiB
Dart
118 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../core/api_gateway.dart';
|
|
import '../../domain/chat_sessions.dart';
|
|
|
|
/// Renames one session through the shared server field. Save is disabled while
|
|
/// the trimmed name is blank, matching the web dialog. A refusal keeps the
|
|
/// dialog open with the server's own words.
|
|
Future<String?> showRenameChatDialog(
|
|
BuildContext context,
|
|
JsonMap session, {
|
|
required Future<void> Function(String title) onSubmit,
|
|
}) {
|
|
final dialog = _RenameChatDialog(
|
|
initialTitle: chatSessionTitle(session),
|
|
onSubmit: onSubmit,
|
|
);
|
|
return showDialog<String>(context: context, builder: (_) => dialog);
|
|
}
|
|
|
|
class _RenameChatDialog extends StatefulWidget {
|
|
const _RenameChatDialog({required this.initialTitle, required this.onSubmit});
|
|
|
|
final String initialTitle;
|
|
final Future<void> Function(String title) onSubmit;
|
|
|
|
@override
|
|
State<_RenameChatDialog> createState() => _RenameChatDialogState();
|
|
}
|
|
|
|
class _RenameChatDialogState extends State<_RenameChatDialog> {
|
|
late final TextEditingController _title =
|
|
TextEditingController(text: widget.initialTitle)
|
|
..selection = TextSelection(
|
|
baseOffset: 0,
|
|
extentOffset: widget.initialTitle.length,
|
|
);
|
|
String? _error;
|
|
bool _saving = false;
|
|
|
|
@override
|
|
void dispose() {
|
|
_title.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> _save() async {
|
|
if (_saving) return;
|
|
final title = _title.text.trim();
|
|
if (title.isEmpty) return;
|
|
setState(() {
|
|
_saving = true;
|
|
_error = null;
|
|
});
|
|
try {
|
|
await widget.onSubmit(title);
|
|
if (!mounted) return;
|
|
Navigator.pop(context, title);
|
|
} catch (error) {
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_saving = false;
|
|
_error = '$error';
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ValueListenableBuilder<TextEditingValue>(
|
|
valueListenable: _title,
|
|
builder: (context, value, _) {
|
|
final canSave = !_saving && value.text.trim().isNotEmpty;
|
|
final error = _error;
|
|
return AlertDialog(
|
|
// A long server refusal plus a 2x helper text can exceed the dialog
|
|
// height at 320px; scroll the content instead of clipping it.
|
|
scrollable: true,
|
|
title: const Text('Rename chat'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
TextField(
|
|
key: const Key('chat-rename-field'),
|
|
controller: _title,
|
|
autofocus: true,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Name',
|
|
helperText: 'This name is shared with every device.',
|
|
helperMaxLines: 2,
|
|
),
|
|
),
|
|
if (error != null) ...[
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
error,
|
|
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: _saving ? null : () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: canSave ? _save : null,
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|