Grow the tapped chat row into the chat page on phones

Replace the identity-avatar Hero with a container transform: the row's
surface, tint and edge marker morph into the full page while the content
cross-fades, and Back, the Cupertino edge swipe or Android predictive back
shrink the page into the open chat's row. Reduced motion or a row off
screen fades instead; wide layouts are unchanged.
This commit is contained in:
2026-11-10 03:11:05 +00:00
parent 60b4c495f1
commit eea1361980
16 changed files with 1392 additions and 124 deletions
@@ -1,106 +1,192 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/chat/screen.dart';
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
import 'package:pipelines_app/shell/adaptive_shell.dart';
import 'package:pipelines_app/shell/destination.dart';
import 'package:pipelines_app/ui/motion/container_transform_flight.dart';
import 'package:pipelines_app/ui/motion/container_transform_route.dart';
import 'package:pipelines_app/ui/motion/container_transform_source.dart';
import 'package:pipelines_app/ui/motion/motion.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
const _session = <String, dynamic>{
'id': 'fake-chat',
'title': 'Fake chat',
'directory': '/tmp/fake-chat',
'color': 'blue',
};
import '../../native_back.dart';
import 'conversation/chat_thread_fixtures.dart';
class _Gateway extends FakeChatGateway {
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
if (type == 'chat_sessions') {
return Future.value({
'chat_sessions': [
{'id': 'a', 'title': 'First chat', 'color': 'blue'},
{'id': 'b', 'title': 'Second chat'},
],
});
}
if (type == 'chat_shells') return Future.value({'chat_shells': []});
return super.call(type, fields);
}
}
Future<void> _pumpShell(WidgetTester tester, Size size) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final gateway = _Gateway()..history = (_) async => chatPage(const []);
addTearDown(gateway.close);
await tester.pumpWidget(
MaterialApp(
theme: appLightTheme(),
home: AdaptiveShell(
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
},
),
),
);
await tester.pumpAndSettle();
}
Finder get _surface => find.byKey(containerTransformSurfaceKey);
void main() {
testWidgets('mobile identity flies into the header and returns to the row', (
testWidgets('a phone grows the tapped row into the chat and back', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
// Chat tests run with reduced motion (flutter_test_config); this one
// covers the motion itself.
final reduced = tester.platformDispatcher.accessibilityFeatures;
tester.platformDispatcher.accessibilityFeaturesTestValue =
const FakeAccessibilityFeatures();
addTearDown(
() => tester.platformDispatcher.accessibilityFeaturesTestValue = reduced,
);
await _pumpShell(tester, const Size(390, 844));
final row = tester.getRect(find.byKey(const Key('chat-row-a')));
expect(
find.byType(Hero),
findsNothing,
reason: 'the row is the shared element',
);
await tester.tap(find.text('First chat'));
await tester.pump();
await tester.pump();
await tester.pump(const Duration(milliseconds: 120));
final navigator = tester.state<NavigatorState>(
find.byType(Navigator).first,
);
expect(navigator.canPop(), isTrue);
final mid = tester.getRect(_surface);
expect(mid.top, lessThan(row.top));
expect(mid.height, greaterThan(row.height));
expect(mid.height, lessThan(844));
await tester.pumpAndSettle();
expect(tester.getRect(_surface), const Rect.fromLTWH(0, 0, 390, 844));
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
expect(find.byType(Hero), findsNothing);
await tester.tap(findNativeBack());
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final closing = tester.getRect(_surface);
expect(closing.height, lessThan(844));
expect(closing.height, greaterThan(row.height));
await tester.pumpAndSettle();
expect(navigator.canPop(), isFalse);
expect(_surface, findsNothing);
expect(tester.getRect(find.byKey(const Key('chat-row-a'))), row);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a phone under reduced motion fades the chat in place', (
tester,
) async {
await _pumpShell(tester, const Size(390, 844));
await tester.tap(find.text('First chat'));
await tester.pump();
await tester.pump();
await tester.pump(const Duration(milliseconds: 1));
expect(tester.getRect(_surface), const Rect.fromLTWH(0, 0, 390, 844));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
await tester.tap(findNativeBack());
await tester.pump();
await tester.pump(const Duration(milliseconds: 1));
expect(tester.getRect(_surface), const Rect.fromLTWH(0, 0, 390, 844));
await tester.pumpAndSettle();
expect(_surface, findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a wide window opens the chat beside the list, untransformed', (
tester,
) async {
await _pumpShell(tester, const Size(1280, 800));
await tester.tap(find.text('First chat'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 120));
expect(_surface, findsNothing);
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
expect(_surface, findsNothing);
final navigator = tester.state<NavigatorState>(
find.byType(Navigator).first,
);
expect(navigator.canPop(), isFalse);
expect(
find.byWidgetPredicate((w) => w is ContainerTransformSource),
findsWidgets,
reason: 'rows still register, but nothing grows from them',
);
await tester.pumpWidget(const SizedBox.shrink());
});
testWidgets('a row offers its tinted surface and edge marker', (
tester,
) async {
final sources = ContainerTransformSources();
await tester.pumpWidget(
MaterialApp(
theme: appLightTheme(),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(
context,
).copyWith(size: const Size(390, 844), disableAnimations: false),
child: child!,
),
home: Scaffold(
body: ChatSessionRow(
session: _session,
onOpen: (session) =>
Navigator.of(
tester.element(find.byType(ChatSessionRow)),
).push<void>(
MaterialPageRoute(
builder: (_) => Scaffold(
body: ChatThreadHeader(
title: 'Fake chat',
folder: 'fake-chat',
onInfo: () {},
showBack: true,
identity: ChatSessionAvatar(
session: session,
selected: true,
),
identityHeroTag: 'chat-identity-fake-chat',
),
),
),
),
onAction: (_) {},
),
),
),
);
await tester.pump();
expect(find.byType(Hero), findsOneWidget);
final rowAvatar = find.byType(ChatSessionAvatar);
final rowRect = tester.getRect(rowAvatar);
await tester.tap(find.byKey(const Key('chat-row-fake-chat')));
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('Fake chat'), findsOneWidget);
final heroFinder = find.byType(Hero, skipOffstage: false);
final heroRects = [
for (var index = 0; index < tester.widgetList(heroFinder).length; index++)
tester.getRect(heroFinder.at(index)),
];
expect(heroRects, hasLength(2));
expect(
heroRects.any((rect) => rect.size != rowRect.size && rect != rowRect),
isTrue,
);
await tester.pumpAndSettle();
final headerAvatar = tester.getRect(find.byType(ChatSessionAvatar));
expect(headerAvatar.top, isNot(rowRect.top));
await tester.pageBack();
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-row-fake-chat')), findsOneWidget);
});
testWidgets('reduced motion keeps the identity in place without a Hero', (
tester,
) async {
await tester.pumpWidget(
MediaQuery(
data: const MediaQueryData(disableAnimations: true),
child: MaterialApp(
theme: appLightTheme(),
home: Scaffold(
body: ChatThreadHeader(
title: 'Fake chat',
folder: 'fake-chat',
onInfo: () {},
identity: ChatSessionAvatar(session: _session, selected: true),
identityHeroTag: 'chat-identity-fake-chat',
body: ContainerTransformScope(
sources: sources,
child: ChatSessionRow(
session: const {'id': 'x', 'title': 'Tinted', 'color': 'blue'},
visible: true,
selected: true,
onOpen: (_) {},
onAction: (_) {},
),
),
),
),
);
await tester.pump();
expect(find.byType(Hero), findsNothing);
final origin = sources.originOf('x')!;
expect(origin.rect, tester.getRect(find.byKey(const Key('chat-row-x'))));
final background = appLightTheme().scaffoldBackgroundColor;
expect(origin.color, isNot(background), reason: 'the chat colour tints it');
expect(origin.color.a, 1);
expect(origin.markerWidth, 10);
expect(origin.marker, isNotNull);
});
test('the route reads its timing from Motion', () {
final route = ContainerTransformPageRoute<void>(
link: ContainerTransformLink(() => null),
cupertino: false,
builder: (_) => const SizedBox(),
);
expect(route.transitionDuration, Motion.containerTransform);
expect(route.reverseTransitionDuration, Motion.containerTransformReverse);
expect(route.opaque, isTrue);
});
}
@@ -0,0 +1,293 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/motion/container_transform_flight.dart';
import 'package:pipelines_app/ui/motion/container_transform_route.dart';
import 'package:pipelines_app/ui/motion/container_transform_source.dart';
const _screen = Size(390, 844);
const _rowColor = Color(0xFFE3F2FD);
/// A list of three rows; tapping one pushes its page, grown from that row.
class _List extends StatelessWidget {
const _List({required this.sources, required this.cupertino});
final ContainerTransformSources sources;
final bool cupertino;
@override
Widget build(BuildContext context) => ContainerTransformScope(
sources: sources,
child: ListView(
padding: const EdgeInsets.only(top: 200),
children: [
for (final id in ['a', 'b', 'c'])
ContainerTransformSource(
id: id,
color: _rowColor,
marker: const Color(0xFF1565C0),
markerWidth: 3,
child: GestureDetector(
key: Key('row-$id'),
onTap: () => Navigator.of(context).push(
ContainerTransformPageRoute<void>(
link: sources.link(() => id),
cupertino: cupertino,
builder: (_) => _Page(id: id, cupertino: cupertino),
),
),
child: SizedBox(height: 72, child: Text('row $id')),
),
),
],
),
);
}
class _Page extends StatelessWidget {
const _Page({required this.id, required this.cupertino});
final String id;
final bool cupertino;
@override
Widget build(BuildContext context) => cupertino
? CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(),
child: Center(child: Text('page $id')),
)
: Scaffold(
appBar: AppBar(),
body: Center(child: Text('page $id')),
);
}
Future<ContainerTransformSources> _pump(
WidgetTester tester, {
bool cupertino = false,
bool reduced = false,
}) async {
tester.view.physicalSize = _screen;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final sources = ContainerTransformSources();
final home = _List(sources: sources, cupertino: cupertino);
Widget media(BuildContext context, Widget? child) => MediaQuery(
data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
child: child!,
);
await tester.pumpWidget(
cupertino
? CupertinoApp(builder: media, home: home)
: MaterialApp(builder: media, home: home),
);
return sources;
}
Rect _surface(WidgetTester tester) =>
tester.getRect(find.byKey(containerTransformSurfaceKey));
double _opacityAbove(WidgetTester tester, Finder finder) => tester
.widget<Opacity>(
find.ancestor(of: finder, matching: find.byType(Opacity)).first,
)
.opacity;
/// Strictly between the row and the full screen on every edge it moves.
void _expectBetween(Rect rect, Rect row) {
expect(rect.top, lessThan(row.top));
expect(rect.top, greaterThan(0));
expect(rect.height, greaterThan(row.height));
expect(rect.height, lessThan(_screen.height));
}
Future<void> _backGesture(String method, [Map<String, Object?>? args]) =>
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.handlePlatformMessage(
'flutter/backgesture',
const StandardMethodCodec().encodeMethodCall(
MethodCall(method, args),
),
(_) {},
);
void main() {
testWidgets('the row grows into the page and Back shrinks it back', (
tester,
) async {
final sources = await _pump(tester);
final row = tester.getRect(find.byKey(const Key('row-b')));
expect(sources.originOf('b')!.rect, row);
await tester.tap(find.byKey(const Key('row-b')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 16));
// The first frame starts on the row, in the row's colour, with the page
// content still hidden.
expect(_surface(tester).top, closeTo(row.top, 16));
expect(_opacityAbove(tester, find.text('page b')), 0);
await tester.pump(const Duration(milliseconds: 120));
_expectBetween(_surface(tester), row);
// The list behind stays where it was.
expect(tester.getRect(find.byKey(const Key('row-b'))), row);
await tester.pumpAndSettle();
expect(_surface(tester), Offset.zero & _screen);
expect(_opacityAbove(tester, find.text('page b')), 1);
await tester.pageBack();
await tester.pump();
await tester.pump(const Duration(milliseconds: 110));
_expectBetween(_surface(tester), row);
// The page content goes early in the close.
expect(_opacityAbove(tester, find.text('page b')), lessThan(1));
await tester.pumpAndSettle();
expect(find.text('page b'), findsNothing);
expect(find.byKey(containerTransformSurfaceKey), findsNothing);
expect(tester.getRect(find.byKey(const Key('row-b'))), row);
});
testWidgets('reduced motion fades the page in place', (tester) async {
await _pump(tester, reduced: true);
await tester.tap(find.byKey(const Key('row-b')));
await tester.pump();
await tester.pump(const Duration(milliseconds: 60));
expect(_surface(tester), Offset.zero & _screen);
final fading = tester
.widget<Opacity>(
find
.ancestor(
of: find.byKey(containerTransformSurfaceKey),
matching: find.byType(Opacity),
)
.first,
)
.opacity;
expect(fading, inExclusiveRange(0, 1));
await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget);
await tester.pageBack();
await tester.pump();
await tester.pump(const Duration(milliseconds: 60));
expect(_surface(tester), Offset.zero & _screen);
await tester.pumpAndSettle();
expect(find.text('page b'), findsNothing);
});
testWidgets('a row that is gone fades the page instead', (tester) async {
final sources = await _pump(tester);
expect(sources.originOf('missing'), isNull);
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
navigator.push(
ContainerTransformPageRoute<void>(
link: sources.link(() => 'missing'),
cupertino: false,
builder: (_) => const _Page(id: 'x', cupertino: false),
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(_surface(tester), Offset.zero & _screen);
await tester.pumpAndSettle();
expect(find.text('page x'), findsOneWidget);
});
testWidgets('a Cupertino swipe back shrinks the page with the finger', (
tester,
) async {
await _pump(tester, cupertino: true);
final row = tester.getRect(find.byKey(const Key('row-b')));
await tester.tap(find.byKey(const Key('row-b')));
await tester.pumpAndSettle();
expect(_surface(tester), Offset.zero & _screen);
final gesture = await tester.startGesture(const Offset(5, 400));
await gesture.moveBy(const Offset(20, 0));
await gesture.moveBy(const Offset(100, 0));
await tester.pump();
final early = _surface(tester);
_expectBetween(early, row);
await gesture.moveBy(const Offset(100, 0));
await tester.pump();
final later = _surface(tester);
expect(later.height, lessThan(early.height), reason: 'follows the finger');
// Back toward the start edge, the page grows again.
await gesture.moveBy(const Offset(-150, 0));
await tester.pump();
expect(_surface(tester).height, greaterThan(later.height));
await gesture.moveBy(const Offset(200, 0));
await gesture.up();
await tester.pumpAndSettle();
expect(find.text('page b'), findsNothing);
expect(find.byKey(const Key('row-b')), findsOneWidget);
});
testWidgets('a short Cupertino swipe released early stays on the page', (
tester,
) async {
await _pump(tester, cupertino: true);
await tester.tap(find.byKey(const Key('row-b')));
await tester.pumpAndSettle();
final gesture = await tester.startGesture(const Offset(5, 400));
await gesture.moveBy(const Offset(20, 0));
await gesture.moveBy(const Offset(40, 0));
await tester.pump();
await gesture.up();
await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget);
expect(_surface(tester), Offset.zero & _screen);
});
testWidgets('Android predictive back drives the shrink, then commits', (
tester,
) async {
await _pump(tester);
final row = tester.getRect(find.byKey(const Key('row-b')));
await tester.tap(find.byKey(const Key('row-b')));
await tester.pumpAndSettle();
await _backGesture('startBackGesture', {
'touchOffset': [5.0, 400.0],
'progress': 0.0,
'swipeEdge': 0,
});
await tester.pump();
await _backGesture('updateBackGestureProgress', {
'x': 120.0,
'y': 400.0,
'progress': 0.5,
'swipeEdge': 0,
});
await tester.pump();
_expectBetween(_surface(tester), row);
await _backGesture('cancelBackGesture');
await tester.pumpAndSettle();
expect(find.text('page b'), findsOneWidget);
expect(_surface(tester), Offset.zero & _screen);
await _backGesture('startBackGesture', {
'touchOffset': [5.0, 400.0],
'progress': 0.0,
'swipeEdge': 0,
});
await tester.pump();
await _backGesture('updateBackGestureProgress', {
'x': 200.0,
'y': 400.0,
'progress': 0.7,
'swipeEdge': 0,
});
await tester.pump();
await _backGesture('commitBackGesture');
await tester.pumpAndSettle();
expect(find.text('page b'), findsNothing);
expect(tester.getRect(find.byKey(const Key('row-b'))), row);
});
}