ente/lib/ui/payment/child_subscription_widget.dart

130 lines
4.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
2023-04-06 08:39:34 +00:00
import "package:photos/generated/l10n.dart";
import 'package:photos/models/user_details.dart';
import 'package:photos/services/user_service.dart';
2023-04-08 04:35:37 +00:00
import "package:photos/theme/ente_theme.dart";
import 'package:photos/ui/components/buttons/button_widget.dart';
import 'package:photos/utils/dialog_util.dart';
2023-04-08 04:35:37 +00:00
import "package:styled_text/styled_text.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(
2023-04-06 08:39:34 +00:00
S.of(context).youAreOnAFamilyPlan,
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),
2023-04-08 04:35:37 +00:00
child: StyledText(
text: S.of(context).contactFamilyAdmin(familyAdmin),
style: Theme.of(context).textTheme.bodyText1,
tags: {
'green': StyledTextTag(
style: TextStyle(
color: getEnteColorScheme(context).primary500,
2022-04-25 04:21:43 +00:00
),
2023-04-08 04:35:37 +00:00
),
},
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
),
2023-04-06 08:39:34 +00:00
child: Text(
S.of(context).leaveFamily,
style: const TextStyle(
2022-04-25 04:21:43 +00:00
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,
2023-04-08 04:35:37 +00:00
child: Padding(
padding: const EdgeInsets.all(20),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
children: [
TextSpan(
text: S
.of(context)
.pleaseContactSupportAndWeWillBeHappyToHelp,
style: Theme.of(context).textTheme.bodyText2,
),
],
),
),
),
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,
2023-04-06 08:39:34 +00:00
title: S.of(context).leaveFamily,
body: S.of(context).areYouSureThatYouWantToLeaveTheFamily,
firstButtonLabel: S.of(context).leave,
firstButtonOnTap: () async {
try {
await UserService.instance.leaveFamilyPlan();
} catch (e) {
Logger("ChildSubscriptionWidget").severe("failed to leave family");
rethrow;
}
},
);
if (choice!.action == ButtonAction.error) {
await showGenericErrorDialog(context: context);
}
}
}