subscription_common_widgets.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // @dart=2.9
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/ente_theme_data.dart';
  4. import 'package:photos/models/subscription.dart';
  5. import 'package:photos/ui/payment/billing_questions_widget.dart';
  6. import 'package:photos/utils/data_util.dart';
  7. import 'package:photos/utils/date_time_util.dart';
  8. class SubscriptionHeaderWidget extends StatefulWidget {
  9. final bool isOnboarding;
  10. final int currentUsage;
  11. const SubscriptionHeaderWidget({
  12. Key key,
  13. this.isOnboarding,
  14. this.currentUsage,
  15. }) : super(key: key);
  16. @override
  17. State<StatefulWidget> createState() {
  18. return _SubscriptionHeaderWidgetState();
  19. }
  20. }
  21. class _SubscriptionHeaderWidgetState extends State<SubscriptionHeaderWidget> {
  22. @override
  23. Widget build(BuildContext context) {
  24. if (widget.isOnboarding) {
  25. return Padding(
  26. padding: const EdgeInsets.fromLTRB(20, 20, 20, 24),
  27. child: Column(
  28. crossAxisAlignment: CrossAxisAlignment.start,
  29. children: [
  30. Row(
  31. children: [
  32. Text(
  33. "Select your plan",
  34. style: Theme.of(context).textTheme.headline4,
  35. ),
  36. ],
  37. ),
  38. const SizedBox(
  39. height: 10,
  40. ),
  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. ],
  46. ),
  47. );
  48. } else {
  49. return SizedBox(
  50. height: 72,
  51. width: double.infinity,
  52. child: Padding(
  53. padding: const EdgeInsets.all(24.0),
  54. child: RichText(
  55. text: TextSpan(
  56. children: [
  57. TextSpan(
  58. text: "Current usage is ",
  59. style: Theme.of(context).textTheme.subtitle1,
  60. ),
  61. TextSpan(
  62. text: formatBytes(widget.currentUsage),
  63. style: Theme.of(context)
  64. .textTheme
  65. .subtitle1
  66. .copyWith(fontWeight: FontWeight.bold),
  67. )
  68. ],
  69. ),
  70. ),
  71. ),
  72. );
  73. }
  74. }
  75. }
  76. class ValidityWidget extends StatelessWidget {
  77. final Subscription currentSubscription;
  78. const ValidityWidget({Key key, this.currentSubscription}) : super(key: key);
  79. @override
  80. Widget build(BuildContext context) {
  81. if (currentSubscription == null) {
  82. return const SizedBox.shrink();
  83. }
  84. final endDate = getDateAndMonthAndYear(
  85. DateTime.fromMicrosecondsSinceEpoch(currentSubscription.expiryTime),
  86. );
  87. var message = "Renews on $endDate";
  88. if (currentSubscription.productID == freeProductID) {
  89. message = "Free plan valid till $endDate";
  90. } else if (currentSubscription.attributes?.isCancelled ?? false) {
  91. message = "Your subscription will be cancelled on $endDate";
  92. }
  93. return Padding(
  94. padding: const EdgeInsets.only(top: 8),
  95. child: Text(
  96. message,
  97. style: Theme.of(context).textTheme.caption,
  98. ),
  99. );
  100. }
  101. }
  102. class SubFaqWidget extends StatelessWidget {
  103. const SubFaqWidget({Key key}) : super(key: key);
  104. @override
  105. Widget build(BuildContext context) {
  106. return Align(
  107. alignment: Alignment.bottomCenter,
  108. child: GestureDetector(
  109. behavior: HitTestBehavior.translucent,
  110. onTap: () {
  111. showModalBottomSheet<void>(
  112. backgroundColor: Theme.of(context).colorScheme.bgColorForQuestions,
  113. barrierColor: Colors.black87,
  114. context: context,
  115. builder: (context) {
  116. return const BillingQuestionsWidget();
  117. },
  118. );
  119. },
  120. child: Container(
  121. padding: const EdgeInsets.all(40),
  122. child: RichText(
  123. text: TextSpan(
  124. text: "Questions?",
  125. style: Theme.of(context).textTheme.bodyMedium.copyWith(
  126. decoration: TextDecoration.underline,
  127. ),
  128. ),
  129. ),
  130. ),
  131. ),
  132. );
  133. }
  134. }