account_section_widget.dart 4.2 KB

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