debug_section_widget.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // @dart=2.9
  2. import 'package:ente_auth/core/configuration.dart';
  3. import 'package:ente_auth/l10n/l10n.dart';
  4. import 'package:ente_auth/ui/settings/common_settings.dart';
  5. import 'package:ente_auth/ui/settings/settings_section_title.dart';
  6. import 'package:ente_auth/ui/settings/settings_text_item.dart';
  7. import 'package:expandable/expandable.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:flutter_sodium/flutter_sodium.dart';
  10. class DebugSectionWidget extends StatelessWidget {
  11. const DebugSectionWidget({Key key}) : super(key: key);
  12. @override
  13. Widget build(BuildContext context) {
  14. // This is a debug only section not shown to end users, so these strings are
  15. // not translated.
  16. return ExpandablePanel(
  17. header: const SettingsSectionTitle("Debug"),
  18. collapsed: Container(),
  19. expanded: _getSectionOptions(context),
  20. theme: getExpandableTheme(context),
  21. );
  22. }
  23. Widget _getSectionOptions(BuildContext context) {
  24. return Column(
  25. children: [
  26. GestureDetector(
  27. behavior: HitTestBehavior.translucent,
  28. onTap: () async {
  29. _showKeyAttributesDialog(context);
  30. },
  31. child: const SettingsTextItem(
  32. text: "Key attributes",
  33. icon: Icons.navigate_next,
  34. ),
  35. ),
  36. ],
  37. );
  38. }
  39. void _showKeyAttributesDialog(BuildContext context) {
  40. final l10n = context.l10n;
  41. final keyAttributes = Configuration.instance.getKeyAttributes();
  42. final AlertDialog alert = AlertDialog(
  43. title: const Text("key attributes"),
  44. content: SingleChildScrollView(
  45. child: Column(
  46. children: [
  47. const Text(
  48. "Key",
  49. style: TextStyle(fontWeight: FontWeight.bold),
  50. ),
  51. Text(Sodium.bin2base64(Configuration.instance.getKey())),
  52. const Padding(padding: EdgeInsets.all(12)),
  53. const Text(
  54. "Encrypted Key",
  55. style: TextStyle(fontWeight: FontWeight.bold),
  56. ),
  57. Text(keyAttributes.encryptedKey),
  58. const Padding(padding: EdgeInsets.all(12)),
  59. const Text(
  60. "Key Decryption Nonce",
  61. style: TextStyle(fontWeight: FontWeight.bold),
  62. ),
  63. Text(keyAttributes.keyDecryptionNonce),
  64. const Padding(padding: EdgeInsets.all(12)),
  65. const Text(
  66. "KEK Salt",
  67. style: TextStyle(fontWeight: FontWeight.bold),
  68. ),
  69. Text(keyAttributes.kekSalt),
  70. const Padding(padding: EdgeInsets.all(12)),
  71. ],
  72. ),
  73. ),
  74. actions: [
  75. TextButton(
  76. child: Text(l10n.ok),
  77. onPressed: () {
  78. Navigator.of(context, rootNavigator: true).pop('dialog');
  79. },
  80. ),
  81. ],
  82. );
  83. showDialog(
  84. context: context,
  85. builder: (BuildContext context) {
  86. return alert;
  87. },
  88. );
  89. }
  90. }