Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] Redesign and change logic in SubscriptionPlanWidget to match new design

ashilkn3edc32327241
diff --git a/mobile/lib/ui/payment/subscription_plan_widget.dart b/mobile/lib/ui/payment/subscription_plan_widget.dart
index 00d8769fe8..a4e870d710 100644
--- a/mobile/lib/ui/payment/subscription_plan_widget.dart
+++ b/mobile/lib/ui/payment/subscription_plan_widget.dart
@@ -1,77 +1,137 @@
import 'package:flutter/material.dart';
import "package:photos/generated/l10n.dart";
+import "package:photos/theme/ente_theme.dart";
import 'package:photos/utils/data_util.dart';
class SubscriptionPlanWidget extends StatelessWidget {
const SubscriptionPlanWidget({
- Key? key,
+ super.key,
required this.storage,
required this.price,
required this.period,
this.isActive = false,
- }) : super(key: key);
+ });
final int storage;
final String price;
final String period;
final bool isActive;
- String _displayPrice(BuildContext context) {
- // todo: l10n pricing part
- final result = price + (period.isNotEmpty ? " / " + period : "");
- return price.isNotEmpty ? result : S.of(context).freeTrial;
+ @override
+ Widget build(BuildContext context) {
+ final numAndUnit = convertBytesToNumberAndUnit(storage);
+ final String storageValue = numAndUnit.$1.toString();
+ final String storageUnit = numAndUnit.$2;
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ RichText(
+ text: TextSpan(
+ children: [
+ TextSpan(
+ text: storageValue,
+ style: TextStyle(
+ fontSize: 40,
+ fontWeight: FontWeight.w600,
+ color: getEnteColorScheme(context).textBase,
+ ),
+ ),
+ WidgetSpan(
+ child: Transform.translate(
+ offset: const Offset(2, -16),
+ child: Text(
+ storageUnit,
+ style: getEnteTextTheme(context).h3Muted,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ _Price(price: price, period: period),
+ ],
+ );
}
+}
+
+class _Price extends StatelessWidget {
+ final String price;
+ final String period;
+ const _Price({required this.price, required this.period});
@override
Widget build(BuildContext context) {
- final Color textColor = isActive ? Colors.white : Colors.black;
- return Container(
- width: double.infinity,
- color: Theme.of(context).colorScheme.onPrimary,
- padding: EdgeInsets.symmetric(horizontal: isActive ? 8 : 16, vertical: 4),
- child: Container(
- decoration: BoxDecoration(
- color: isActive
- ? const Color(0xFF22763F)
- : const Color.fromRGBO(240, 240, 240, 1.0),
- gradient: isActive
- ? const LinearGradient(
- begin: Alignment.centerLeft,
- end: Alignment.centerRight,
- colors: [
- Color(0xFF2CD267),
- Color(0xFF1DB954),
- ],
- )
- : null,
+ final colorScheme = getEnteColorScheme(context);
+ if (price.isEmpty) {
+ return Text(S.of(context).freeTrial);
+ }
+ if (period == "month") {
+ return RichText(
+ text: TextSpan(
+ children: <TextSpan>[
+ TextSpan(
+ text: price,
+ style: TextStyle(
+ fontSize: 20,
+ color: colorScheme.textBase,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ TextSpan(
+ text: ' / ' 'month',
+ style: TextStyle(
+ fontSize: 16,
+ color: colorScheme.textBase,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ],
),
- // color: Colors.yellow,
- padding:
- EdgeInsets.symmetric(horizontal: isActive ? 22 : 20, vertical: 18),
- child: Column(
- children: [
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- convertBytesToReadableFormat(storage),
- style: Theme.of(context)
- .textTheme
- .titleLarge!
- .copyWith(color: textColor),
+ );
+ } else if (period == "year") {
+ final currencySymbol = price[0];
+ final priceWithoutCurrency = price.substring(1);
+ final priceDouble = double.parse(priceWithoutCurrency);
+ final pricePerMonth = priceDouble / 12;
+ final pricePerMonthString = pricePerMonth.toStringAsFixed(2);
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ RichText(
+ text: TextSpan(
+ children: <TextSpan>[
+ TextSpan(
+ text: currencySymbol + pricePerMonthString,
+ style: TextStyle(
+ fontSize: 20,
+ color: colorScheme.textBase,
+ fontWeight: FontWeight.w600,
+ ),
),
- Text(
- _displayPrice(context),
- style: Theme.of(context).textTheme.titleLarge!.copyWith(
- color: textColor,
- fontWeight: FontWeight.normal,
- ),
+ TextSpan(
+ text: ' / ' 'month',
+ style: TextStyle(
+ fontSize: 16,
+ color: colorScheme.textBase,
+ fontWeight: FontWeight.w600,
+ ),
),
],
),
- ],
- ),
- ),
- );
+ ),
+ Text(
+ price + " / " + "year",
+ style: TextStyle(
+ fontSize: 12,
+ color: colorScheme.textFaint,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ],
+ );
+ } else {
+ assert(false, "Invalid period: $period");
+ return const Text("");
+ }
}
}
diff --git a/mobile/lib/utils/data_util.dart b/mobile/lib/utils/data_util.dart
index 0f3feca736..48a0bbf79a 100644
--- a/mobile/lib/utils/data_util.dart
+++ b/mobile/lib/utils/data_util.dart
@@ -11,6 +11,15 @@ String convertBytesToReadableFormat(int bytes) {
return bytes.toString() + " " + storageUnits[storageUnitIndex];
}
+(int, String) convertBytesToNumberAndUnit(int bytes) {
+ int storageUnitIndex = 0;
+ while (bytes >= 1024 && storageUnitIndex < storageUnits.length - 1) {
+ storageUnitIndex++;
+ bytes = (bytes / 1024).round();
+ }
+ return (bytes, storageUnits[storageUnitIndex]);
+}
+
String formatBytes(int bytes, [int decimals = 2]) {
if (bytes == 0) return '0 bytes';
const k = 1024;