subscription_common_widgets.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/ente_theme_data.dart';
  3. import 'package:photos/models/subscription.dart';
  4. import "package:photos/theme/ente_theme.dart";
  5. import "package:photos/ui/components/captioned_text_widget.dart";
  6. import "package:photos/ui/components/menu_item_widget/menu_item_widget.dart";
  7. import 'package:photos/ui/payment/billing_questions_widget.dart';
  8. import 'package:photos/utils/data_util.dart';
  9. import 'package:photos/utils/date_time_util.dart';
  10. class SubscriptionHeaderWidget extends StatefulWidget {
  11. final bool? isOnboarding;
  12. final int? currentUsage;
  13. const SubscriptionHeaderWidget({
  14. Key? key,
  15. this.isOnboarding,
  16. this.currentUsage,
  17. }) : super(key: key);
  18. @override
  19. State<StatefulWidget> createState() {
  20. return _SubscriptionHeaderWidgetState();
  21. }
  22. }
  23. class _SubscriptionHeaderWidgetState extends State<SubscriptionHeaderWidget> {
  24. @override
  25. Widget build(BuildContext context) {
  26. if (widget.isOnboarding!) {
  27. return Padding(
  28. padding: const EdgeInsets.fromLTRB(20, 20, 20, 24),
  29. child: Column(
  30. crossAxisAlignment: CrossAxisAlignment.start,
  31. children: [
  32. Row(
  33. children: [
  34. Text(
  35. "Select your plan",
  36. style: Theme.of(context).textTheme.headline4,
  37. ),
  38. ],
  39. ),
  40. const SizedBox(height: 10),
  41. Text(
  42. "ente preserves your memories, so they're always available to you, even if you lose your device.",
  43. style: Theme.of(context).textTheme.caption,
  44. ),
  45. const SizedBox(height: 4),
  46. Text(
  47. "Your family can be added to your plan as well. ",
  48. style: Theme.of(context).textTheme.caption,
  49. ),
  50. ],
  51. ),
  52. );
  53. } else {
  54. return SizedBox(
  55. height: 72,
  56. width: double.infinity,
  57. child: Padding(
  58. padding: const EdgeInsets.all(24.0),
  59. child: RichText(
  60. text: TextSpan(
  61. children: [
  62. TextSpan(
  63. text: "Current usage is ",
  64. style: Theme.of(context).textTheme.subtitle1,
  65. ),
  66. TextSpan(
  67. text: formatBytes(widget.currentUsage!),
  68. style: Theme.of(context)
  69. .textTheme
  70. .subtitle1!
  71. .copyWith(fontWeight: FontWeight.bold),
  72. )
  73. ],
  74. ),
  75. ),
  76. ),
  77. );
  78. }
  79. }
  80. }
  81. class ValidityWidget extends StatelessWidget {
  82. final Subscription? currentSubscription;
  83. const ValidityWidget({Key? key, this.currentSubscription}) : super(key: key);
  84. @override
  85. Widget build(BuildContext context) {
  86. if (currentSubscription == null) {
  87. return const SizedBox.shrink();
  88. }
  89. final endDate = getDateAndMonthAndYear(
  90. DateTime.fromMicrosecondsSinceEpoch(currentSubscription!.expiryTime),
  91. );
  92. var message = "Renews on $endDate";
  93. if (currentSubscription!.productID == freeProductID) {
  94. message = "Free trial valid till $endDate";
  95. } else if (currentSubscription!.attributes?.isCancelled ?? false) {
  96. message = "Your subscription will be cancelled on $endDate";
  97. }
  98. return Padding(
  99. padding: const EdgeInsets.only(top: 8),
  100. child: Text(
  101. message,
  102. style: Theme.of(context).textTheme.caption,
  103. ),
  104. );
  105. }
  106. }
  107. class SubFaqWidget extends StatelessWidget {
  108. final bool isOnboarding;
  109. const SubFaqWidget({Key? key, this.isOnboarding = false}) : super(key: key);
  110. @override
  111. Widget build(BuildContext context) {
  112. final colorScheme = getEnteColorScheme(context);
  113. return Padding(
  114. padding: EdgeInsets.fromLTRB(16, 40, 16, isOnboarding ? 40 : 4),
  115. child: MenuItemWidget(
  116. captionedTextWidget: const CaptionedTextWidget(
  117. title: "Questions?",
  118. ),
  119. menuItemColor: colorScheme.fillFaint,
  120. trailingWidget: Icon(
  121. Icons.chevron_right_outlined,
  122. color: colorScheme.strokeBase,
  123. ),
  124. singleBorderRadius: 4,
  125. alignCaptionedTextToLeft: true,
  126. onTap: () async {
  127. showModalBottomSheet<void>(
  128. backgroundColor: Theme.of(context).colorScheme.bgColorForQuestions,
  129. barrierColor: Colors.black87,
  130. context: context,
  131. builder: (context) {
  132. return const BillingQuestionsWidget();
  133. },
  134. );
  135. },
  136. ),
  137. );
  138. }
  139. }