debug_section_widget.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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: SettingsSectionTitle("Debug"),
  15. collapsed: Container(),
  16. expanded: _getSectionOptions(context),
  17. theme: getExpandableTheme(context),
  18. );
  19. }
  20. Widget _getSectionOptions(BuildContext context) {
  21. return Column(children: [
  22. GestureDetector(
  23. behavior: HitTestBehavior.translucent,
  24. onTap: () async {
  25. _showKeyAttributesDialog(context);
  26. },
  27. child:
  28. SettingsTextItem(text: "Key attributes", icon: Icons.navigate_next),
  29. ),
  30. GestureDetector(
  31. behavior: HitTestBehavior.translucent,
  32. onTap: () async {
  33. Network.instance.getAlice().showInspector();
  34. },
  35. child: SettingsTextItem(
  36. text: "Network requests", icon: Icons.navigate_next),
  37. )
  38. ]);
  39. }
  40. void _showKeyAttributesDialog(BuildContext context) {
  41. final keyAttributes = Configuration.instance.getKeyAttributes();
  42. AlertDialog alert = AlertDialog(
  43. title: Text("key attributes"),
  44. content: SingleChildScrollView(
  45. child: Column(children: [
  46. Text("Key", style: TextStyle(fontWeight: FontWeight.bold)),
  47. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  48. Padding(padding: EdgeInsets.all(12)),
  49. Text("Encrypted Key", style: TextStyle(fontWeight: FontWeight.bold)),
  50. Text(keyAttributes.encryptedKey),
  51. Padding(padding: EdgeInsets.all(12)),
  52. Text("Key Decryption Nonce",
  53. style: TextStyle(fontWeight: FontWeight.bold)),
  54. Text(keyAttributes.keyDecryptionNonce),
  55. Padding(padding: EdgeInsets.all(12)),
  56. Text("KEK Salt", style: TextStyle(fontWeight: FontWeight.bold)),
  57. Text(keyAttributes.kekSalt),
  58. Padding(padding: EdgeInsets.all(12)),
  59. ]),
  60. ),
  61. actions: [
  62. TextButton(
  63. child: Text("OK"),
  64. onPressed: () {
  65. Navigator.of(context, rootNavigator: true).pop('dialog');
  66. },
  67. ),
  68. ],
  69. );
  70. showDialog(
  71. context: context,
  72. builder: (BuildContext context) {
  73. return alert;
  74. },
  75. );
  76. }
  77. }