subscription_common_widgets.dart 3.5 KB

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