ente/lib/ui/payment/subscription_common_widgets.dart

143 lines
4 KiB
Dart
Raw Normal View History

// @dart=2.9
import 'package:flutter/material.dart';
import 'package:photos/ente_theme_data.dart';
import 'package:photos/models/subscription.dart';
import 'package:photos/ui/payment/billing_questions_widget.dart';
import 'package:photos/utils/data_util.dart';
import 'package:photos/utils/date_time_util.dart';
class SubscriptionHeaderWidget extends StatefulWidget {
final bool isOnboarding;
final int currentUsage;
2022-06-11 08:23:52 +00:00
const SubscriptionHeaderWidget({
Key key,
this.isOnboarding,
this.currentUsage,
}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _SubscriptionHeaderWidgetState();
}
}
class _SubscriptionHeaderWidgetState extends State<SubscriptionHeaderWidget> {
@override
Widget build(BuildContext context) {
if (widget.isOnboarding) {
return Padding(
padding: const EdgeInsets.fromLTRB(20, 20, 20, 24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
"Select your plan",
style: Theme.of(context).textTheme.headline4,
),
],
),
const SizedBox(
height: 10,
),
Text(
"Ente preserves your memories, so they're always available to you, even if you lose your device ",
style: Theme.of(context).textTheme.caption,
),
],
),
);
} else {
return SizedBox(
2022-05-03 11:53:40 +00:00
height: 72,
2022-04-28 05:24:26 +00:00
width: double.infinity,
child: Padding(
2022-05-03 11:53:40 +00:00
padding: const EdgeInsets.all(24.0),
child: RichText(
text: TextSpan(
children: [
TextSpan(
2022-06-11 08:23:52 +00:00
text: "Current usage is ",
style: Theme.of(context).textTheme.subtitle1,
),
2022-05-03 11:53:40 +00:00
TextSpan(
text: formatBytes(widget.currentUsage),
2022-07-03 09:49:33 +00:00
style: Theme.of(context)
.textTheme
.subtitle1
.copyWith(fontWeight: FontWeight.bold),
2022-05-03 11:53:40 +00:00
)
],
),
),
),
);
}
}
}
class ValidityWidget extends StatelessWidget {
final Subscription currentSubscription;
const ValidityWidget({Key key, this.currentSubscription}) : super(key: key);
@override
Widget build(BuildContext context) {
if (currentSubscription == null) {
return Container();
}
2022-08-29 14:43:31 +00:00
final endDate = getDateAndMonthAndYear(
2022-06-11 08:23:52 +00:00
DateTime.fromMicrosecondsSinceEpoch(currentSubscription.expiryTime),
);
2022-04-28 05:24:26 +00:00
var message = "Renews on $endDate";
if (currentSubscription.productID == freeProductID) {
2022-05-16 20:52:10 +00:00
message = "Free plan valid till $endDate";
} else if (currentSubscription.attributes?.isCancelled ?? false) {
2022-04-28 05:24:26 +00:00
message = "Your subscription will be cancelled on $endDate";
}
2021-08-23 10:22:07 +00:00
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
message,
2022-04-28 05:24:26 +00:00
style: Theme.of(context).textTheme.caption,
),
);
}
}
class SubFaqWidget extends StatelessWidget {
2022-07-03 06:49:00 +00:00
const SubFaqWidget({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.bottomCenter,
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: () {
showModalBottomSheet<void>(
backgroundColor: Theme.of(context).colorScheme.bgColorForQuestions,
barrierColor: Colors.black87,
context: context,
builder: (context) {
2022-07-04 06:02:17 +00:00
return const BillingQuestionsWidget();
},
);
},
child: Container(
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.all(40),
child: RichText(
text: TextSpan(
2022-05-16 20:52:10 +00:00
text: "Questions?",
2022-06-19 10:09:37 +00:00
style: Theme.of(context).textTheme.overline,
),
),
),
),
);
}
}