Skip to content
12 changes: 8 additions & 4 deletions integration_test/plans/plans_smoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lantern/core/common/common.dart'
show canUseStoreBilling, isStoreVersion;
show PlatformUtils, canUseStoreBilling, isStoreVersion;
import 'package:lantern/core/extensions/plan.dart';
import 'package:lantern/core/keys/app_keys.dart';
import 'package:lantern/core/localization/i18n.dart';
Expand Down Expand Up @@ -115,13 +115,17 @@ void registerPlansSmokeTests() {
try {
e2eLog('isStoreVersion=${isStoreVersion()}');
// The restore-purchase link is present only when StoreKit or Play
// Billing is currently available.
// Billing is currently available, and never on the TV shell's Plans
// (Settings keeps Restore there).
final restoreShown =
canUseStoreBilling() && !PlatformUtils.tvShellEnabled;
expect(
_restoreLink,
canUseStoreBilling() ? findsOneWidget : findsNothing,
restoreShown ? findsOneWidget : findsNothing,
reason:
'Restore-purchase link does not match '
'canUseStoreBilling()=${canUseStoreBilling()}',
'canUseStoreBilling()=${canUseStoreBilling()} '
'tvShellEnabled=${PlatformUtils.tvShellEnabled}',
);
} finally {
await appRobot.resetToRoot();
Expand Down
12 changes: 12 additions & 0 deletions lib/core/common/app_buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class PrimaryButton extends StatelessWidget {
final bool? isTaller;
final bool? useThemeColor;

/// For a screen that gives this button its first focus (the TV Plans
/// screen); the button keeps its own node when null.
final FocusNode? focusNode;

// Default constructor for button without an icon
const PrimaryButton({
required this.label,
Expand All @@ -36,6 +40,7 @@ class PrimaryButton extends StatelessWidget {
this.showBorder = false,
this.useThemeColor,
this.icon,
this.focusNode,
super.key,
});

Expand All @@ -49,12 +54,14 @@ class PrimaryButton extends StatelessWidget {
return icon == null
? ElevatedButton(
key: buttonKey,
focusNode: focusNode,
onPressed: enabled ? onPressed : null,
style: _buildButtonStyle(context, button!, iconSz),
child: Text(label, textAlign: TextAlign.center),
)
: ElevatedButton.icon(
key: buttonKey,
focusNode: focusNode,
onPressed: enabled ? onPressed : null,
icon: AppImage(
path: icon!,
Expand Down Expand Up @@ -295,8 +302,12 @@ class AppTextButton extends StatelessWidget {
this.padding,
this.underLine = true,
this.fontSize,
this.focusNode,
});

/// The button's focus node, for a screen that gives it focus itself.
final FocusNode? focusNode;

@override
Widget build(BuildContext context) {
final cappedFontSize = fontSize == null ? null : spCap(context, fontSize!);
Expand All @@ -313,6 +324,7 @@ class AppTextButton extends StatelessWidget {
foregroundColor: textColor ?? context.textLink,
);
return TextButton(
focusNode: focusNode,
onPressed: onPressed,
style: style.merge(tvFocusRingButtonStyle(context)),
child: Text(label),
Expand Down
8 changes: 7 additions & 1 deletion lib/core/router/tv_route_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const Set<String> tvRedirectRoutes = {
PersonalProxiesIntro.name,
};

/// Full-screen routes with their own TV layout across the whole screen,
/// instead of the centred phone-width column.
const Set<String> tvOwnLayoutRoutes = {Plans.name};

const Duration tvRouteDuration = Duration(milliseconds: 200);

/// The TV shell's route: every screen is wrapped in [TvShell] unless it is
Expand All @@ -63,9 +67,11 @@ Route<T> tvRouteBuilder<T>(
opaque: page.opaque,
transitionDuration: tvRouteDuration,
reverseTransitionDuration: tvRouteDuration,
// Full-screen routes keep today's centred phone-width column.
// Full-screen routes keep today's centred phone-width column unless
// they lay themselves out for the TV.
pageBuilder: (context, _, _) => fullScreen
? TvFrame(
enabled: !tvOwnLayoutRoutes.contains(name),
background: Theme.of(context).scaffoldBackgroundColor,
child: body,
)
Expand Down
9 changes: 8 additions & 1 deletion lib/features/plans/plan_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ class PlanItem extends StatelessWidget {
required this.onPressed,
this.referralMessage = '',
this.discountPct = 0,
this.cardWidth,
});

/// The width the Best Value badge is placed from; the viewport's when
/// null (the phone). The formula below expects a viewport width and
/// subtracts the phone's page margins, so a caller that has only the
/// card's width passes that plus `2 * defaultSize` (TV does).
final double? cardWidth;

@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
final width = MediaQuery.of(context).size.width;
final width = cardWidth ?? MediaQuery.of(context).size.width;
final finalSize = (width * 0.5) - (defaultSize * 3);
final originalPrice = plan.formatOriginalPrice;
final showOriginalPrice = discountPct > 0 && originalPrice.isNotEmpty;
Expand Down
Loading
Loading