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
186 lines
5.0 KiB
Dart
186 lines
5.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'chat_adaptive.dart';
|
|
|
|
/// The create dialog's server catalog area: loading, error with retry, the
|
|
/// empty-catalog message, or the two server-backed selectors.
|
|
class ChatCatalogFields extends StatelessWidget {
|
|
const ChatCatalogFields({
|
|
super.key,
|
|
required this.loading,
|
|
required this.error,
|
|
required this.directories,
|
|
required this.backends,
|
|
required this.directory,
|
|
required this.backend,
|
|
required this.onDirectory,
|
|
required this.onBackend,
|
|
required this.onRetry,
|
|
});
|
|
|
|
final bool loading;
|
|
final String? error;
|
|
final List<String> directories;
|
|
final List<String> backends;
|
|
final String? directory;
|
|
final String? backend;
|
|
final ValueChanged<String> onDirectory;
|
|
final ValueChanged<String> onBackend;
|
|
final VoidCallback onRetry;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
if (loading) return const Text('Loading directories…');
|
|
if (error != null) {
|
|
return _message(cupertino, 'Unable to load chat options: $error');
|
|
}
|
|
if (directories.isEmpty || backends.isEmpty) {
|
|
return _message(
|
|
cupertino,
|
|
'The server has no chat directories or backends available.',
|
|
);
|
|
}
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
if (cupertino)
|
|
CupertinoPickerField(
|
|
label: 'Server directory',
|
|
value: directory,
|
|
values: directories,
|
|
onSelected: onDirectory,
|
|
)
|
|
else
|
|
MaterialPickerField(
|
|
label: 'Server directory',
|
|
value: directory,
|
|
values: directories,
|
|
onSelected: onDirectory,
|
|
),
|
|
if (cupertino)
|
|
CupertinoPickerField(
|
|
label: 'Backend',
|
|
value: backend,
|
|
values: backends,
|
|
onSelected: onBackend,
|
|
)
|
|
else
|
|
MaterialPickerField(
|
|
label: 'Backend',
|
|
value: backend,
|
|
values: backends,
|
|
onSelected: onBackend,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _message(bool cupertino, String text) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(text),
|
|
Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: cupertino
|
|
? CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: onRetry,
|
|
child: const Text('Retry'),
|
|
)
|
|
: TextButton(onPressed: onRetry, child: const Text('Retry')),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class MaterialPickerField extends StatelessWidget {
|
|
const MaterialPickerField({
|
|
super.key,
|
|
required this.label,
|
|
required this.value,
|
|
required this.values,
|
|
required this.onSelected,
|
|
});
|
|
|
|
final String label;
|
|
final String? value;
|
|
final List<String> values;
|
|
final ValueChanged<String> onSelected;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownButtonFormField<String>(
|
|
key: Key('chat-create-${label.toLowerCase().replaceAll(' ', '-')}'),
|
|
initialValue: value,
|
|
decoration: InputDecoration(labelText: label),
|
|
items: [
|
|
for (final item in values)
|
|
DropdownMenuItem(value: item, child: Text(item)),
|
|
],
|
|
onChanged: (item) {
|
|
if (item != null) onSelected(item);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class CupertinoPickerField extends StatelessWidget {
|
|
const CupertinoPickerField({
|
|
super.key,
|
|
required this.label,
|
|
required this.value,
|
|
required this.values,
|
|
required this.onSelected,
|
|
});
|
|
|
|
final String label;
|
|
final String? value;
|
|
final List<String> values;
|
|
final ValueChanged<String> onSelected;
|
|
|
|
Future<void> _choose(BuildContext context) async {
|
|
final choice = await showCupertinoModalPopup<String>(
|
|
context: context,
|
|
builder: (sheetContext) => CupertinoActionSheet(
|
|
title: Text(label),
|
|
actions: [
|
|
for (final item in values)
|
|
CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.pop(sheetContext, item),
|
|
child: Text(item),
|
|
),
|
|
],
|
|
cancelButton: CupertinoActionSheetAction(
|
|
onPressed: () => Navigator.pop(sheetContext),
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
);
|
|
if (choice != null) onSelected(choice);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Semantics(
|
|
label: '$label: ${value ?? ''}',
|
|
button: true,
|
|
child: CupertinoButton(
|
|
key: Key('chat-create-${label.toLowerCase().replaceAll(' ', '-')}'),
|
|
padding: const EdgeInsets.symmetric(vertical: 4),
|
|
onPressed: () => _choose(context),
|
|
child: Row(
|
|
children: [
|
|
Expanded(child: Text('$label: ${value ?? ''}')),
|
|
const Icon(CupertinoIcons.chevron_down),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|