feat(app): on a phone an open pipeline, run or chat is its own page over the tabs
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import '../../shell/destination.dart';
|
||||
import '../../shell/detail_page.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -163,49 +165,67 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The open chat is its own page over the tabs on a phone.
|
||||
final DetailPageHost _page = DetailPageHost();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_page.dispose();
|
||||
_sessions.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _thread(String selected, VoidCallback onBack) {
|
||||
final row = _rowFor(selected);
|
||||
final start = _startNotice;
|
||||
return ChatThreadView(
|
||||
key: ValueKey<String>('chat-session-$selected'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: selected,
|
||||
title: '${row?['title'] ?? ''}'.trim(),
|
||||
session: row,
|
||||
syncToken: widget.syncToken,
|
||||
scrollPositions: _scrollPositions,
|
||||
initialNotice: start != null && start.id == selected
|
||||
? start.notice
|
||||
: null,
|
||||
onBack: onBack,
|
||||
onModelChanged: (applied) => _modelChanged(selected, applied),
|
||||
onCreatedSession: _openCreated,
|
||||
onSessionRenamed: (title) => _renamed(selected, title),
|
||||
onSessionClosed: _closed,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selected = _selected;
|
||||
final row = selected == null ? null : _rowFor(selected);
|
||||
final start = _startNotice;
|
||||
// On a phone an open chat is its own page over the tabs; a wide window
|
||||
// keeps it in the tab, beside the destination rail.
|
||||
final narrow = MediaQuery.sizeOf(context).width < kDetailPageMaxWidth;
|
||||
_page.sync(
|
||||
context,
|
||||
selected: selected != null && narrow,
|
||||
destination: AppDestination.chat,
|
||||
onClosed: _back,
|
||||
builder: (context) => selected == null
|
||||
? const SizedBox.shrink()
|
||||
: _thread(selected, () => Navigator.of(context).maybePop()),
|
||||
);
|
||||
final list = ChatSessionsScreen(
|
||||
gateway: widget.gateway,
|
||||
embedded: true,
|
||||
syncToken: widget.syncToken,
|
||||
controller: _sessions,
|
||||
onOpen: _open,
|
||||
onSessions: _adoptRows,
|
||||
activeSessionId: narrow ? null : selected,
|
||||
);
|
||||
if (narrow) return list;
|
||||
return Stack(
|
||||
children: [
|
||||
Offstage(
|
||||
offstage: selected != null,
|
||||
child: ChatSessionsScreen(
|
||||
gateway: widget.gateway,
|
||||
embedded: true,
|
||||
syncToken: widget.syncToken,
|
||||
controller: _sessions,
|
||||
onOpen: _open,
|
||||
onSessions: _adoptRows,
|
||||
activeSessionId: selected,
|
||||
),
|
||||
),
|
||||
if (selected != null)
|
||||
ChatThreadView(
|
||||
key: ValueKey<String>('chat-session-$selected'),
|
||||
gateway: widget.gateway,
|
||||
sessionId: selected,
|
||||
title: '${row?['title'] ?? ''}'.trim(),
|
||||
session: row,
|
||||
syncToken: widget.syncToken,
|
||||
scrollPositions: _scrollPositions,
|
||||
initialNotice: start != null && start.id == selected
|
||||
? start.notice
|
||||
: null,
|
||||
onBack: _back,
|
||||
onModelChanged: (applied) => _modelChanged(selected, applied),
|
||||
onCreatedSession: _openCreated,
|
||||
onSessionRenamed: (title) => _renamed(selected, title),
|
||||
onSessionClosed: _closed,
|
||||
),
|
||||
Offstage(offstage: selected != null, child: list),
|
||||
if (selected != null) _thread(selected, _back),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user