debug_section_widget.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // @dart=2.9
  2. import 'package:expandable/expandable.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_sodium/flutter_sodium.dart';
  5. import 'package:photos/core/configuration.dart';
  6. import 'package:photos/services/ignored_files_service.dart';
  7. import 'package:photos/services/local_sync_service.dart';
  8. import 'package:photos/services/sync_service.dart';
  9. import 'package:photos/ui/settings/common_settings.dart';
  10. import 'package:photos/ui/settings/settings_section_title.dart';
  11. import 'package:photos/ui/settings/settings_text_item.dart';
  12. import 'package:photos/utils/toast_util.dart';
  13. class DebugSectionWidget extends StatelessWidget {
  14. const DebugSectionWidget({Key key}) : super(key: key);
  15. @override
  16. Widget build(BuildContext context) {
  17. return ExpandablePanel(
  18. header: const SettingsSectionTitle("Debug"),
  19. collapsed: Container(),
  20. expanded: _getSectionOptions(context),
  21. theme: getExpandableTheme(context),
  22. );
  23. }
  24. Widget _getSectionOptions(BuildContext context) {
  25. return Column(
  26. children: [
  27. GestureDetector(
  28. behavior: HitTestBehavior.translucent,
  29. onTap: () async {
  30. _showKeyAttributesDialog(context);
  31. },
  32. child: const SettingsTextItem(
  33. text: "Key attributes",
  34. icon: Icons.navigate_next,
  35. ),
  36. ),
  37. GestureDetector(
  38. behavior: HitTestBehavior.translucent,
  39. onTap: () async {
  40. await LocalSyncService.instance.resetLocalSync();
  41. showToast(context, "Done");
  42. },
  43. child: const SettingsTextItem(
  44. text: "Delete Local Import DB",
  45. icon: Icons.navigate_next,
  46. ),
  47. ),
  48. GestureDetector(
  49. behavior: HitTestBehavior.translucent,
  50. onTap: () async {
  51. await IgnoredFilesService.instance.reset();
  52. SyncService.instance.sync();
  53. showToast(context, "Done");
  54. },
  55. child: const SettingsTextItem(
  56. text: "Allow auto-upload for ignored files",
  57. icon: Icons.navigate_next,
  58. ),
  59. ),
  60. ],
  61. );
  62. }
  63. void _showKeyAttributesDialog(BuildContext context) {
  64. final keyAttributes = Configuration.instance.getKeyAttributes();
  65. final AlertDialog alert = AlertDialog(
  66. title: const Text("key attributes"),
  67. content: SingleChildScrollView(
  68. child: Column(
  69. children: [
  70. const Text(
  71. "Key",
  72. style: TextStyle(fontWeight: FontWeight.bold),
  73. ),
  74. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  75. const Padding(padding: EdgeInsets.all(12)),
  76. const Text(
  77. "Encrypted Key",
  78. style: TextStyle(fontWeight: FontWeight.bold),
  79. ),
  80. Text(keyAttributes.encryptedKey),
  81. const Padding(padding: EdgeInsets.all(12)),
  82. const Text(
  83. "Key Decryption Nonce",
  84. style: TextStyle(fontWeight: FontWeight.bold),
  85. ),
  86. Text(keyAttributes.keyDecryptionNonce),
  87. const Padding(padding: EdgeInsets.all(12)),
  88. const Text(
  89. "KEK Salt",
  90. style: TextStyle(fontWeight: FontWeight.bold),
  91. ),
  92. Text(keyAttributes.kekSalt),
  93. const Padding(padding: EdgeInsets.all(12)),
  94. ],
  95. ),
  96. ),
  97. actions: [
  98. TextButton(
  99. child: const Text("OK"),
  100. onPressed: () {
  101. Navigator.of(context, rootNavigator: true).pop('dialog');
  102. },
  103. ),
  104. ],
  105. );
  106. showDialog(
  107. context: context,
  108. builder: (BuildContext context) {
  109. return alert;
  110. },
  111. );
  112. }
  113. }