account_section_widget.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/core/configuration.dart';
  4. import 'package:photos/services/billing_service.dart';
  5. import 'package:photos/services/user_service.dart';
  6. import 'package:photos/ui/loading_widget.dart';
  7. import 'package:photos/ui/settings/settings_section_title.dart';
  8. import 'package:photos/ui/settings/settings_text_item.dart';
  9. import 'package:photos/ui/subscription_page.dart';
  10. import 'package:photos/utils/data_util.dart';
  11. import 'package:photos/utils/dialog_util.dart';
  12. class AccountSectionWidget extends StatefulWidget {
  13. AccountSectionWidget({Key key}) : super(key: key);
  14. @override
  15. AccountSectionWidgetState createState() => AccountSectionWidgetState();
  16. }
  17. class AccountSectionWidgetState extends State<AccountSectionWidget> {
  18. String _usage;
  19. @override
  20. void initState() {
  21. _getUsage();
  22. super.initState();
  23. }
  24. @override
  25. Widget build(BuildContext context) {
  26. return Container(
  27. child: Column(
  28. children: [
  29. SettingsSectionTitle("account"),
  30. Padding(
  31. padding: EdgeInsets.all(4),
  32. ),
  33. GestureDetector(
  34. behavior: HitTestBehavior.translucent,
  35. onTap: () async {
  36. Navigator.of(context).push(
  37. MaterialPageRoute(
  38. builder: (BuildContext context) {
  39. return SubscriptionPage();
  40. },
  41. ),
  42. );
  43. },
  44. child: SettingsTextItem(
  45. text: "subscription plan", icon: Icons.navigate_next),
  46. ),
  47. Platform.isIOS
  48. ? Padding(padding: EdgeInsets.all(2))
  49. : Padding(padding: EdgeInsets.all(2)),
  50. Divider(height: 4),
  51. Platform.isIOS
  52. ? Padding(padding: EdgeInsets.all(8))
  53. : Padding(padding: EdgeInsets.all(8)),
  54. Row(
  55. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  56. children: [
  57. Text("total data backed up"),
  58. Container(
  59. height: 20,
  60. child: _usage == null ? loadWidget : Text(_usage),
  61. ),
  62. ],
  63. ),
  64. Platform.isIOS
  65. ? Padding(padding: EdgeInsets.all(6))
  66. : Padding(padding: EdgeInsets.all(8)),
  67. Divider(height: 4),
  68. GestureDetector(
  69. behavior: HitTestBehavior.translucent,
  70. onTap: () async {
  71. AlertDialog alert = AlertDialog(
  72. title: Text("logout"),
  73. content: Text("are you sure you want to logout?"),
  74. actions: [
  75. TextButton(
  76. child: Text(
  77. "no",
  78. style: TextStyle(
  79. color: Theme.of(context).buttonColor,
  80. ),
  81. ),
  82. onPressed: () {
  83. Navigator.of(context, rootNavigator: true).pop('dialog');
  84. },
  85. ),
  86. TextButton(
  87. child: Text(
  88. "yes, logout",
  89. style: TextStyle(
  90. color: Colors.red,
  91. ),
  92. ),
  93. onPressed: () async {
  94. Navigator.of(context, rootNavigator: true).pop('dialog');
  95. await UserService.instance.logout(context);
  96. },
  97. ),
  98. ],
  99. );
  100. showDialog(
  101. context: context,
  102. builder: (BuildContext context) {
  103. return alert;
  104. },
  105. );
  106. },
  107. child: SettingsTextItem(text: "logout", icon: Icons.navigate_next),
  108. ),
  109. ],
  110. ),
  111. );
  112. }
  113. void _getUsage() {
  114. BillingService.instance.fetchUsage().then((usage) async {
  115. if (mounted) {
  116. setState(() {
  117. _usage = formatBytes(usage);
  118. });
  119. }
  120. });
  121. }
  122. }