debug_section_widget.dart 3.5 KB

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