Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Revamp referral UI and code edit flow

Neeraj Guptab02b7ba5b18c
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arb
index d697d72837..d52c5b52c8 100644
--- a/mobile/apps/photos/lib/l10n/intl_en.arb
+++ b/mobile/apps/photos/lib/l10n/intl_en.arb
@@ -308,8 +308,10 @@
"failedToApplyCode": "Failed to apply code",
"enterReferralCode": "Enter referral code",
"codeAppliedPageTitle": "Code applied",
- "changeYourReferralCode": "Change your referral code",
+ "changeYourReferralCode": "Change your code",
"change": "Change",
+ "saveCode": "Save code",
+ "referralCodeHint": "You can customise this code up to 3 times",
"unavailableReferralCode": "Sorry, this code is unavailable.",
"codeChangeLimitReached": "Sorry, you've reached the limit of code changes.",
"onlyFamilyAdminCanChangeCode": "Please contact {familyAdminEmail} to change your code.",
@@ -325,12 +327,16 @@
"shareTextReferralCode": "Ente referral code: {referralCode} \n\nApply it in Settings β†’ General β†’ Referrals to get {referralStorageInGB} GB free after you signup for a paid plan\n\nhttps://ente.io",
"claimFreeStorage": "Claim free storage",
"inviteYourFriends": "Invite your friends",
+ "earnFreeStorage": "Earn free storage",
+ "shareCodeEarnStorage": "Share your code, earn storage.",
+ "youBothGet": "You both get",
+ "free": "free",
"failedToFetchReferralDetails": "Unable to fetch referral details. Please try again later.",
- "referralStep1": "1. Give this code to your friends",
+ "referralStep1": "1. Customise and share your code with your friends.",
"referralStep2": "2. They sign up for a paid plan",
"referralStep3": "3. Both of you get {storageInGB} GB* free",
"referralsAreCurrentlyPaused": "Referrals are currently paused",
- "youCanAtMaxDoubleYourStorage": "* You can at max double your storage",
+ "youCanAtMaxDoubleYourStorage": "You can max double your storage",
"claimedStorageSoFar": "{isFamilyMember, select, true {Your family has claimed {storageAmountInGb} GB so far} false {You have claimed {storageAmountInGb} GB so far} other {You have claimed {storageAmountInGb} GB so far!}}",
"@claimedStorageSoFar": {
"placeholders": {
@@ -354,6 +360,12 @@
"freeStorageClaimed": "Free storage claimed",
"freeStorageUsable": "Free storage usable",
"usableReferralStorageInfo": "Usable storage is limited by your current plan. Excess claimed storage will automatically become usable when you upgrade your plan.",
+ "referralStats": "Referral stats",
+ "usedYourCode": "used your code",
+ "claimedByYou": "claimed by you",
+ "earned": "earned",
+ "usable": "usable",
+ "referralStorageInfo": "Referrals from paid subscribers earn bonus storage.\n\nYou can use storage up to your plan limit. Upgrade to use the rest of your earned storage.",
"removeFromAlbumTitle": "Remove from album?",
"removeFromAlbum": "Remove from album",
"itemsWillBeRemovedFromAlbum": "Selected items will be removed from this album",
diff --git a/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart b/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart
new file mode 100644
index 0000000000..a29681d40b
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/components/base_bottom_sheet.dart
@@ -0,0 +1,120 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+
+Future<T?> showBaseBottomSheet<T>(
+ BuildContext context, {
+ required String title,
+ required Widget child,
+ bool showCloseButton = true,
+ VoidCallback? onClose,
+ double headerSpacing = 20,
+ Color? backgroundColor,
+ CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.start,
+ EdgeInsets padding = const EdgeInsets.fromLTRB(24, 20, 24, 24),
+ bool isDismissible = true,
+ bool enableDrag = true,
+ bool isKeyboardAware = true,
+}) {
+ return showModalBottomSheet<T>(
+ context: context,
+ isScrollControlled: true,
+ backgroundColor: Colors.transparent,
+ isDismissible: isDismissible,
+ enableDrag: enableDrag,
+ builder: (context) => BaseBottomSheet(
+ title: title,
+ showCloseButton: showCloseButton,
+ onClose: onClose,
+ headerSpacing: headerSpacing,
+ backgroundColor: backgroundColor,
+ crossAxisAlignment: crossAxisAlignment,
+ padding: padding,
+ isKeyboardAware: isKeyboardAware,
+ child: child,
+ ),
+ );
+}
+
+class BaseBottomSheet extends StatelessWidget {
+ final Widget child;
+ final String title;
+ final bool showCloseButton;
+ final VoidCallback? onClose;
+ final CrossAxisAlignment crossAxisAlignment;
+ final EdgeInsets padding;
+ final Color? backgroundColor;
+ final double headerSpacing;
+ final bool isKeyboardAware;
+
+ const BaseBottomSheet({
+ required this.child,
+ required this.title,
+ this.showCloseButton = true,
+ this.onClose,
+ this.crossAxisAlignment = CrossAxisAlignment.start,
+ this.padding = const EdgeInsets.fromLTRB(24, 20, 24, 24),
+ this.backgroundColor,
+ this.headerSpacing = 20,
+ this.isKeyboardAware = true,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final bottomInset =
+ isKeyboardAware ? MediaQuery.of(context).viewInsets.bottom : 0.0;
+
+ return Container(
+ decoration: BoxDecoration(
+ color: backgroundColor ?? colorScheme.backgroundElevated2,
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(20),
+ topRight: Radius.circular(20),
+ ),
+ ),
+ child: Padding(
+ padding: EdgeInsets.only(bottom: bottomInset),
+ child: SafeArea(
+ top: false,
+ child: Padding(
+ padding: padding,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: crossAxisAlignment,
+ children: [
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ Text(title, style: textTheme.largeBold),
+ if (showCloseButton)
+ GestureDetector(
+ onTap: onClose ?? () => Navigator.of(context).pop(),
+ child: Container(
+ padding: const EdgeInsets.all(8),
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: colorScheme.fillFaint,
+ ),
+ child: Icon(
+ Icons.close,
+ size: 24,
+ color: colorScheme.textBase,
+ ),
+ ),
+ )
+ else
+ const SizedBox.shrink(),
+ ],
+ ),
+ SizedBox(height: headerSpacing),
+ child,
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dart b/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dart
new file mode 100644
index 0000000000..d3ad2fb95c
--- /dev/null
+++ b/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dart
@@ -0,0 +1,201 @@
+import "package:dio/dio.dart";
+import "package:flutter/material.dart";
+import "package:logging/logging.dart";
+import "package:photos/generated/l10n.dart";
+import "package:photos/service_locator.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/components/base_bottom_sheet.dart";
+import "package:photos/utils/dialog_util.dart";
+
+Future<bool?> showChangeReferralCodeSheet(
+ BuildContext context, {
+ required String currentCode,
+ required VoidCallback onCodeChanged,
+}) {
+ return showBaseBottomSheet<bool>(
+ context,
+ title: AppLocalizations.of(context).changeYourReferralCode,
+ headerSpacing: 20,
+ child: _ChangeReferralCodeContent(
+ currentCode: currentCode,
+ onCodeChanged: onCodeChanged,
+ ),
+ );
+}
+
+class _ChangeReferralCodeContent extends StatefulWidget {
+ final String currentCode;
+ final VoidCallback onCodeChanged;
+
+ const _ChangeReferralCodeContent({
+ required this.currentCode,
+ required this.onCodeChanged,
+ });
+
+ @override
+ State<_ChangeReferralCodeContent> createState() =>
+ _ChangeReferralCodeContentState();
+}
+
+class _ChangeReferralCodeContentState
+ extends State<_ChangeReferralCodeContent> {
+ late TextEditingController _controller;
+ bool _isLoading = false;
+ String? _errorMessage;
+
+ @override
+ void initState() {
+ super.initState();
+ _controller = TextEditingController(text: widget.currentCode);
+ _controller.addListener(_onTextChanged);
+ }
+
+ @override
+ void dispose() {
+ _controller.removeListener(_onTextChanged);
+ _controller.dispose();
+ super.dispose();
+ }
+
+ void _onTextChanged() {
+ setState(() {
+ _errorMessage = null;
+ });
+ }
+
+ bool get _hasChanges =>
+ _controller.text.trim().isNotEmpty &&
+ _controller.text.trim() != widget.currentCode;
+
+ Future<void> _saveCode() async {
+ final newCode = _controller.text.trim();
+ if (newCode.isEmpty || newCode == widget.currentCode) {
+ return;
+ }
+
+ setState(() {
+ _isLoading = true;
+ _errorMessage = null;
+ });
+
+ try {
+ await storageBonusService.updateCode(newCode);
+ widget.onCodeChanged();
+ if (mounted) {
+ Navigator.of(context).pop(true);
+ }
+ } catch (e, s) {
+ Logger("ChangeReferralCodeSheet").severe("Failed to update code", e, s);
+ if (e is DioException) {
+ if (e.response?.statusCode == 400) {
+ setState(() {
+ _errorMessage = AppLocalizations.of(context).unavailableReferralCode;
+ });
+ } else if (e.response?.statusCode == 429) {
+ setState(() {
+ _errorMessage = AppLocalizations.of(context).codeChangeLimitReached;
+ });
+ } else {
+ if (mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
+ }
+ } else {
+ if (mounted) {
+ await showGenericErrorDialog(context: context, error: e);
+ }
+ }
+ } finally {
+ if (mounted) {
+ setState(() {
+ _isLoading = false;
+ });
+ }
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;
+
+ final inputBackgroundColor =
+ isDarkMode ? const Color(0xFF1C1C1C) : const Color(0xFFFAFAFA);
+
+ const greenColor = Color(0xFF08C225);
+ const warningRedColor = Color(0xFFF63A3A);
+ final helperTextColor =
+ _errorMessage != null ? warningRedColor : colorScheme.textMuted;
+
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ // Text input field
+ Container(
+ decoration: BoxDecoration(
+ color: inputBackgroundColor,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ child: TextField(
+ controller: _controller,
+ textCapitalization: TextCapitalization.characters,
+ style: textTheme.body,
+ decoration: InputDecoration(
+ border: InputBorder.none,
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 20,
+ ),
+ hintText: AppLocalizations.of(context).enterCode,
+ hintStyle: textTheme.body.copyWith(color: colorScheme.textMuted),
+ ),
+ ),
+ ),
+ const SizedBox(height: 9),
+ // Warning/helper text
+ Text(
+ _errorMessage ?? AppLocalizations.of(context).referralCodeHint,
+ style: textTheme.mini.copyWith(
+ color: helperTextColor,
+ ),
+ ),
+ const SizedBox(height: 20),
+ // Save button
+ SizedBox(
+ width: double.infinity,
+ height: 56,
+ child: ElevatedButton(
+ onPressed: _isLoading || !_hasChanges ? null : _saveCode,
+ style: ElevatedButton.styleFrom(
+ backgroundColor: _hasChanges ? greenColor : colorScheme.fillMuted,
+ foregroundColor: Colors.white,
+ disabledBackgroundColor: colorScheme.fillMuted,
+ disabledForegroundColor: colorScheme.textMuted,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(20),
+ ),
+ elevation: 0,
+ ),
+ child: _isLoading
+ ? SizedBox(
+ width: 24,
+ height: 24,
+ child: CircularProgressIndicator(
+ strokeWidth: 2,
+ color: colorScheme.textMuted,
+ ),
+ )
+ : Text(
+ AppLocalizations.of(context).saveCode,
+ style: textTheme.bodyBold.copyWith(
+ color: _hasChanges ? Colors.white : colorScheme.textMuted,
+ ),
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+}
diff --git a/mobile/apps/photos/lib/ui/growth/referral_code_widget.dart b/mobile/apps/photos/lib/ui/growth/referral_code_widget.dart
index 23979173cb..510558de07 100644
--- a/mobile/apps/photos/lib/ui/growth/referral_code_widget.dart
+++ b/mobile/apps/photos/lib/ui/growth/referral_code_widget.dart
@@ -1,14 +1,12 @@
-import "package:dio/dio.dart";
import "package:dotted_border/dotted_border.dart";
import "package:flutter/material.dart";
-import "package:logging/logging.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/user_details.dart";
-import "package:photos/service_locator.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/growth/change_referral_code_sheet.dart";
import "package:photos/utils/dialog_util.dart";
-// Figma: https://www.figma.com/file/SYtMyLBs5SAOkTbfMMzhqt/ente-Visual-Design?node-id=11219%3A62974&t=BRCLJhxXP11Q3Wyw-0
class ReferralCodeWidget extends StatelessWidget {
final String codeValue;
final bool shouldShowEdit;
@@ -25,115 +23,95 @@ class ReferralCodeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textStyle = getEnteTextTheme(context);
- return Center(
- child: Container(
- color: colorScheme.backgroundElevated2,
- child: DottedBorder(
- color: colorScheme.strokeMuted,
- strokeWidth: 1,
- dashPattern: const [6, 6],
- radius: const Radius.circular(8),
- child: Padding(
- padding: const EdgeInsets.only(
- left: 26.0,
- top: 14,
- right: 12,
- bottom: 14,
+ final textTheme = getEnteTextTheme(context);
+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;
+
+ const greenColor = Color(0xFF08C225);
+ final cardColor =
+ isDarkMode ? const Color(0xFF212121) : const Color(0xFFFFFFFF);
+
+ // The edit button is 24px (6px padding + 12px icon + 6px padding)
+ // Plus 12px tap padding on each side = 48px total tap area
+ // We need extra space at bottom-right for the overlapping button
+ const editButtonSize = 24.0;
+ const tapPadding = 12.0;
+ const overlapAmount = editButtonSize / 2; // How much it overlaps the box
+
+ return Stack(
+ clipBehavior: Clip.none,
+ children: [
+ // Add padding to the code box to make room for the edit button in layout
+ Padding(
+ padding: EdgeInsets.only(
+ bottom: shouldShowEdit ? overlapAmount + tapPadding : 0,
+ right: shouldShowEdit ? overlapAmount + tapPadding : 0,
+ ),
+ child: DottedBorder(
+ color: greenColor,
+ strokeWidth: 1,
+ dashPattern: const [6, 6],
+ borderType: BorderType.RRect,
+ radius: const Radius.circular(16),
+ child: Container(
+ decoration: BoxDecoration(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(16),
+ ),
+ padding: const EdgeInsets.symmetric(horizontal: 36, vertical: 20),
+ child: Text(
+ codeValue,
+ style: textTheme.small.copyWith(color: greenColor),
+ ),
),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- codeValue,
- style: textStyle.bodyBold.copyWith(
- color: colorScheme.primary700,
+ ),
+ ),
+ if (shouldShowEdit)
+ Positioned(
+ right: 0,
+ bottom: 0,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ if (userDetails!.isPartOfFamily() &&
+ !userDetails!.isFamilyAdmin()) {
+ final String familyAdmin = userDetails!.familyData!.members!
+ .firstWhere((element) => element.isAdmin)
+ .email;
+ showInfoDialog(
+ context,
+ title: AppLocalizations.of(context).error,
+ body:
+ AppLocalizations.of(context).onlyFamilyAdminCanChangeCode(
+ familyAdminEmail: familyAdmin,
+ ),
+ icon: Icons.error,
+ );
+ } else {
+ showChangeReferralCodeSheet(
+ context,
+ currentCode: codeValue,
+ onCodeChanged: () => notifyParent?.call(),
+ );
+ }
+ },
+ child: Padding(
+ padding: const EdgeInsets.all(tapPadding),
+ child: Container(
+ decoration: const BoxDecoration(
+ color: greenColor,
+ shape: BoxShape.circle,
+ ),
+ padding: const EdgeInsets.all(6),
+ child: const HugeIcon(
+ icon: HugeIcons.strokeRoundedEdit03,
+ color: Colors.white,
+ size: 12,
),
),
- const SizedBox(width: 12),
- shouldShowEdit
- ? GestureDetector(
- onTap: () {
- if (userDetails!.isPartOfFamily() &&
- !userDetails!.isFamilyAdmin()) {
- final String familyAdmin = userDetails!
- .familyData!.members!
- .firstWhere((element) => element.isAdmin)
- .email;
- showInfoDialog(
- context,
- title: AppLocalizations.of(context).error,
- body: AppLocalizations.of(context)
- .onlyFamilyAdminCanChangeCode(
- familyAdminEmail: familyAdmin,
- ),
- icon: Icons.error,
- );
- } else {
- showUpdateReferralCodeDialog(context);
- }
- },
- child: Icon(
- Icons.edit,
- size: 22,
- color: colorScheme.strokeMuted,
- ),
- )
- : const SizedBox.shrink(),
- ],
+ ),
),
),
- ),
- ),
- );
- }
-
- Future<void> showUpdateReferralCodeDialog(BuildContext context) async {
- final result = await showTextInputDialog(
- context,
- title: AppLocalizations.of(context).changeYourReferralCode,
- submitButtonLabel: AppLocalizations.of(context).change,
- hintText: AppLocalizations.of(context).enterCode,
- alwaysShowSuccessState: true,
- initialValue: codeValue,
- textCapitalization: TextCapitalization.characters,
- onSubmit: (String text) async {
- // indicates user cancelled the request
- if (text == "" || text.trim() == codeValue) {
- return;
- }
-
- try {
- await storageBonusService.updateCode(text);
- notifyParent?.call();
- } catch (e, s) {
- Logger("ReferralCodeWidget").severe("Failed to update code", e, s);
- if (e is DioException) {
- if (e.response?.statusCode == 400) {
- await showInfoDialog(
- context,
- title: AppLocalizations.of(context).error,
- body: AppLocalizations.of(context).unavailableReferralCode,
- icon: Icons.error,
- );
- return;
- } else if (e.response?.statusCode == 429) {
- await showInfoDialog(
- context,
- title: AppLocalizations.of(context).error,
- body: AppLocalizations.of(context).codeChangeLimitReached,
- icon: Icons.error,
- );
- return;
- }
- }
- rethrow;
- }
- },
+ ],
);
- if (result is Exception) {
- await showGenericErrorDialog(context: context, error: result);
- }
}
}
diff --git a/mobile/apps/photos/lib/ui/growth/referral_screen.dart b/mobile/apps/photos/lib/ui/growth/referral_screen.dart
index 211905c794..5d2d33b79f 100644
--- a/mobile/apps/photos/lib/ui/growth/referral_screen.dart
+++ b/mobile/apps/photos/lib/ui/growth/referral_screen.dart
@@ -1,19 +1,16 @@
import "package:ente_pure_utils/ente_pure_utils.dart";
import "package:flutter/material.dart";
+import "package:hugeicons/hugeicons.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/api/storage_bonus/storage_bonus.dart";
import "package:photos/models/user_details.dart";
import "package:photos/service_locator.dart";
import "package:photos/services/account/user_service.dart";
import "package:photos/theme/ente_theme.dart";
+import "package:photos/theme/text_style.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/common/web_page.dart";
-import 'package:photos/ui/components/buttons/icon_button_widget.dart';
-import "package:photos/ui/components/captioned_text_widget.dart";
-import "package:photos/ui/components/divider_widget.dart";
-import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";
-import "package:photos/ui/components/title_bar_title_widget.dart";
-import "package:photos/ui/components/title_bar_widget.dart";
+import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";
import "package:photos/ui/growth/apply_code_screen.dart";
import "package:photos/ui/growth/referral_code_widget.dart";
import "package:photos/ui/growth/storage_details_screen.dart";
@@ -47,68 +44,54 @@ class _ReferralScreenState extends State<ReferralScreen> {
@override
Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;
+
+ final pageBackgroundColor =
+ isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
+
return Scaffold(
- body: CustomScrollView(
- primary: false,
- slivers: <Widget>[
- TitleBarWidget(
- flexibleSpaceTitle: TitleBarTitleWidget(
- title: AppLocalizations.of(context).claimFreeStorage,
- ),
- flexibleSpaceCaption:
- AppLocalizations.of(context).inviteYourFriends,
- actionIcons: [
- IconButtonWidget(
- icon: Icons.close_outlined,
- iconButtonType: IconButtonType.secondary,
- onTap: () {
- if (Navigator.canPop(context)) {
- Navigator.pop(context);
- }
- if (Navigator.canPop(context)) {
- Navigator.pop(context);
- }
- },
- ),
- ],
- ),
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (delegateBuildContext, index) {
- return Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 16, vertical: 20),
- child: FutureBuilder<Tuple2<ReferralView, UserDetails>>(
- future: _fetchData(),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- return ReferralWidget(
- referralView: snapshot.data!.item1,
- userDetails: snapshot.data!.item2,
- notifyParent: _safeUIUpdate,
- );
- } else if (snapshot.hasError) {
- return Center(
- child: Padding(
- padding: const EdgeInsets.all(24.0),
- child: Text(
- AppLocalizations.of(context)
- .failedToFetchReferralDetails,
- ),
- ),
- );
- }
- {
- return const EnteLoadingWidget();
- }
- },
- ),
- );
- },
- childCount: 1,
- ),
- ),
- ],
+ backgroundColor: pageBackgroundColor,
+ body: SafeArea(
+ child: FutureBuilder<Tuple2<ReferralView, UserDetails>>(
+ future: _fetchData(),
+ builder: (context, snapshot) {
+ if (snapshot.hasData) {
+ return ReferralWidget(
+ referralView: snapshot.data!.item1,
+ userDetails: snapshot.data!.item2,
+ notifyParent: _safeUIUpdate,
+ );
+ } else if (snapshot.hasError) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Icon(
+ Icons.arrow_back,
+ color: colorScheme.strokeBase,
+ size: 24,
+ ),
+ ),
+ Expanded(
+ child: Center(
+ child: Text(
+ AppLocalizations.of(context)
+ .failedToFetchReferralDetails,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+ return const Center(child: EnteLoadingWidget());
+ },
+ ),
),
);
}
@@ -129,77 +112,93 @@ class ReferralWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
- final textStyle = getEnteTextTheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;
final bool isReferralEnabled = referralView.planInfo.isEnabled;
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // Container with 8 border radius and red color
- isReferralEnabled
- ? InkWell(
- onTap: () {
- shareText(
- AppLocalizations.of(context).shareTextReferralCode(
- referralCode: referralView.code,
- referralStorageInGB: referralView.planInfo.storageInGB,
- ),
- );
- },
- child: Stack(
- children: [
- Container(
- width: double.infinity,
- decoration: BoxDecoration(
- border: Border.all(
- color: colorScheme.strokeFaint,
- width: 1,
- ),
- borderRadius: BorderRadius.circular(8),
+
+ final cardColor =
+ isDarkMode ? const Color(0xFF212121) : const Color(0xFFFFFFFF);
+
+ return SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ // Back arrow
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Icon(
+ Icons.arrow_back,
+ color: colorScheme.strokeBase,
+ size: 24,
+ ),
+ ),
+ const SizedBox(height: 24),
+ // Header section with title and share button
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ AppLocalizations.of(context).earnFreeStorage,
+ style: textTheme.largeBold,
),
- child: Padding(
- padding: const EdgeInsets.symmetric(
- vertical: 12,
- horizontal: 12,
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- AppLocalizations.of(context).referralStep1,
- ),
- const SizedBox(height: 12),
- ReferralCodeWidget(
- referralView.code,
- shouldShowEdit: true,
- userDetails: userDetails,
- notifyParent: notifyParent,
- ),
- const SizedBox(height: 12),
- Text(
- AppLocalizations.of(context).referralStep2,
- ),
- const SizedBox(height: 12),
- Text(
- AppLocalizations.of(context).referralStep3(
- storageInGB: referralView.planInfo.storageInGB,
- ),
- ),
- ],
+ const SizedBox(height: 8),
+ Text(
+ AppLocalizations.of(context).shareCodeEarnStorage,
+ style: textTheme.miniMuted,
+ ),
+ ],
+ ),
+ ),
+ if (isReferralEnabled)
+ GestureDetector(
+ onTap: () {
+ shareText(
+ AppLocalizations.of(context).shareTextReferralCode(
+ referralCode: referralView.code,
+ referralStorageInGB:
+ referralView.planInfo.storageInGB,
),
+ );
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(8),
),
- ),
- Positioned(
- right: 8,
- top: 8,
- child: Icon(
- Icons.adaptive.share,
- color: colorScheme.blurStrokePressed,
+ padding: const EdgeInsets.all(8),
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedShare08,
+ color: colorScheme.strokeBase,
+ size: 20,
),
),
- ],
+ ),
+ ],
+ ),
+ const SizedBox(height: 42),
+ // Referral code section
+ if (isReferralEnabled) ...[
+ Center(
+ child: ReferralCodeWidget(
+ referralView.code,
+ shouldShowEdit: true,
+ userDetails: userDetails,
+ notifyParent: notifyParent,
),
- )
- : Padding(
+ ),
+ const SizedBox(height: 16),
+ // Instructions
+ _buildInstructions(context, textTheme),
+ const SizedBox(height: 16),
+ ] else ...[
+ Padding(
padding: const EdgeInsets.symmetric(vertical: 48),
child: Center(
child: Column(
@@ -211,39 +210,21 @@ class ReferralWidget extends StatelessWidget {
),
const SizedBox(height: 12),
Text(
- AppLocalizations.of(context)
- .referralsAreCurrentlyPaused,
- style: textStyle.small
- .copyWith(color: colorScheme.textFaint),
+ AppLocalizations.of(context).referralsAreCurrentlyPaused,
+ style:
+ textTheme.small.copyWith(color: colorScheme.textFaint),
),
],
),
),
),
- const SizedBox(height: 4),
- isReferralEnabled
- ? Text(
- AppLocalizations.of(context).youCanAtMaxDoubleYourStorage,
- style: textStyle.mini.copyWith(
- color: colorScheme.textMuted,
- ),
- textAlign: TextAlign.left,
- )
- : const SizedBox.shrink(),
- const SizedBox(height: 24),
- referralView.enableApplyCode
- ? MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: AppLocalizations.of(context).applyCodeTitle,
- ),
- menuItemColor: colorScheme.fillFaint,
- trailingWidget: Icon(
- Icons.chevron_right_outlined,
- color: colorScheme.strokeBase,
- ),
- singleBorderRadius: 8,
- alignCaptionedTextToLeft: true,
- isBottomBorderRadiusRemoved: true,
+ ],
+ // Menu items
+ if (referralView.enableApplyCode) ...[
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).applyCodeTitle,
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
onTap: () async {
await routeToPage(
context,
@@ -251,73 +232,75 @@ class ReferralWidget extends StatelessWidget {
);
notifyParent();
},
- )
- : const SizedBox.shrink(),
- referralView.enableApplyCode
- ? DividerWidget(
- dividerType: DividerType.menu,
- bgColor: colorScheme.fillFaint,
- )
- : const SizedBox.shrink(),
- MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: AppLocalizations.of(context).faq,
- ),
- menuItemColor: colorScheme.fillFaint,
- trailingWidget: Icon(
- Icons.chevron_right_outlined,
- color: colorScheme.strokeBase,
- ),
- singleBorderRadius: 8,
- isTopBorderRadiusRemoved: referralView.enableApplyCode,
- alignCaptionedTextToLeft: true,
- onTap: () async {
- // ignore: unawaited_futures
- routeToPage(
- context,
- WebPage(
- AppLocalizations.of(context).faq,
- "https://ente.io/help/photos/features/account/referral-program/",
),
- );
- },
- ),
- const SizedBox(height: 24),
- Padding(
- padding: const EdgeInsets.symmetric(
- horizontal: 8.0,
- vertical: 6.0,
- ),
- child: Text(
- AppLocalizations.of(context).claimedStorageSoFar(
- isFamilyMember:
- referralView.isFamilyMember.toString().toLowerCase(),
- storageAmountInGb:
- convertBytesToAbsoluteGBs(referralView.claimedStorage),
+ const SizedBox(height: 8),
+ ],
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).faq,
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ onTap: () async {
+ await routeToPage(
+ context,
+ WebPage(
+ AppLocalizations.of(context).faq,
+ "https://ente.io/help/photos/features/account/referral-program/",
+ ),
+ );
+ },
),
- style: textStyle.small.copyWith(
- color: colorScheme.textMuted,
+ const SizedBox(height: 8),
+ MenuItemWidgetNew(
+ title: AppLocalizations.of(context).details,
+ trailingIcon: Icons.chevron_right_outlined,
+ trailingIconIsMuted: true,
+ onTap: () async {
+ await routeToPage(
+ context,
+ StorageDetailsScreen(referralView, userDetails),
+ );
+ },
),
- ),
+ const SizedBox(height: 60),
+ ],
),
- MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: AppLocalizations.of(context).details,
- ),
- menuItemColor: colorScheme.fillFaint,
- trailingWidget: Icon(
- Icons.chevron_right_outlined,
- color: colorScheme.strokeBase,
+ ),
+ );
+ }
+
+ Widget _buildInstructions(BuildContext context, EnteTextTheme textTheme) {
+ const greenColor = Color(0xFF08C225);
+ final storageInGB = referralView.planInfo.storageInGB;
+ final mutedStyle = textTheme.miniMuted.copyWith(height: 2);
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ AppLocalizations.of(context).referralStep1,
+ style: mutedStyle,
+ ),
+ Text(
+ AppLocalizations.of(context).referralStep2,
+ style: mutedStyle,
+ ),
+ RichText(
+ text: TextSpan(
+ style: mutedStyle,
+ children: [
+ TextSpan(
+ text: "3. ${AppLocalizations.of(context).youBothGet} ",
+ ),
+ TextSpan(
+ text: "${storageInGB}GB ${AppLocalizations.of(context).free}",
+ style: const TextStyle(color: greenColor),
+ ),
+ TextSpan(
+ text:
+ ". (${AppLocalizations.of(context).youCanAtMaxDoubleYourStorage})",
+ ),
+ ],
),
- singleBorderRadius: 8,
- alignCaptionedTextToLeft: true,
- onTap: () async {
- // ignore: unawaited_futures
- routeToPage(
- context,
- StorageDetailsScreen(referralView, userDetails),
- );
- },
),
],
);
diff --git a/mobile/apps/photos/lib/ui/growth/storage_details_screen.dart b/mobile/apps/photos/lib/ui/growth/storage_details_screen.dart
index feedb3fc8f..0dd9fd30d1 100644
--- a/mobile/apps/photos/lib/ui/growth/storage_details_screen.dart
+++ b/mobile/apps/photos/lib/ui/growth/storage_details_screen.dart
@@ -8,9 +8,6 @@ import "package:photos/models/user_details.dart";
import "package:photos/service_locator.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
-import 'package:photos/ui/components/buttons/icon_button_widget.dart';
-import "package:photos/ui/components/title_bar_title_widget.dart";
-import "package:photos/ui/components/title_bar_widget.dart";
class StorageDetailsScreen extends StatefulWidget {
final ReferralView referralView;
@@ -23,208 +20,221 @@ class StorageDetailsScreen extends StatefulWidget {
}
class _StorageDetailsScreenState extends State<StorageDetailsScreen> {
- bool canApplyCode = true;
-
- @override
- void initState() {
- super.initState();
- }
-
@override
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
- final textStyle = getEnteTextTheme(context);
+ final textTheme = getEnteTextTheme(context);
+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;
+
+ final pageBackgroundColor =
+ isDarkMode ? const Color(0xFF161616) : const Color(0xFFFAFAFA);
+ final cardColor =
+ isDarkMode ? const Color(0xFF212121) : const Color(0xFFFFFFFF);
+
return Scaffold(
- body: CustomScrollView(
- primary: false,
- slivers: <Widget>[
- TitleBarWidget(
- flexibleSpaceTitle: TitleBarTitleWidget(
- title: AppLocalizations.of(context).claimFreeStorage,
- ),
- flexibleSpaceCaption: AppLocalizations.of(context).details,
- actionIcons: [
- IconButtonWidget(
- icon: Icons.close_outlined,
- iconButtonType: IconButtonType.secondary,
- onTap: () {
- Navigator.of(context)
- ..pop()
- ..pop()
- ..pop();
- },
- ),
- ],
- ),
- SliverList(
- delegate: SliverChildBuilderDelegate(
- (delegateBuildContext, index) {
- return Padding(
- padding: const EdgeInsets.symmetric(horizontal: 12),
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 20),
- // wrap the child inside a FutureBuilder to get the
- // current state of the TextField
- child: FutureBuilder<BonusDetails>(
- future: storageBonusService.getBonusDetails(),
- builder: (context, snapshot) {
- if (snapshot.connectionState ==
- ConnectionState.waiting) {
- return const Center(
- child: Padding(
- padding: EdgeInsets.only(top: 48.0),
- child: EnteLoadingWidget(),
+ backgroundColor: pageBackgroundColor,
+ body: SafeArea(
+ child: FutureBuilder<BonusDetails>(
+ future: storageBonusService.getBonusDetails(),
+ builder: (context, snapshot) {
+ if (snapshot.connectionState == ConnectionState.waiting) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Icon(
+ Icons.arrow_back,
+ color: colorScheme.strokeBase,
+ size: 24,
+ ),
+ ),
+ const Expanded(
+ child: Center(child: EnteLoadingWidget()),
+ ),
+ ],
+ ),
+ );
+ }
+
+ if (snapshot.hasError) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Icon(
+ Icons.arrow_back,
+ color: colorScheme.strokeBase,
+ size: 24,
+ ),
+ ),
+ Expanded(
+ child: Center(
+ child: Text(
+ AppLocalizations.of(context).oopsSomethingWentWrong,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ final BonusDetails data = snapshot.data!;
+
+ return SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ // Back arrow
+ GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Icon(
+ Icons.arrow_back,
+ color: colorScheme.strokeBase,
+ size: 24,
+ ),
+ ),
+ const SizedBox(height: 24),
+ // Title
+ Text(
+ AppLocalizations.of(context).referralStats,
+ style: textTheme.largeBold,
+ ),
+ const SizedBox(height: 24),
+ // Stats cards
+ Column(
+ children: [
+ // Row 1: Used your code + Eligible
+ Row(
+ children: [
+ Expanded(
+ child: _StatCard(
+ value: data.refCount.toString(),
+ label: AppLocalizations.of(context)
+ .usedYourCode,
+ cardColor: cardColor,
+ ),
),
- );
- }
- if (snapshot.hasError) {
- debugPrint(snapshot.error.toString());
- return Text(
- AppLocalizations.of(context).oopsSomethingWentWrong,
- );
- } else {
- final BonusDetails data = snapshot.data!;
- return Padding(
- padding:
- const EdgeInsets.symmetric(horizontal: 12.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- BonusInfoSection(
- sectionName: AppLocalizations.of(context)
- .peopleUsingYourCode,
- leftValue: data.refUpgradeCount,
- leftUnitName:
- AppLocalizations.of(context).eligible,
- rightValue: data.refUpgradeCount >= 0
- ? data.refCount
- : null,
- rightUnitName:
- AppLocalizations.of(context).total,
- showUnit: data.refCount > 0,
- ),
- data.hasAppliedCode
- ? BonusInfoSection(
- sectionName:
- AppLocalizations.of(context)
- .codeUsedByYou,
- leftValue: 1,
- showUnit: false,
- )
- : const SizedBox.shrink(),
- BonusInfoSection(
- sectionName: AppLocalizations.of(context)
- .freeStorageClaimed,
- leftValue: convertBytesToAbsoluteGBs(
- widget.referralView.claimedStorage,
- ),
- leftUnitName: "GB",
- rightValue: null,
- ),
- BonusInfoSection(
- sectionName: AppLocalizations.of(context)
- .freeStorageUsable,
- leftValue: convertBytesToAbsoluteGBs(
- min(
- widget.referralView.claimedStorage,
- widget.userDetails
- .getPlanPlusAddonStorage(),
- ),
- ),
- leftUnitName: "GB",
- rightValue: convertBytesToAbsoluteGBs(
- widget.userDetails
- .getPlanPlusAddonStorage(),
- ),
- rightUnitName: "GB",
- ),
- const SizedBox(
- height: 24,
- ),
- Text(
- AppLocalizations.of(context)
- .usableReferralStorageInfo,
- style: textStyle.small
- .copyWith(color: colorScheme.textMuted),
+ const SizedBox(width: 16),
+ Expanded(
+ child: _StatCard(
+ value: data.refUpgradeCount.toString(),
+ label:
+ AppLocalizations.of(context).eligible,
+ cardColor: cardColor,
+ ),
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ // Row 2: Claimed by you (only if has applied code)
+ if (data.hasAppliedCode) ...[
+ Row(
+ children: [
+ Expanded(
+ child: _StatCard(
+ value: "1",
+ label: AppLocalizations.of(context)
+ .claimedByYou,
+ cardColor: cardColor,
),
- ],
+ ),
+ ],
+ ),
+ const SizedBox(height: 16),
+ ],
+ // Row 3: Earned + Usable
+ Row(
+ children: [
+ Expanded(
+ child: _StatCard(
+ value:
+ "${convertBytesToAbsoluteGBs(widget.referralView.claimedStorage)} GB",
+ label: AppLocalizations.of(context).earned,
+ cardColor: cardColor,
+ ),
+ ),
+ const SizedBox(width: 16),
+ Expanded(
+ child: _StatCard(
+ value:
+ "${convertBytesToAbsoluteGBs(min(widget.referralView.claimedStorage, widget.userDetails.getPlanPlusAddonStorage()))} GB",
+ label: AppLocalizations.of(context).usable,
+ cardColor: cardColor,
+ ),
),
- );
- }
- },
+ ],
+ ),
+ ],
),
- ),
- );
- },
- childCount: 1,
- ),
- ),
- ],
+ const SizedBox(height: 24),
+ // Info text
+ Text(
+ AppLocalizations.of(context).referralStorageInfo,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ height: 1.5,
+ ),
+ ),
+ const SizedBox(height: 60),
+ ],
+ ),
+ ),
+ );
+ },
+ ),
),
);
}
}
-class BonusInfoSection extends StatelessWidget {
- final String sectionName;
- final bool showUnit;
- final String leftUnitName;
- final String rightUnitName;
- final int leftValue;
- final int? rightValue;
+class _StatCard extends StatelessWidget {
+ final String value;
+ final String label;
+ final Color cardColor;
- const BonusInfoSection({
- super.key,
- required this.sectionName,
- required this.leftValue,
- this.leftUnitName = "GB",
- this.rightValue,
- this.rightUnitName = "GB",
- this.showUnit = true,
+ const _StatCard({
+ required this.value,
+ required this.label,
+ required this.cardColor,
});
@override
Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textStyle = getEnteTextTheme(context);
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- sectionName,
- style: textStyle.body.copyWith(
- color: colorScheme.textMuted,
+ final textTheme = getEnteTextTheme(context);
+ const greenColor = Color(0xFF08C225);
+
+ return Container(
+ decoration: BoxDecoration(
+ color: cardColor,
+ borderRadius: BorderRadius.circular(20),
+ ),
+ padding: const EdgeInsets.all(16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ value,
+ style: textTheme.h3Bold.copyWith(color: greenColor),
),
- ),
- const SizedBox(height: 2),
- RichText(
- text: TextSpan(
- children: [
- TextSpan(
- text: leftValue.toString(),
- style: textStyle.h3,
- ),
- TextSpan(
- text: showUnit ? " $leftUnitName" : "",
- style: textStyle.large,
- ),
- TextSpan(
- text: (rightValue != null && rightValue! > 0)
- ? " / ${rightValue.toString()}"
- : "",
- style: textStyle.h3,
- ),
- TextSpan(
- text: showUnit && (rightValue != null && rightValue! > 0)
- ? " $rightUnitName"
- : "",
- style: textStyle.large,
- ),
- ],
+ const SizedBox(height: 4),
+ Text(
+ label,
+ style: textTheme.smallMuted,
),
- ),
- const SizedBox(height: 24),
- ],
+ ],
+ ),
);
}
}