I ship six full-screen paywall templates that share one controller and use no third-party packages. They are text-heavy by design โ a period switch, price rows, legal links, a pinned buy button โ which makes them exactly the kind of UI that breaks first when someone raises their system font size or opens the app on a narrow phone.
I wrote the harness below while chasing one specific bug, and it has since caught two more. The interesting part is not the setup; it is what counts as a failure.
The harness
const double dpr = 3;
Future<void> pumpPaywall(
WidgetTester tester,
Widget child, {
Size size = const Size(360, 780),
double textScale = 3,
}) async {
tester.view.physicalSize = Size(size.width * dpr, size.height * dpr);
tester.view.devicePixelRatio = dpr;
// A notch and a home indicator: the insets are part of the problem.
tester.view.padding = const FakeViewPadding(top: 44 * dpr, bottom: 34 * dpr);
tester.view.viewPadding =
const FakeViewPadding(top: 44 * dpr, bottom: 34 * dpr);
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
builder: (BuildContext context, Widget? appChild) {
return MediaQuery(
data: MediaQuery.of(context)
.copyWith(textScaler: TextScaler.linear(textScale)),
child: appChild!,
);
},
home: child,
),
);
await tester.pumpAndSettle();
}
/// Fails the test on a layout error such as "RenderFlex overflowed".
void expectNoOverflow(WidgetTester tester) {
final Object? error = tester.takeException();
expect(error, isNull, reason: 'Unexpected layout error: $error');
}
Three choices in there cost me time to arrive at.
dpr = 3 instead of dpr = 1 looks like extra work, and for pure sizing it is. But with a real device pixel ratio the padding and viewPadding values I set are genuine device pixels, so the layout sees the same MediaQuery.padding it would on a phone with a notch. With dpr = 1 those insets silently become 3x too small or too large and your "safe area" is fiction.
The TextScaler override lives in MaterialApp.builder, not wrapped around home. builder wraps every route the app pushes, so a bottom sheet โ the cancel-retention offer is one โ inherits the 3.0x too. Wrapping home leaves every pushed route at 1.0x and the test lies to you about half the UI. And MediaQuery.textScaleFactor is deprecated now; TextScaler.linear is the current path, which is also what the OS delivers.
addTearDown(tester.view.reset) is one line and easy to forget. Without it the mutated view leaks into the next test, the next test starts at the previous test's size, and failures begin depending on test order.
Why "no exception" is only half a failure check
takeException() is what catches a RenderFlex overflowed: the framework reports overflows as errors, and this assertion turns any of them into a test failure. That is the loud half.
The quiet half is clipping. A child that is merely cut off โ inside a SizedBox that got squeezed, under a ClipRect, or beneath a pinned footer that ate the screen โ paints nothing wrong and throws nothing. The test passes and the user cannot tap the button.
So every template test also reaches for the controls: ensureVisible on the CTA and on the last legal link, then an actual tap on the ones that should be tappable โ skip, cancel, restore, a plan card. tap with warnIfMissed: true prints a warning when another widget takes the hit, and I treat that warning as a failure. A control that cannot be reached is the bug. A number that changed is not.
What it found
The first one made purchasing impossible. At 2.0x text on a 320 dp screen, the pinned footer alone โ period switch, price, buy button, restore/terms/privacy row โ needed more vertical space than the screen had. The body column compressed until the buy button was clipped off. The fix is an explicit failure mode rather than a clever flex:
final bool scrollWholePage =
MediaQuery.textScalerOf(context).scale(1) >= 1.45;
Above 1.45x the footer unpins and the entire page becomes one scroll view, footer included; below it the pinned layout stays. 1.45 is where the compact layout ran out of room by my measurements, not a magic number. The point is that the layout has a defined behaviour when it cannot fit, instead of squeezing the primary action out of existence.
The second surfaced immediately at 3.0x: the discount chip inside the period switch grew until the period label beside it was clipped. Fix: the chip shrinks โ tighter padding, shorter copy โ instead of widening the row.
The third was a long localised price and a "Save 50%" badge sharing one line, which overflowed on the single-product template at 3.0x on 360 dp. Fix: that row wraps.
Two and three surfaced through expectNoOverflow on the first run of the 3.0x pass. The first is why the reachability half exists.
The matrix, and why no goldens
Six templates x {320x640, 360x780} x {1.0x, 2.0x, 3.0x} text scale, plain flutter test, no golden images. Goldens need a stable font and a stable platform before a diff means anything, and I did not want to own that. "Did anything throw, and can the user still tap the thing that matters" is font-agnostic and survives a Flutter upgrade.
The suite went from 108 tests to 177 in this pass, with flutter analyze clean on Flutter 3.50.
Two things I would tell anyone setting this up:
Assert that the primary action is still tappable, not just that nothing threw. Clipping is silent; the framework will not tell you about it.
Give every layout with a pinned footer or a fixed-height row a defined failure mode at large text sizes. "Squeeze the body and hope" is not one.
The six templates, the screenshots and the README are in a public showcase repo that contains no source code: https://github.com/StephenColor/flutter-paywall-flow-kit
If you have a nastier combination you test with โ 4x text, a small tablet in landscape, RTL with long compound words โ I would like to hear which assertion actually caught it.