2022-04-20 19:36:33 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-04-25 04:21:43 +00:00
|
|
|
import 'package:flutter/painting.dart';
|
2022-04-20 19:36:33 +00:00
|
|
|
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({
|
|
|
|
Key key,
|
|
|
|
@required this.userDetails,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
final UserDetails userDetails;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
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(
|
2022-06-06 15:27:45 +00:00
|
|
|
"You are on a family plan!",
|
|
|
|
style:
|
|
|
|
Theme.of(context).textTheme.bodyText1.copyWith(fontSize: 14),
|
2022-04-25 04:21:43 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 8),
|
|
|
|
child: RichText(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
text: TextSpan(
|
|
|
|
children: [
|
|
|
|
TextSpan(
|
2022-06-06 15:27:45 +00:00
|
|
|
text: "Please contact ",
|
2022-04-25 04:21:43 +00:00
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: familyAdmin,
|
|
|
|
style: TextStyle(color: Color.fromRGBO(29, 185, 84, 1)),
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: " to manage your family subscription",
|
|
|
|
),
|
|
|
|
],
|
2022-06-06 15:27:45 +00:00
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.bodyText1
|
|
|
|
.copyWith(fontSize: 14),
|
2022-04-25 04:21:43 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 8),
|
|
|
|
),
|
|
|
|
Image.asset(
|
2022-06-06 15:27:45 +00:00
|
|
|
"assets/family sharing.png",
|
2022-04-25 04:21:43 +00:00
|
|
|
height: 256,
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 0),
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
child: OutlinedButton(
|
|
|
|
style: OutlinedButton.styleFrom(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 18, horizontal: 100),
|
|
|
|
side: BorderSide(
|
|
|
|
width: 2,
|
|
|
|
color: Color.fromRGBO(255, 52, 52, 1),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
"leave family",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
fontSize: 18,
|
|
|
|
color: Color.fromRGBO(255, 52, 52, 1),
|
|
|
|
),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
onPressed: () async => {await _leaveFamilyPlan(context)},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Align(
|
|
|
|
alignment: Alignment.bottomCenter,
|
|
|
|
child: RichText(
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
text: TextSpan(
|
|
|
|
children: const [
|
|
|
|
TextSpan(
|
2022-06-06 15:27:45 +00:00
|
|
|
text: "Please contact ",
|
2022-04-25 04:21:43 +00:00
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: "support@ente.io",
|
|
|
|
style: TextStyle(color: Color.fromRGBO(29, 185, 84, 1)),
|
|
|
|
),
|
|
|
|
TextSpan(
|
|
|
|
text: " for help",
|
|
|
|
),
|
|
|
|
],
|
2022-06-06 15:27:45 +00:00
|
|
|
style: Theme.of(context).textTheme.overline,
|
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 {
|
|
|
|
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-04-20 19:36:33 +00:00
|
|
|
firstActionColor: Theme.of(context).buttonColor,
|
|
|
|
secondActionColor: Colors.white,
|
|
|
|
);
|
|
|
|
if (choice != DialogUserChoice.secondChoice) {
|
|
|
|
return;
|
|
|
|
}
|
2022-05-17 11:38:21 +00:00
|
|
|
final dialog = createProgressDialog(context, "Please wait...");
|
2022-04-20 19:36:33 +00:00
|
|
|
await dialog.show();
|
|
|
|
try {
|
|
|
|
await UserService.instance.leaveFamilyPlan();
|
|
|
|
dialog.hide();
|
2022-04-26 08:40:37 +00:00
|
|
|
Navigator.of(context).pop('');
|
2022-04-20 19:36:33 +00:00
|
|
|
} catch (e) {
|
|
|
|
dialog.hide();
|
|
|
|
showGenericErrorDialog(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|