feat(app): an open chat takes over the app bar instead of adding its own
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import '../../../core/api_gateway.dart';
|
import '../../../core/api_gateway.dart';
|
||||||
|
import '../../../shell/shell_bar.dart';
|
||||||
import '../data/chat_repository.dart';
|
import '../data/chat_repository.dart';
|
||||||
import '../domain/chat_activity_detail.dart';
|
import '../domain/chat_activity_detail.dart';
|
||||||
import '../domain/chat_notice.dart';
|
import '../domain/chat_notice.dart';
|
||||||
@@ -631,73 +632,77 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
|||||||
// Place the first loaded transcript and keep a following view at the end.
|
// Place the first loaded transcript and keep a following view at the end.
|
||||||
// Scheduling after the build means the new extent is already laid out.
|
// Scheduling after the build means the new extent is already laid out.
|
||||||
_scheduleFollow();
|
_scheduleFollow();
|
||||||
return Column(
|
// Under the app shell the conversation takes over the app's bar (title,
|
||||||
|
// Back, model, information) instead of drawing a second bar below it.
|
||||||
|
final inShellBar = ShellBar.available(context);
|
||||||
|
final column = Column(
|
||||||
children: [
|
children: [
|
||||||
// The conversation's own bar first, outside the transcript's scroller,
|
// The conversation's own bar first, outside the transcript's scroller,
|
||||||
// as on the web (chat-bar, then background tasks, then transcript).
|
// as on the web (chat-bar, then background tasks, then transcript).
|
||||||
Padding(
|
if (!inShellBar)
|
||||||
key: const Key('chat-thread-header'),
|
Padding(
|
||||||
padding: const EdgeInsetsDirectional.fromSTEB(4, 8, 4, 4),
|
key: const Key('chat-thread-header'),
|
||||||
child: LayoutBuilder(
|
padding: const EdgeInsetsDirectional.fromSTEB(4, 8, 4, 4),
|
||||||
builder: (context, constraints) {
|
child: LayoutBuilder(
|
||||||
final title = widget.title.trim();
|
builder: (context, constraints) {
|
||||||
final session = widget.session;
|
final title = widget.title.trim();
|
||||||
final hasModel =
|
final session = widget.session;
|
||||||
session != null &&
|
final hasModel =
|
||||||
supportsChatModels('${session['backend'] ?? ''}');
|
session != null &&
|
||||||
// One compact row, as on the web: back, the conversation's
|
supportsChatModels('${session['backend'] ?? ''}');
|
||||||
// name, its model and the information action. The title
|
// One compact row, as on the web: back, the conversation's
|
||||||
// takes the remaining width and ellipsises; the model keeps
|
// name, its model and the information action. The title
|
||||||
// a bounded share so neither control is pushed off a narrow
|
// takes the remaining width and ellipsises; the model keeps
|
||||||
// 2x phone and the header never wraps onto a second line.
|
// a bounded share so neither control is pushed off a narrow
|
||||||
return Row(
|
// 2x phone and the header never wraps onto a second line.
|
||||||
children: [
|
return Row(
|
||||||
_backButton(cupertino),
|
children: [
|
||||||
Expanded(
|
_backButton(cupertino),
|
||||||
child: Padding(
|
Expanded(
|
||||||
padding: const EdgeInsetsDirectional.only(start: 4),
|
child: Padding(
|
||||||
child: title.isEmpty
|
padding: const EdgeInsetsDirectional.only(start: 4),
|
||||||
? const SizedBox.shrink()
|
child: title.isEmpty
|
||||||
: Text(
|
? const SizedBox.shrink()
|
||||||
title,
|
: Text(
|
||||||
maxLines: 1,
|
title,
|
||||||
overflow: TextOverflow.ellipsis,
|
maxLines: 1,
|
||||||
style: cupertino
|
overflow: TextOverflow.ellipsis,
|
||||||
? CupertinoTheme.of(
|
style: cupertino
|
||||||
context,
|
? CupertinoTheme.of(
|
||||||
).textTheme.navTitleTextStyle
|
context,
|
||||||
: Theme.of(context).textTheme.titleLarge,
|
).textTheme.navTitleTextStyle
|
||||||
),
|
: Theme.of(context).textTheme.titleLarge,
|
||||||
),
|
),
|
||||||
),
|
|
||||||
if (hasModel)
|
|
||||||
ConstrainedBox(
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxWidth: constraints.maxWidth * 0.4,
|
|
||||||
),
|
),
|
||||||
child: ChatModelControl(
|
),
|
||||||
key: ValueKey<String>(
|
if (hasModel)
|
||||||
'chat-model-${widget.sessionId}',
|
ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
maxWidth: constraints.maxWidth * 0.4,
|
||||||
|
),
|
||||||
|
child: ChatModelControl(
|
||||||
|
key: ValueKey<String>(
|
||||||
|
'chat-model-${widget.sessionId}',
|
||||||
|
),
|
||||||
|
gateway: widget.gateway,
|
||||||
|
sessionId: widget.sessionId,
|
||||||
|
session: session,
|
||||||
|
onChanged: widget.onModelChanged,
|
||||||
|
answeredBy: latestReplyModel(_controller.messages),
|
||||||
),
|
),
|
||||||
gateway: widget.gateway,
|
|
||||||
sessionId: widget.sessionId,
|
|
||||||
session: session,
|
|
||||||
onChanged: widget.onModelChanged,
|
|
||||||
answeredBy: latestReplyModel(_controller.messages),
|
|
||||||
),
|
),
|
||||||
|
ChatBarAction(
|
||||||
|
key: const Key('chat-info'),
|
||||||
|
label: 'Chat information',
|
||||||
|
onPressed: _openInfo,
|
||||||
|
materialIcon: Icons.info_outline,
|
||||||
|
cupertinoIcon: CupertinoIcons.info,
|
||||||
),
|
),
|
||||||
ChatBarAction(
|
],
|
||||||
key: const Key('chat-info'),
|
);
|
||||||
label: 'Chat information',
|
},
|
||||||
onPressed: _openInfo,
|
),
|
||||||
materialIcon: Icons.info_outline,
|
|
||||||
cupertinoIcon: CupertinoIcons.info,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
|
||||||
// The session's still-running background tasks, above the transcript
|
// The session's still-running background tasks, above the transcript
|
||||||
// and outside its scroller (web C11). It removes itself when the last
|
// and outside its scroller (web C11). It removes itself when the last
|
||||||
// task exits and never draws a finished task.
|
// task exits and never draws a finished task.
|
||||||
@@ -829,6 +834,37 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
if (!inShellBar) return column;
|
||||||
|
final session = widget.session;
|
||||||
|
final hasModel =
|
||||||
|
session != null && supportsChatModels('${session['backend'] ?? ''}');
|
||||||
|
final title = widget.title.trim();
|
||||||
|
return ShellBar(
|
||||||
|
title: title.isEmpty ? null : title,
|
||||||
|
onBack: widget.onBack,
|
||||||
|
actions: [
|
||||||
|
if (hasModel)
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 180),
|
||||||
|
child: ChatModelControl(
|
||||||
|
key: ValueKey<String>('chat-model-${widget.sessionId}'),
|
||||||
|
gateway: widget.gateway,
|
||||||
|
sessionId: widget.sessionId,
|
||||||
|
session: session,
|
||||||
|
onChanged: widget.onModelChanged,
|
||||||
|
answeredBy: latestReplyModel(_controller.messages),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ChatBarAction(
|
||||||
|
key: const Key('chat-info'),
|
||||||
|
label: 'Chat information',
|
||||||
|
onPressed: _openInfo,
|
||||||
|
materialIcon: Icons.info_outline,
|
||||||
|
cupertinoIcon: CupertinoIcons.info,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
child: column,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -231,9 +231,12 @@ void main() {
|
|||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(find.text('A live line arrived.'), findsOneWidget);
|
expect(find.text('A live line arrived.'), findsOneWidget);
|
||||||
|
|
||||||
// One compact icon-only Back control in the thread header; its
|
// The open chat takes over the app bar: one Back there, and no
|
||||||
// accessible name is the destination, and both hosts share the key.
|
// second header row under it.
|
||||||
await tester.tap(find.byKey(const Key('chat-back')));
|
expect(find.byKey(const Key('chat-thread-header')), findsNothing);
|
||||||
|
await tester.tap(find.byKey(const ValueKey('shell.back')));
|
||||||
|
await tester.pump();
|
||||||
|
// The bar hands back to the list on the next frame.
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
expect(provider.value.uri.path, '/chat');
|
expect(provider.value.uri.path, '/chat');
|
||||||
expect(find.byType(ChatThreadView), findsNothing);
|
expect(find.byType(ChatThreadView), findsNothing);
|
||||||
|
|||||||
Reference in New Issue
Block a user