2022-04-20 19:36:33 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-10 04:48:56 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2022-04-20 19:36:33 +00:00
|
|
|
import 'package:photos/models/user_details.dart';
|
|
|
|
import 'package:photos/services/user_service.dart';
|
2023-01-10 04:48:56 +00:00
|
|
|
import 'package:photos/ui/components/button_widget.dart';
|
2022-04-20 19:36:33 +00:00
|
|
|
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,
|
2022-04-20 19:36:33 +00:00
|
|
|
}) : 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!
|
2022-04-20 19:36:33 +00:00
|
|
|
.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(
|
2022-06-06 15:27:45 +00:00
|
|
|
"You are on a family plan!",
|
2022-06-13 14:42:08 +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
|
|
|
),
|
|
|
|
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(
|
2022-06-06 15:27:45 +00:00
|
|
|
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(
|
2022-06-13 14:42:08 +00:00
|
|
|
text: " to manage your subscription",
|
2022-04-25 04:21:43 +00:00
|
|
|
),
|
|
|
|
],
|
2022-06-13 14:42:08 +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(
|
2022-06-13 14:42:08 +00:00
|
|
|
"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(
|
2022-06-06 15:27:45 +00:00
|
|
|
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-20 19:36:33 +00:00
|
|
|
),
|
|
|
|
),
|
2022-04-25 04:21:43 +00:00
|
|
|
),
|
2022-04-20 19:36:33 +00:00
|
|
|
),
|
2022-04-25 04:21:43 +00:00
|
|
|
],
|
|
|
|
),
|
2022-04-20 19:36:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _leaveFamilyPlan(BuildContext context) async {
|
2023-01-27 12:08:53 +00:00
|
|
|
final choice = await showChoiceDialog(
|
2022-04-20 19:36:33 +00:00
|
|
|
context,
|
2023-01-10 04:48:56 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
2022-04-20 19:36:33 +00:00
|
|
|
);
|
2023-02-10 07:22:16 +00:00
|
|
|
if (choice!.action == ButtonAction.error) {
|
2023-01-10 04:48:56 +00:00
|
|
|
await showGenericErrorDialog(context: context);
|
2022-04-20 19:36:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|