41d30a4280
Split the 406-line chat session browser into a controller, body, shared adaptive primitives and separate standard Material and Cupertino lists and dialogs. Preserve the existing server directory/backend catalogs, instructions field, closed/starred grouping, directory headings and empty/no-match states. - keep refresh generations so stale replies are discarded - open a created chat immediately and refresh the list in the background - disable rename Save while the trimmed name is blank - label row actions per session, with the id on duplicate titles - wrap Cupertino empty/no-match/error messages instead of clipping, and give them a Cupertino text style under a bare MaterialApp - allow the Material rename helper to wrap at large text scales - cover both native branches, lifecycle ordering, create/rename/close/star and the Cupertino theme path with widget tests
108 lines
3.3 KiB
Dart
108 lines
3.3 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../core/api_gateway.dart';
|
|
import '../../domain/chat_sessions.dart';
|
|
import 'chat_adaptive.dart';
|
|
|
|
/// Renames one session. Save is disabled while the trimmed name is blank,
|
|
/// matching the web dialog.
|
|
Future<String?> showRenameChatDialog(BuildContext context, JsonMap session) {
|
|
final dialog = _RenameChatDialog(initialTitle: chatSessionTitle(session));
|
|
return chatControlsStyleOf(context) == ChatControlsStyle.cupertino
|
|
? showCupertinoDialog<String>(context: context, builder: (_) => dialog)
|
|
: showDialog<String>(context: context, builder: (_) => dialog);
|
|
}
|
|
|
|
class _RenameChatDialog extends StatefulWidget {
|
|
const _RenameChatDialog({required this.initialTitle});
|
|
|
|
final String initialTitle;
|
|
|
|
@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,
|
|
);
|
|
|
|
@override
|
|
void dispose() {
|
|
_title.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _save() {
|
|
final title = _title.text.trim();
|
|
if (title.isEmpty) return;
|
|
Navigator.pop(context, title);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ValueListenableBuilder<TextEditingValue>(
|
|
valueListenable: _title,
|
|
builder: (context, value, _) {
|
|
final canSave = value.text.trim().isNotEmpty;
|
|
if (chatControlsStyleOf(context) == ChatControlsStyle.cupertino) {
|
|
return CupertinoAlertDialog(
|
|
title: const Text('Rename chat'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
CupertinoTextField(
|
|
key: const Key('chat-rename-field'),
|
|
controller: _title,
|
|
autofocus: true,
|
|
placeholder: 'Name',
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text('This name is shared with every device.'),
|
|
],
|
|
),
|
|
actions: [
|
|
CupertinoDialogAction(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
CupertinoDialogAction(
|
|
isDefaultAction: true,
|
|
onPressed: canSave ? _save : null,
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
return AlertDialog(
|
|
title: const Text('Rename chat'),
|
|
content: 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,
|
|
),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: canSave ? _save : null,
|
|
child: const Text('Save'),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|