subscription_common_widgets.dart 3.9 KB

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