subscription_common_widgets.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:photos/models/subscription.dart';
  4. import 'package:photos/ui/loading_widget.dart';
  5. import 'package:photos/utils/data_util.dart';
  6. import 'package:photos/utils/date_time_util.dart';
  7. import '../billing_questions_widget.dart';
  8. class SubscriptionHeaderWidget extends StatefulWidget {
  9. final bool isOnboarding;
  10. final Future<int> usageFuture;
  11. const SubscriptionHeaderWidget({Key key, this.isOnboarding, this.usageFuture})
  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: TextStyle(
  27. color: Colors.white54,
  28. height: 1.2,
  29. ),
  30. ),
  31. );
  32. } else {
  33. return SizedBox(
  34. height: 50,
  35. child: FutureBuilder(
  36. future: widget.usageFuture,
  37. builder: (BuildContext context, AsyncSnapshot snapshot) {
  38. if (snapshot.hasData) {
  39. return Padding(
  40. padding: const EdgeInsets.all(16.0),
  41. child: Text("current usage is " + formatBytes(snapshot.data)),
  42. );
  43. } else if (snapshot.hasError) {
  44. return Container();
  45. } else {
  46. return Padding(
  47. padding: const EdgeInsets.all(16.0),
  48. child: loadWidget,
  49. );
  50. }
  51. },
  52. ),
  53. );
  54. }
  55. }
  56. }
  57. class ValidityWidget extends StatelessWidget {
  58. final Subscription currentSubscription;
  59. const ValidityWidget({Key key, this.currentSubscription}) : super(key: key);
  60. @override
  61. Widget build(BuildContext context) {
  62. if (currentSubscription == null) {
  63. return Container();
  64. }
  65. var endDate = getDateAndMonthAndYear(
  66. DateTime.fromMicrosecondsSinceEpoch(currentSubscription.expiryTime));
  67. var message = "renews on $endDate";
  68. if (currentSubscription.productID == kFreeProductID) {
  69. message = "free plan valid till $endDate";
  70. } else if (currentSubscription.attributes?.isCancelled ?? false) {
  71. message = "your subscription will be cancelled on $endDate";
  72. }
  73. return Padding(
  74. padding: const EdgeInsets.only(top: 8),
  75. child: Text(
  76. message,
  77. style: TextStyle(
  78. color: Colors.white.withOpacity(0.6),
  79. fontSize: 14,
  80. ),
  81. ),
  82. );
  83. }
  84. }
  85. class SubFaqWidget extends StatelessWidget {
  86. @override
  87. Widget build(BuildContext context) {
  88. return Align(
  89. alignment: Alignment.bottomCenter,
  90. child: GestureDetector(
  91. behavior: HitTestBehavior.translucent,
  92. onTap: () {
  93. showModalBottomSheet<void>(
  94. backgroundColor: Color.fromRGBO(10, 15, 15, 1.0),
  95. barrierColor: Colors.black87,
  96. context: context,
  97. builder: (context) {
  98. return BillingQuestionsWidget();
  99. },
  100. );
  101. },
  102. child: Container(
  103. padding: EdgeInsets.all(40),
  104. child: RichText(
  105. text: TextSpan(
  106. text: "questions?",
  107. style: TextStyle(
  108. color: Colors.blue,
  109. fontFamily: 'Ubuntu',
  110. ),
  111. ),
  112. ),
  113. ),
  114. ),
  115. );
  116. }
  117. }