first commit
This commit is contained in:
74
test/card_stripe_layout_test.dart
Normal file
74
test/card_stripe_layout_test.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
/// The accent stripe on the Bookings stop card is a `Container` with a width
|
||||
/// and no height, laid out by `Row(crossAxisAlignment: stretch)`. That idiom is
|
||||
/// a trap inside a `ListView`: stretch sizes children to the Row's own
|
||||
/// cross-axis extent, which in a scrollable is UNBOUNDED, so the stripe is
|
||||
/// asked to be infinitely tall and the entire card fails to lay out.
|
||||
///
|
||||
/// It fails silently in the worst possible way — the progress rail above the
|
||||
/// list is a separate widget reading the same data, so it kept showing the
|
||||
/// right stop count while every card rendered as nothing. That looked exactly
|
||||
/// like "the bookings data is broken", and three rounds of data fixes chased
|
||||
/// it before the layout was suspected.
|
||||
///
|
||||
/// PickupCard itself is private to the `pickups.dart` library and cannot be
|
||||
/// imported, so these tests pin the idiom rather than the widget.
|
||||
void main() {
|
||||
Widget inList(Widget child) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ListView(children: [child]),
|
||||
),
|
||||
);
|
||||
|
||||
Widget stripeRow({required bool withIntrinsicHeight}) {
|
||||
final row = Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(width: 4, color: const Color(0xFF960019)),
|
||||
const Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(12),
|
||||
child: Text('Sri Balaji Stores\n19, Thadagam Road'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
child: withIntrinsicHeight ? IntrinsicHeight(child: row) : row,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('a stretch Row with a height-less child breaks in a ListView',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(inList(stripeRow(withIntrinsicHeight: false)));
|
||||
expect(tester.takeException(), isNotNull,
|
||||
reason: 'this is the shape that made every stop card disappear');
|
||||
});
|
||||
|
||||
testWidgets('IntrinsicHeight gives stretch something finite to stretch to',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(inList(stripeRow(withIntrinsicHeight: true)));
|
||||
expect(tester.takeException(), isNull);
|
||||
|
||||
// And the card has real height — an invisible zero-height card would pass
|
||||
// an exception check while still showing the rider nothing.
|
||||
final size = tester.getSize(find.byType(IntrinsicHeight));
|
||||
expect(size.height, greaterThan(20));
|
||||
|
||||
// The stripe spans the full card height rather than collapsing.
|
||||
final stripe = tester.getSize(
|
||||
find.descendant(
|
||||
of: find.byType(IntrinsicHeight),
|
||||
matching: find.byType(Container),
|
||||
).first,
|
||||
);
|
||||
expect(stripe.height, size.height);
|
||||
expect(stripe.width, 4);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user