debug_section_widget.dart 3.0 KB

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