π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile][photos] Revamp onboarding and subscription screens
r4khul106dc78670fb
diff --git a/mobile/apps/photos/changes/subscription-revamp.md b/mobile/apps/photos/changes/subscription-revamp.mdnew file mode 100644index 0000000000..85db19e2a4--- /dev/null+++ b/mobile/apps/photos/changes/subscription-revamp.md@@ -0,0 +1 @@+- Refreshed the plan picker and subscription screens.diff --git a/mobile/apps/photos/lib/ui/payment/billing_questions_widget.dart b/mobile/apps/photos/lib/ui/payment/billing_questions_widget.dartindex d5dd11de36..da939de2ca 100644--- a/mobile/apps/photos/lib/ui/payment/billing_questions_widget.dart+++ b/mobile/apps/photos/lib/ui/payment/billing_questions_widget.dart@@ -1,9 +1,8 @@import 'dart:convert';-import 'package:ente_components/ente_components.dart';+import 'package:ente_ui/components/faq/faq_widgets.dart';import 'package:ente_ui/components/loading_widget.dart';import 'package:flutter/material.dart';-import 'package:hugeicons/hugeicons.dart';import 'package:photos/core/network/network.dart';class BillingQuestionsWidget extends StatefulWidget {@@ -40,12 +39,10 @@ class _BillingQuestionsWidgetState extends State<BillingQuestionsWidget> {if (faqs == null) {return const EnteLoadingWidget();}- return Column(+ return FaqSection(children: [- for (var i = 0; i < faqs.length; i++) ...[- if (i > 0) const SizedBox(height: Spacing.sm),- FaqWidget(faq: faqs[i]),- ],+ for (final faq in faqs)+ FaqItemWidget(question: faq.q ?? '', answer: faq.a ?? ''),],);},@@ -53,86 +50,6 @@ class _BillingQuestionsWidgetState extends State<BillingQuestionsWidget> {}}-class FaqWidget extends StatefulWidget {- const FaqWidget({super.key, required this.faq});-- final FaqItem faq;-- @override- State<FaqWidget> createState() => _FaqWidgetState();-}--class _FaqWidgetState extends State<FaqWidget> {- bool _isExpanded = false;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- return Material(- color: colors.fillLight,- borderRadius: BorderRadius.circular(Radii.button),- clipBehavior: Clip.antiAlias,- child: InkWell(- onTap: () => setState(() => _isExpanded = !_isExpanded),- child: Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- Padding(- padding: const EdgeInsets.fromLTRB(- Spacing.xl,- Spacing.lg,- Spacing.xl,- Spacing.md,- ),- child: Row(- children: [- Expanded(- child: Text(- widget.faq.q ?? '',- style: TextStyles.bodyBold.copyWith(- color: colors.textBase,- ),- ),- ),- const SizedBox(width: Spacing.sm),- HugeIcon(- icon: _isExpanded- ? HugeIcons.strokeRoundedArrowUp01- : HugeIcons.strokeRoundedArrowDown01,- size: IconSizes.small,- color: colors.textBase,- ),- ],- ),- ),- AnimatedSize(- duration: Motion.standard,- curve: Curves.easeInOutCubic,- alignment: Alignment.topCenter,- child: _isExpanded- ? Padding(- padding: const EdgeInsets.fromLTRB(- Spacing.xl,- 0,- Spacing.xl,- Spacing.lg,- ),- child: Text(- widget.faq.a ?? '',- style: TextStyles.mini.copyWith(- color: colors.textLight,- ),- ),- )- : const SizedBox(width: double.infinity),- ),- ],- ),- ),- );- }-}-class FaqItem {final String? q;final String? a;diff --git a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dartindex 8ba3b45f8a..d9c6ce4ee0 100644--- a/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart+++ b/mobile/apps/photos/lib/ui/payment/store_subscription_page.dart@@ -5,9 +5,8 @@ import "package:ente_components/ente_components.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:ente_strings/ente_strings.dart";import 'package:ente_ui/components/loading_widget.dart';-import "package:flutter/foundation.dart";+import 'package:ente_ui/components/subscription/plan_card.dart';import 'package:flutter/material.dart';-import "package:hugeicons/hugeicons.dart";import 'package:in_app_purchase/in_app_purchase.dart';import 'package:logging/logging.dart';import "package:photos/core/constants.dart";@@ -30,6 +29,7 @@ import 'package:photos/ui/components/models/button_type.dart';import 'package:photos/ui/family/family_plan_page.dart';import 'package:photos/ui/notification/toast.dart';import 'package:photos/ui/payment/subscription_common_widgets.dart';+import "package:photos/ui/payment/subscription_page_scaffold.dart";import 'package:photos/ui/payment/subscription_plan_widget.dart';import "package:photos/ui/payment/view_add_on_widget.dart";import 'package:photos/utils/dialog_util.dart';@@ -197,7 +197,6 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {@overrideWidget build(BuildContext context) {- final textTheme = getEnteTextTheme(context);colorScheme = getEnteColorScheme(context);if (!_isLoading) {_isLoading = true;@@ -208,63 +207,23 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {context.strings.pleaseWait,isDismissible: true,);- if (widget.isOnboarding) {- return _buildOnboardingPage();- }- return Scaffold(- backgroundColor: colorScheme.backgroundColour,- appBar: AppBar(- elevation: 0,- backgroundColor: colorScheme.backgroundColour,- leading: IconButton(- icon: const Icon(Icons.arrow_back),- color: colorScheme.content,- onPressed: () {- Navigator.of(context).pop();- },- ),- title: Text(- "${context.strings.subscription}${kDebugMode ? ' Store' : ''}",- style: textTheme.largeBold,- ),- centerTitle: true,- ),- body: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [Expanded(child: _getBody())],- ),- );+ return _buildSubscriptionPage();}- Widget _buildOnboardingPage() {- final colors = context.componentColors;- return OnboardingPageScaffold(- key: _scaffoldKey,- title: context.strings.chooseYourPlan,- illustration: OnboardingIllustration.pricing,- headerHeight: OnboardingPageScaffold.planHeaderHeight,- titleBarStyle: OnboardingTitleBarStyle.header,- headerTrailing: IconButtonComponent(- variant: IconButtonComponentVariant.unfilled,- size: 48,- iconSize: IconSizes.medium,- icon: HugeIcon(- icon: HugeIcons.strokeRoundedHelpCircle,- color: colors.specialWhite,- ),- tooltip: context.strings.faqs,- onTap: () => showPlanFaqSheet(context),- ),+ Widget _buildSubscriptionPage() {+ return SubscriptionPageScaffold(+ scaffoldKey: _scaffoldKey,+ onHelpTap: () => showPlanFaqSheet(context),isBodyCentered: !_hasLoadedData,- pinActions: true,- body: _hasLoadedData- ? _buildOnboardingPlans()- : const EnteLoadingWidget(),+ body: widget.isOnboarding+ ? (_hasLoadedData+ ? _buildOnboardingPlans()+ : const EnteLoadingWidget())+ : _getBody(),actions: [- if (_hasLoadedData)- ButtonComponent(- label: context.strings.continueLabel,- shouldShowSuccessState: false,+ if (widget.isOnboarding && _hasLoadedData)+ SubscriptionContinueButton(+ label: _continueLabel(),isDisabled: _selectedProductID == null,onTap: _selectedProductID == null ? null : _onOnboardingContinueTap,),@@ -272,6 +231,21 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {);}+ String _continueLabel() {+ final selected = _selectedProductID;+ final storage = selected == freeProductID+ ? _freePlan.storage+ : _plans+ .where((plan) => _getPlanProductID(plan) == selected)+ .firstOrNull+ ?.storage;+ return storage == null+ ? context.strings.continueLabel+ : context.strings.subscriptionContinueWithPlan(+ storage: subscriptionStorageLabel(storage),+ );+ }+Widget _buildOnboardingPlans() {return Column(mainAxisSize: MainAxisSize.min,@@ -393,7 +367,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {if (hasYearlyPlans) {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 32),+ padding: const EdgeInsets.only(bottom: Spacing.lg),child: SubscriptionToggle(isYearly: showYearlyPlan,onToggle: _onToggleBillingPeriod,@@ -404,7 +378,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {widgets.add(Padding(- padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),+ padding: const EdgeInsets.only(bottom: Spacing.xxl),child: SubscriptionPlanList(children: _isActiveStripeSubscriber? _getStripePlanWidgets()@@ -439,7 +413,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {} else {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),child: MenuItemWidgetNew(title: context.strings.managePaymentMethod,menuItemColor: colorScheme.fillFaint,@@ -459,7 +433,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {widgets.add(const Padding(- padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),+ padding: EdgeInsets.symmetric(vertical: Spacing.xs),child: SubFaqWidget(),),);@@ -467,17 +441,11 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {if (!widget.isOnboarding) {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),- child: MenuItemWidgetNew(+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),+ child: SubscriptionFamilyWidget(title: _isFreePlanUser()? context.strings.family: context.strings.manageFamily,- menuItemColor: colorScheme.fillFaint,- pressedColor: colorScheme.fillFaintPressed,- trailingWidget: Icon(- Icons.chevron_right_outlined,- color: colorScheme.strokeBase,- ),onTap: () async {late final UserDetails userDetails;try {@@ -511,11 +479,9 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {widgets.add(const SizedBox(height: 80));- return SingleChildScrollView(- child: Column(- mainAxisAlignment: MainAxisAlignment.spaceEvenly,- children: widgets,- ),+ return Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: widgets,);}@@ -605,6 +571,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {isActive: widget.isOnboarding? _selectedProductID == productID: isActive && !_hideCurrentPlanSelection,+ isCurrentPlan: isActive && !_hideCurrentPlanSelection,isPopular: _isPopularPlan(plan),monthlyPrice: _monthlyPriceFor(plan),),@@ -634,6 +601,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {isActive: widget.isOnboarding? _selectedProductID == freeProductID: _isFreePlanUser(),+ isCurrentPlan: _isFreePlanUser(),),),);@@ -718,6 +686,7 @@ class _StoreSubscriptionPageState extends State<StoreSubscriptionPage> {isActive: widget.isOnboarding? _selectedProductID == productID: isActive,+ isCurrentPlan: isActive && !_hideCurrentPlanSelection,isPopular: _isPopularPlan(plan),monthlyPrice: _monthlyPriceFor(plan),),diff --git a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dartindex a284c3f075..cf5ac7c538 100644--- a/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart+++ b/mobile/apps/photos/lib/ui/payment/stripe_subscription_page.dart@@ -4,8 +4,8 @@ import "package:ente_components/ente_components.dart";import "package:ente_pure_utils/ente_pure_utils.dart";import "package:ente_strings/ente_strings.dart";import 'package:ente_ui/components/loading_widget.dart';+import 'package:ente_ui/components/subscription/plan_card.dart';import 'package:flutter/material.dart';-import "package:hugeicons/hugeicons.dart";import "package:logging/logging.dart";import "package:photos/core/event_bus.dart";import "package:photos/events/subscription_purchased_event.dart";@@ -25,6 +25,7 @@ import 'package:photos/ui/family/family_plan_page.dart';import 'package:photos/ui/notification/toast.dart';import 'package:photos/ui/payment/payment_web_page.dart';import 'package:photos/ui/payment/subscription_common_widgets.dart';+import "package:photos/ui/payment/subscription_page_scaffold.dart";import 'package:photos/ui/payment/subscription_plan_widget.dart';import "package:photos/ui/payment/view_add_on_widget.dart";import 'package:photos/utils/dialog_util.dart';@@ -139,36 +140,12 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {@overrideWidget build(BuildContext context) {colorScheme = getEnteColorScheme(context);- final textTheme = getEnteTextTheme(context);if (!_isLoading) {_isLoading = true;_dialog = createProgressDialog(context, context.strings.pleaseWait);_fetchSub();}- if (widget.isOnboarding) {- return _buildOnboardingPage();- }-- return Scaffold(- backgroundColor: colorScheme.backgroundColour,- appBar: AppBar(- elevation: 0,- backgroundColor: colorScheme.backgroundColour,- leading: IconButton(- icon: const Icon(Icons.arrow_back),- color: colorScheme.content,- onPressed: () {- Navigator.of(context).pop();- },- ),- title: Text(context.strings.subscription, style: textTheme.largeBold),- centerTitle: true,- ),- body: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [Expanded(child: _getBody())],- ),- );+ return _buildSubscriptionPage();}Widget _getBody() {@@ -178,35 +155,20 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {return const EnteLoadingWidget();}- Widget _buildOnboardingPage() {- final colors = context.componentColors;- return OnboardingPageScaffold(- key: _scaffoldKey,- title: context.strings.chooseYourPlan,- illustration: OnboardingIllustration.pricing,- headerHeight: OnboardingPageScaffold.planHeaderHeight,- titleBarStyle: OnboardingTitleBarStyle.header,- headerTrailing: IconButtonComponent(- variant: IconButtonComponentVariant.unfilled,- size: 48,- iconSize: IconSizes.medium,- icon: HugeIcon(- icon: HugeIcons.strokeRoundedHelpCircle,- color: colors.specialWhite,- ),- tooltip: context.strings.faqs,- onTap: () => showPlanFaqSheet(context),- ),+ Widget _buildSubscriptionPage() {+ return SubscriptionPageScaffold(+ scaffoldKey: _scaffoldKey,+ onHelpTap: () => showPlanFaqSheet(context),isBodyCentered: !_hasLoadedData,- pinActions: true,- body: _hasLoadedData- ? _buildOnboardingPlans()- : const EnteLoadingWidget(),+ body: widget.isOnboarding+ ? (_hasLoadedData+ ? _buildOnboardingPlans()+ : const EnteLoadingWidget())+ : _getBody(),actions: [- if (_hasLoadedData)- ButtonComponent(- label: context.strings.continueLabel,- shouldShowSuccessState: false,+ if (widget.isOnboarding && _hasLoadedData)+ SubscriptionContinueButton(+ label: _continueLabel(),isDisabled: _selectedPlanProductID == null,onTap: _selectedPlanProductID == null? null@@ -216,6 +178,21 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {);}+ String _continueLabel() {+ final selected = _selectedPlanProductID;+ final storage = selected == freeProductID+ ? _freePlan.storage+ : _plans+ .where((plan) => plan.stripeID == selected)+ .firstOrNull+ ?.storage;+ return storage == null+ ? context.strings.continueLabel+ : context.strings.subscriptionContinueWithPlan(+ storage: subscriptionStorageLabel(storage),+ );+ }+Widget _buildOnboardingPlans() {return Column(mainAxisSize: MainAxisSize.min,@@ -254,7 +231,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 32),+ padding: const EdgeInsets.only(bottom: Spacing.lg),child: SubscriptionToggle(isYearly: _showYearlyPlan,onToggle: _onToggleBillingPeriod,@@ -264,7 +241,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {widgets.add(Padding(- padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),+ padding: const EdgeInsets.only(bottom: Spacing.xxl),child: SubscriptionPlanList(children: _getStripePlanWidgets()),),);@@ -287,7 +264,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {if (_currentSubscription!.productID == freeProductID) {widgets.add(const Padding(- padding: EdgeInsets.symmetric(horizontal: 16, vertical: 4),+ padding: EdgeInsets.symmetric(vertical: Spacing.xs),child: SubFaqWidget(),),);@@ -299,15 +276,9 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {if (!widget.isOnboarding) {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),- child: MenuItemWidgetNew(+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),+ child: SubscriptionFamilyWidget(title: context.strings.manageFamily,- menuItemColor: colorScheme.fillFaint,- pressedColor: colorScheme.fillFaintPressed,- trailingWidget: Icon(- Icons.chevron_right_outlined,- color: colorScheme.strokeBase,- ),onTap: () async {late final UserDetails userDetails;try {@@ -342,7 +313,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {if (_currentSubscription!.productID != freeProductID) {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),child: MenuItemWidgetNew(title: "Manage payment method",menuItemColor: colorScheme.fillFaint,@@ -362,7 +333,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {if (_hasActiveSubscription && _isStripeSubscriber) {widgets.add(Padding(- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),+ padding: const EdgeInsets.symmetric(vertical: Spacing.xs),child: _stripeRenewOrCancelButton(),),);@@ -370,11 +341,9 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {widgets.add(const SizedBox(height: 80));- return SingleChildScrollView(- child: Column(- mainAxisAlignment: MainAxisAlignment.spaceEvenly,- children: widgets,- ),+ return Column(+ crossAxisAlignment: CrossAxisAlignment.stretch,+ children: widgets,);}@@ -538,6 +507,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {isActive: widget.isOnboarding? _selectedPlanProductID == freeProductID: _isFreePlanUser(),+ isCurrentPlan: _isFreePlanUser(),),),);@@ -626,6 +596,7 @@ class _StripeSubscriptionPageState extends State<StripeSubscriptionPage> {isActive: widget.isOnboarding? _selectedPlanProductID == productID: isActive && !_hideCurrentPlanSelection,+ isCurrentPlan: isActive && !_hideCurrentPlanSelection,isPopular: _isPopularPlan(plan),monthlyPrice: _monthlyPriceFor(plan),),diff --git a/mobile/apps/photos/lib/ui/payment/subscription_common_widgets.dart b/mobile/apps/photos/lib/ui/payment/subscription_common_widgets.dartindex 92e6857f02..39720a2062 100644--- a/mobile/apps/photos/lib/ui/payment/subscription_common_widgets.dart+++ b/mobile/apps/photos/lib/ui/payment/subscription_common_widgets.dart@@ -1,8 +1,13 @@+import 'dart:async';+import 'dart:math' as math;+import "package:ente_components/ente_components.dart";import 'package:ente_pure_utils/ente_pure_utils.dart';import "package:ente_strings/ente_strings.dart";+import 'package:ente_ui/components/faq/faq_widgets.dart';+import 'package:ente_ui/components/subscription/billing_period_toggle.dart';+import 'package:ente_ui/components/subscription/family_card.dart';import 'package:flutter/material.dart';-import "package:hugeicons/hugeicons.dart";import "package:intl/intl.dart";import 'package:photos/gateways/billing/models/subscription.dart';import "package:photos/gateways/storage_bonus/models/bonus.dart";@@ -92,29 +97,78 @@ class AddOnBonusValidity extends StatelessWidget {}}+class SubscriptionContinueButton extends StatelessWidget {+ const SubscriptionContinueButton({+ super.key,+ required this.label,+ this.onTap,+ this.isDisabled = false,+ });++ final String label;+ final FutureOr<void> Function()? onTap;+ final bool isDisabled;++ @override+ Widget build(BuildContext context) {+ final labelStyle = TextStyles.large.copyWith(+ fontFamily: TextStyles.outfitFontFamily,+ package: TextStyles.fontPackage,+ fontWeight: FontWeight.w700,+ );+ return LayoutBuilder(+ builder: (context, constraints) {+ final painter = TextPainter(+ text: TextSpan(text: label, style: labelStyle),+ maxLines: 2,+ textDirection: Directionality.of(context),+ textScaler: MediaQuery.textScalerOf(context),+ locale: Localizations.localeOf(context),+ )..layout(maxWidth: math.max(0, constraints.maxWidth - Spacing.xl * 2));+ final fits = !painter.didExceedMaxLines;+ painter.dispose();+ return ButtonComponent(+ label: fits ? label : context.strings.continueLabel,+ labelStyle: labelStyle,+ variant: ButtonComponentVariant.neutral,+ shouldShowSuccessState: false,+ isDisabled: isDisabled,+ onTap: onTap,+ );+ },+ );+ }+}+class SubFaqWidget extends StatelessWidget {const SubFaqWidget({super.key});@overrideWidget build(BuildContext context) {- final colors = context.componentColors;- return MenuGroupComponent(- items: [- MenuComponent(- title: context.strings.faqs,- leading: HugeIcon(- icon: HugeIcons.strokeRoundedHelpCircle,- size: IconSizes.small,- color: colors.textBase,- ),- trailing: HugeIcon(- icon: HugeIcons.strokeRoundedArrowRight01,- size: IconSizes.small,- color: colors.textBase,- ),- onTap: () => showPlanFaqSheet(context),- ),- ],+ return FaqCard(+ title: context.strings.faqs,+ subtitle: context.strings.subscriptionFaqDescription,+ onTap: () => showPlanFaqSheet(context),+ );+ }+}++class SubscriptionFamilyWidget extends StatelessWidget {+ const SubscriptionFamilyWidget({+ super.key,+ required this.title,+ required this.onTap,+ });++ final String title;+ final FutureOr<void> Function() onTap;++ @override+ Widget build(BuildContext context) {+ return FamilyCard(+ title: title,+ subtitle: context.strings.subscriptionFamilyDescription,+ onTap: onTap,);}}@@ -131,124 +185,21 @@ Future<void> showPlanFaqSheet(BuildContext context) {);}-class SubscriptionPlanList extends StatelessWidget {- const SubscriptionPlanList({super.key, required this.children});-- final List<Widget> children;-- @override- Widget build(BuildContext context) {- return Column(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- for (var i = 0; i < children.length; i++) ...[- if (i > 0) const SizedBox(height: Spacing.sm),- children[i],- ],- ],- );- }-}--class SubscriptionToggle extends StatefulWidget {- final bool isYearly;- final Function(bool) onToggle;+class SubscriptionToggle extends StatelessWidget {const SubscriptionToggle({+ super.key,required this.isYearly,required this.onToggle,- super.key,});- @override- State<SubscriptionToggle> createState() => _SubscriptionToggleState();-}--class _SubscriptionToggleState extends State<SubscriptionToggle> {- static const double _padding = Spacing.xs;- static const double _minSegmentHeight = 41;- static const double _radius = 35;-- late bool _isYearly;-- @override- void initState() {- super.initState();- _isYearly = widget.isYearly;- }-- @override- void didUpdateWidget(covariant SubscriptionToggle oldWidget) {- super.didUpdateWidget(oldWidget);- if (oldWidget.isYearly != widget.isYearly) {- _isYearly = widget.isYearly;- }- }+ final bool isYearly;+ final ValueChanged<bool> onToggle;@override- Widget build(BuildContext context) {- final colors = context.componentColors;- final labelStyle = TextStyles.body.copyWith(color: colors.textLight);- return Container(- padding: const EdgeInsets.all(_padding),- decoration: BoxDecoration(- color: colors.strokeFaint,- borderRadius: BorderRadius.circular(_radius),- ),- child: Stack(- children: [- Positioned.fill(- child: AnimatedAlign(- duration: Motion.slow,- curve: Curves.easeInOutCubic,- alignment: _isYearly- ? Alignment.centerLeft- : Alignment.centerRight,- child: FractionallySizedBox(- widthFactor: 0.5,- heightFactor: 1,- child: DecoratedBox(- decoration: BoxDecoration(- color: colors.fillLight,- borderRadius: BorderRadius.circular(_radius),- ),- ),- ),- ),- ),- IntrinsicHeight(- child: Row(- crossAxisAlignment: CrossAxisAlignment.stretch,- children: [- _segment(context.strings.yearly, true, labelStyle),- _segment(context.strings.monthly, false, labelStyle),- ],- ),- ),- ],- ),- );- }-- Widget _segment(String label, bool isYearly, TextStyle style) {- return Expanded(- child: GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () => setIsYearly(isYearly),- child: ConstrainedBox(- constraints: const BoxConstraints(minHeight: _minSegmentHeight),- child: Center(- child: Text(label, style: style, textAlign: TextAlign.center),- ),- ),- ),- );- }-- void setIsYearly(bool isYearly) {- if (_isYearly == isYearly) return;- setState(() {- _isYearly = isYearly;- });- widget.onToggle(isYearly);- }+ Widget build(BuildContext context) => BillingPeriodToggle(+ monthlyLabel: context.strings.monthly,+ yearlyLabel: context.strings.yearly,+ isYearly: isYearly,+ onToggle: onToggle,+ );}diff --git a/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dart b/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dartindex 1a68eaf45a..1ad35dd87c 100644--- a/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dart+++ b/mobile/apps/photos/lib/ui/payment/subscription_plan_widget.dart@@ -1,9 +1,16 @@-import "dart:math" as math;-import 'package:ente_components/ente_components.dart';import 'package:ente_pure_utils/ente_pure_utils.dart';import "package:ente_strings/ente_strings.dart";+import 'package:ente_ui/components/subscription/plan_card.dart';+import 'package:ente_ui/components/subscription/plan_price.dart';+import 'package:flutter/gestures.dart';import 'package:flutter/material.dart';+import "package:photos/ui/payment/subscription_locker_sheet.dart";++String subscriptionStorageLabel(int storage) {+ final (value, unit) = convertBytesToNumberAndUnit(storage);+ return "$value ${unit.toUpperCase()}";+}class SubscriptionPlanWidget extends StatelessWidget {const SubscriptionPlanWidget({@@ -13,173 +20,100 @@ class SubscriptionPlanWidget extends StatelessWidget {required this.period,this.monthlyPrice,this.isActive = false,+ this.isCurrentPlan = false,this.isPopular = false,});- static const double height = 84;- static const double _borderWidth = 2;- static const double _horizontalPadding = Spacing.xl - _borderWidth;- static const double _verticalPadding = Spacing.lg - _borderWidth;- static const double _contentMinHeight =- height - 2 * _borderWidth - 2 * _verticalPadding;- static const double _badgeWidth = 102;- static const double _badgeHeight = 26;- static const double _badgeLineHeight = 20;- static const double _badgeVerticalPadding =- (_badgeHeight - _badgeLineHeight) / 2;-final int storage;final String price;final String period;-final String? monthlyPrice;final bool isActive;+ final bool isCurrentPlan;final bool isPopular;@overrideWidget build(BuildContext context) {final colors = context.componentColors;- final numAndUnit = convertBytesToNumberAndUnit(storage);- int storageValueInUnit = numAndUnit.$1;- String storageUnit = numAndUnit.$2.toUpperCase();- if (storageUnit == "TB") {- storageValueInUnit = storageValueInUnit * 1000;- storageUnit = "GB";- }- final String storageValue = storageValueInUnit.toString();- final badgeHeight =- MediaQuery.textScalerOf(context).scale(_badgeLineHeight) +- 2 * _badgeVerticalPadding;- final badgeOverflow = isPopular- ? math.max(0.0, badgeHeight - _badgeHeight)- : 0.0;-- return Container(- clipBehavior: Clip.antiAlias,- decoration: BoxDecoration(- color: colors.fillLight,- borderRadius: BorderRadius.circular(Radii.button),- border: Border.all(- color: isActive ? colors.primary : Colors.transparent,- width: _borderWidth,- ),+ final (value, unit) = convertBytesToNumberAndUnit(storage);+ return SubscriptionPlanCard(+ value: value.toString(),+ unit: unit.toUpperCase(),+ isSelected: isActive,+ isFree: price.isEmpty,+ badgeLabel: isCurrentPlan+ ? context.strings.subscriptionCurrentPlan+ : isPopular+ ? context.strings.mostPopular+ : null,+ includedAllowance: _LockerAllowance(+ count: price.isEmpty ? 100 : 1000,+ isActive: isActive,+ color: isActive ? colors.specialWhite : colors.textLight,+ ),+ price: _Price(+ price: price,+ period: period,+ monthlyPrice: monthlyPrice,+ isActive: isActive,),- child: Stack(- clipBehavior: Clip.none,+ );+ }+}++class _LockerAllowance extends StatefulWidget {+ const _LockerAllowance({+ required this.count,+ required this.isActive,+ required this.color,+ });++ final int count;+ final bool isActive;+ final Color color;++ @override+ State<_LockerAllowance> createState() => _LockerAllowanceState();+}++class _LockerAllowanceState extends State<_LockerAllowance> {+ final _lockerTap = TapGestureRecognizer();++ @override+ void initState() {+ super.initState();+ _lockerTap.onTap = () => showSubscriptionLockerSheet(context);+ }++ @override+ void dispose() {+ _lockerTap.dispose();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final label = context.strings+ .subscriptionLockerItems(count: widget.count, appName: "\uFFFC")+ .split("\uFFFC");+ return Text.rich(+ TextSpan(children: [- Padding(- padding: EdgeInsets.fromLTRB(- _horizontalPadding,- _verticalPadding + badgeOverflow,- _horizontalPadding,- _verticalPadding,- ),- child: ConstrainedBox(- constraints: const BoxConstraints(minHeight: _contentMinHeight),- child: Column(- mainAxisAlignment: isPopular- ? MainAxisAlignment.end- : MainAxisAlignment.center,- children: [- Row(- mainAxisAlignment: MainAxisAlignment.spaceBetween,- children: [- Expanded(- child: Align(- alignment: Alignment.centerLeft,- child: RichText(- text: TextSpan(- style: TextStyle(- color: colors.textBase,- fontFamily: TextStyles.outfitFontFamily,- package: TextStyles.fontPackage,- fontWeight: FontWeight.w900,- ),- children: [- TextSpan(- text: storageValue,- style: const TextStyle(- fontSize: 36,- height: 28 / 36,- letterSpacing: -1.8,- ),- ),- const TextSpan(- text: " ",- style: TextStyle(- fontSize: 24,- height: 28 / 24,- letterSpacing: -0.96,- ),- ),- TextSpan(- text: storageUnit,- style: const TextStyle(- fontSize: 16,- height: 28 / 16,- fontWeight: FontWeight.w700,- ),- ),- ],- ),- textHeightBehavior: const TextHeightBehavior(- applyHeightToFirstAscent: false,- applyHeightToLastDescent: false,- ),- ),- ),- ),- Flexible(- child: Align(- alignment: Alignment.centerRight,- child: _Price(- price: price,- period: period,- monthlyPrice: monthlyPrice,- ),- ),- ),- ],- ),- ],- ),+ TextSpan(text: label[0]),+ TextSpan(+ text: "Locker",+ recognizer: widget.isActive ? _lockerTap : null,+ style: TextStyle(+ decoration: widget.isActive+ ? TextDecoration.underline+ : TextDecoration.none,+ decorationColor: widget.color,),),- if (isPopular)- Positioned(- left: -_borderWidth,- top: -_borderWidth,- child: Container(- constraints: const BoxConstraints(- minWidth: _badgeWidth,- minHeight: _badgeHeight,- ),- padding: const EdgeInsets.symmetric(- horizontal: Spacing.lg,- vertical: _badgeVerticalPadding,- ),- alignment: Alignment.center,- decoration: BoxDecoration(- color: colors.primary,- borderRadius: const BorderRadius.only(- topLeft: Radius.circular(Radii.button),- bottomRight: Radius.circular(Radii.button),- ),- ),- child: Text(- context.strings.mostPopular,- textAlign: TextAlign.center,- style: TextStyles.tiny.copyWith(- color: colors.specialWhite,- fontFamily: TextStyles.outfitFontFamily,- fontWeight: FontWeight.w700,- height: _badgeLineHeight / 10,- ),- ),- ),- ),+ TextSpan(text: label[1]),],),+ style: TextStyles.mini.copyWith(color: widget.color, height: 18 / 12),);}}@@ -189,39 +123,29 @@ class _Price extends StatelessWidget {required this.price,required this.period,required this.monthlyPrice,+ required this.isActive,});final String price;final String period;final String? monthlyPrice;+ final bool isActive;@overrideWidget build(BuildContext context) {- final colors = context.componentColors;- final amountStyle = TextStyles.large.copyWith(- color: colors.textBase,- height: 28 / 16,- );- final periodStyle = TextStyles.mini.copyWith(- color: colors.textLight,- height: 28 / 12,- );if (price.isEmpty) {- return Text(context.strings.free, style: amountStyle);+ return SubscriptionPrice(+ amount: context.strings.free,+ isSelected: isActive,+ );}-if (period == "month") {- return Text.rich(- TextSpan(- children: [- TextSpan(text: price, style: amountStyle),- TextSpan(text: "/${context.strings.month}", style: periodStyle),- ],- ),- textAlign: TextAlign.end,+ return SubscriptionPrice(+ amount: _displayPrice(price),+ periodLabel: context.strings.month,+ isSelected: isActive,);}-assert(period == "year", "Invalid period: $period");final currencySymbol = price[0];final pricePerMonth = double.parse(price.substring(1)) / 12;@@ -232,47 +156,24 @@ class _Price extends StatelessWidget {pricePerMonthString.length - 3,);}- final perMonthStyle = TextStyles.tiny.copyWith(- color: colors.textLight,- height: 16 / 10,- );- return Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.end,- children: [- Text.rich(- TextSpan(- children: [- TextSpan(text: price, style: amountStyle),- TextSpan(text: "/${context.strings.year}", style: periodStyle),- ],- ),- textAlign: TextAlign.end,- ),- Text.rich(- TextSpan(- children: [- if (monthlyPrice != null) ...[- TextSpan(- text: monthlyPrice,- style: perMonthStyle.copyWith(- decoration: TextDecoration.lineThrough,- decorationColor: colors.textLight,- ),- ),- const TextSpan(text: " β "),- ],- TextSpan(- text:- "$currencySymbol$pricePerMonthString"- "/${context.strings.month}",- ),- ],- style: perMonthStyle,- ),- textAlign: TextAlign.end,- ),- ],+ return SubscriptionPrice(+ amount: _displayPrice(price),+ periodLabel: context.strings.year,+ monthlyPriceLabel:+ "${_displayPrice("$currencySymbol$pricePerMonthString")}/${context.strings.month}",+ originalMonthlyPrice: monthlyPrice == null+ ? null+ : _displayPrice(monthlyPrice!),+ isSelected: isActive,);}}++String _displayPrice(String price) {+ final parts = price.split(".");+ parts[0] = parts[0].replaceAllMapped(+ RegExp(r"\d(?=(\d{3})+$)"),+ (match) => "${match[0]},",+ );+ return parts.join(".");+}diff --git a/mobile/apps/photos/test/ui/payment/subscription_plan_widget_test.dart b/mobile/apps/photos/test/ui/payment/subscription_plan_widget_test.dartnew file mode 100644index 0000000000..7bed2842ab--- /dev/null+++ b/mobile/apps/photos/test/ui/payment/subscription_plan_widget_test.dart@@ -0,0 +1,104 @@+import "package:ente_strings/ente_strings.dart";+import "package:flutter/material.dart";+import "package:flutter/rendering.dart";+import "package:flutter/services.dart";+import "package:flutter_test/flutter_test.dart";+import "package:photos/ente_theme_data.dart";+import "package:photos/ui/payment/subscription_common_widgets.dart";+import "package:photos/ui/payment/subscription_locker_sheet.dart";+import "package:photos/ui/payment/subscription_page_scaffold.dart";+import "package:photos/ui/payment/subscription_plan_widget.dart";++void main() {+ testWidgets("subscription selection preserves taps and readable Continue", (+ tester,+ ) async {+ final font = FontLoader("packages/ente_components/Outfit")+ ..addFont(+ rootBundle.load("packages/ente_components/fonts/Outfit-Bold.ttf"),+ );+ await font.load();+ tester.view.physicalSize = const Size(320, 568);+ tester.view.devicePixelRatio = 1;+ addTearDown(tester.view.resetPhysicalSize);+ addTearDown(tester.view.resetDevicePixelRatio);+ addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);+ var selected = false;+ var selections = 0;+ var continues = 0;+ await tester.pumpWidget(+ MaterialApp(+ theme: lightThemeData,+ localizationsDelegates: StringsLocalizations.localizationsDelegates,+ supportedLocales: StringsLocalizations.supportedLocales,+ home: SubscriptionPageScaffold(+ onHelpTap: () {},+ body: StatefulBuilder(+ builder: (context, setState) => GestureDetector(+ onTap: () => setState(() {+ selections++;+ selected = true;+ }),+ child: SubscriptionPlanWidget(+ storage: 10 * 1073741824,+ price: "",+ period: "month",+ isActive: selected,+ ),+ ),+ ),+ actions: [+ SubscriptionContinueButton(+ label: "Continue with 10 GB plan",+ onTap: () => continues++,+ ),+ ],+ ),+ ),+ );+ await tester.pumpAndSettle();+ expect(find.text("Continue with 10 GB plan"), findsOneWidget);++ await _tapAllowanceText(tester, "Locker");+ await tester.pumpAndSettle();+ expect(selected, isTrue);+ expect(selections, 1);+ expect(find.byType(SubscriptionLockerSheet), findsNothing);++ await _tapAllowanceText(tester, "+ 100 items on ");+ await tester.pumpAndSettle();+ expect(selections, 2);+ expect(find.byType(SubscriptionLockerSheet), findsNothing);++ await _tapAllowanceText(tester, "Locker");+ await tester.pumpAndSettle();+ expect(find.byType(SubscriptionLockerSheet), findsOneWidget);+ expect(selections, 2);++ await tester.tap(find.byTooltip("Close"));+ await tester.pumpAndSettle();+ expect(find.byType(SubscriptionLockerSheet), findsNothing);++ tester.platformDispatcher.textScaleFactorTestValue = 3;+ await tester.pumpAndSettle();+ expect(find.text("Continue"), findsOneWidget);+ await tester.tap(find.text("Continue"));+ await tester.pumpAndSettle();+ expect(continues, 1);+ });+}++Future<void> _tapAllowanceText(WidgetTester tester, String text) async {+ final finder = find.descendant(+ of: find.text("+ 100 items on Locker"),+ matching: find.byType(RichText),+ );+ final paragraph = tester.renderObject<RenderParagraph>(finder);+ final start = paragraph.text.toPlainText().indexOf(text);+ final box = paragraph+ .getBoxesForSelection(+ TextSelection(baseOffset: start, extentOffset: start + text.length),+ )+ .single;+ await tester.tapAt(tester.getTopLeft(finder) + box.toRect().center);+}diff --git a/mobile/apps/photos/test/ui/payment/subscription_toggle_test.dart b/mobile/apps/photos/test/ui/payment/subscription_toggle_test.dartindex 750ee4b970..5ffdde550a 100644--- a/mobile/apps/photos/test/ui/payment/subscription_toggle_test.dart+++ b/mobile/apps/photos/test/ui/payment/subscription_toggle_test.dart@@ -25,7 +25,7 @@ void main() {final toggleAlignment = tester.widget<AnimatedAlign>(find.byType(AnimatedAlign),);- expect(toggleAlignment.alignment, Alignment.centerLeft);+ expect(toggleAlignment.alignment, Alignment.centerRight);});});}