ente/lib/ui/payment/child_subscription_widget.dart

145 lines
4.6 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2022-07-12 06:30:02 +00:00
import 'package:photos/ente_theme_data.dart';
import 'package:photos/models/user_details.dart';
import 'package:photos/services/user_service.dart';
import 'package:photos/ui/common/dialogs.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,
2022-05-17 11:38:21 +00:00
'Leave family',
'Are you sure that you want to leave the family plan?',
firstAction: 'No',
secondAction: 'Yes',
2022-07-12 06:30:02 +00:00
firstActionColor: Theme.of(context).colorScheme.greenAlternative,
secondActionColor: Theme.of(context).colorScheme.onSurface,
);
if (choice != DialogUserChoice.secondChoice) {
return;
}
2022-05-17 11:38:21 +00:00
final dialog = createProgressDialog(context, "Please wait...");
await dialog.show();
try {
await UserService.instance.leaveFamilyPlan();
2022-11-06 10:36:33 +00:00
await dialog.hide();
Navigator.of(context).pop('');
} catch (e) {
2022-11-06 10:36:33 +00:00
await dialog.hide();
showGenericErrorDialog(context: context);
}
}
}