debug_section_widget.dart 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/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. ],
  34. );
  35. }
  36. void _showKeyAttributesDialog(BuildContext context) {
  37. final keyAttributes = Configuration.instance.getKeyAttributes();
  38. final AlertDialog alert = AlertDialog(
  39. title: const Text("key attributes"),
  40. content: SingleChildScrollView(
  41. child: Column(
  42. children: [
  43. const Text(
  44. "Key",
  45. style: TextStyle(fontWeight: FontWeight.bold),
  46. ),
  47. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  48. const Padding(padding: EdgeInsets.all(12)),
  49. const Text(
  50. "Encrypted Key",
  51. style: TextStyle(fontWeight: FontWeight.bold),
  52. ),
  53. Text(keyAttributes.encryptedKey),
  54. const Padding(padding: EdgeInsets.all(12)),
  55. const Text(
  56. "Key Decryption Nonce",
  57. style: TextStyle(fontWeight: FontWeight.bold),
  58. ),
  59. Text(keyAttributes.keyDecryptionNonce),
  60. const Padding(padding: EdgeInsets.all(12)),
  61. const Text(
  62. "KEK Salt",
  63. style: TextStyle(fontWeight: FontWeight.bold),
  64. ),
  65. Text(keyAttributes.kekSalt),
  66. const Padding(padding: EdgeInsets.all(12)),
  67. ],
  68. ),
  69. ),
  70. actions: [
  71. TextButton(
  72. child: const Text("OK"),
  73. onPressed: () {
  74. Navigator.of(context, rootNavigator: true).pop('dialog');
  75. },
  76. ),
  77. ],
  78. );
  79. showDialog(
  80. context: context,
  81. builder: (BuildContext context) {
  82. return alert;
  83. },
  84. );
  85. }
  86. }