ente/lib/ui/payment/child_subscription_widget.dart

140 lines
4.4 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:photos/models/user_details.dart';
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/components/button_widget.dart';
import 'package:photos/utils/dialog_util.dart';
class ChildSubscriptionWidget extends StatelessWidget {
const ChildSubscriptionWidget({
2022-12-27 12:10:53 +00:00
Key? key,
required this.userDetails,
}) : super(key: key);
final UserDetails userDetails;
@override
Widget build(BuildContext context) {
2022-12-27 12:10:53 +00:00
final String familyAdmin = userDetails.familyData!.members!
.firstWhere((element) => element.isAdmin)
.email;
2022-04-25 04:21:43 +00:00
return Padding(
padding: const EdgeInsets.symmetric(vertical: 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Text(
"You are on a family plan!",
style: Theme.of(context).textTheme.bodyText1,
2022-04-25 04:21:43 +00:00
),
),
2022-07-04 06:02:17 +00:00
const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
2022-04-25 04:21:43 +00:00
),
Padding(
2022-07-04 06:02:17 +00:00
padding: const EdgeInsets.symmetric(horizontal: 16),
2022-04-25 04:21:43 +00:00
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
2022-07-04 06:02:17 +00:00
const TextSpan(
text: "Please contact ",
2022-04-25 04:21:43 +00:00
),
TextSpan(
text: familyAdmin,
2022-07-04 06:02:17 +00:00
style:
const TextStyle(color: Color.fromRGBO(29, 185, 84, 1)),
2022-04-25 04:21:43 +00:00
),
2022-07-04 06:02:17 +00:00
const TextSpan(
text: " to manage your subscription",
2022-04-25 04:21:43 +00:00
),
],
style: Theme.of(context).textTheme.bodyText1,
2022-04-25 04:21:43 +00:00
),
),
),
2022-07-04 06:02:17 +00:00
const Padding(
padding: EdgeInsets.symmetric(vertical: 8),
2022-04-25 04:21:43 +00:00
),
Image.asset(
2022-06-24 15:29:24 +00:00
"assets/family_plan_leave.png",
2022-04-25 04:21:43 +00:00
height: 256,
),
2022-07-04 06:02:17 +00:00
const Padding(
padding: EdgeInsets.symmetric(vertical: 0),
2022-04-25 04:21:43 +00:00
),
InkWell(
child: OutlinedButton(
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
2022-07-04 06:02:17 +00:00
padding:
const EdgeInsets.symmetric(vertical: 18, horizontal: 100),
2022-06-13 14:51:03 +00:00
backgroundColor: Colors.red[500],
2022-04-25 04:21:43 +00:00
),
2022-07-04 06:02:17 +00:00
child: const Text(
"Leave Family",
2022-04-25 04:21:43 +00:00
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
2022-06-13 14:51:03 +00:00
color: Colors.white, // same for both themes
2022-04-25 04:21:43 +00:00
),
textAlign: TextAlign.center,
),
onPressed: () async => {await _leaveFamilyPlan(context)},
),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
2022-06-13 15:27:06 +00:00
children: [
2022-04-25 04:21:43 +00:00
TextSpan(
text: "Please contact ",
2022-06-13 15:27:06 +00:00
style: Theme.of(context).textTheme.bodyText2,
2022-04-25 04:21:43 +00:00
),
TextSpan(
text: "support@ente.io",
2022-12-27 12:10:53 +00:00
style: Theme.of(context).textTheme.bodyText2?.copyWith(
2022-07-04 06:02:17 +00:00
color: const Color.fromRGBO(29, 185, 84, 1),
),
2022-04-25 04:21:43 +00:00
),
TextSpan(
text: " for help",
2022-06-13 15:27:06 +00:00
style: Theme.of(context).textTheme.bodyText2,
2022-04-25 04:21:43 +00:00
),
],
),
),
2022-04-25 04:21:43 +00:00
),
),
2022-04-25 04:21:43 +00:00
],
),
);
}
Future<void> _leaveFamilyPlan(BuildContext context) async {
final choice = await showChoiceDialog(
context,
title: "Leave family",
body: "Are you sure that you want to leave the family plan?",
firstButtonLabel: "Leave",
firstButtonOnTap: () async {
try {
await UserService.instance.leaveFamilyPlan();
} catch (e) {
Logger("ChildSubscriptionWidget").severe("failed to leave family");
rethrow;
}
},
);
if (choice == ButtonAction.error) {
await showGenericErrorDialog(context: context);
}
}
}