diff --git a/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart b/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart index dde1e5e01..8ada85d79 100644 --- a/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart +++ b/packages/dart/npt_flutter/lib/widgets/custom_text_button.dart @@ -1,6 +1,12 @@ +import 'dart:convert'; +import 'dart:io'; +import 'dart:typed_data'; + +import 'package:at_backupkey_flutter/services/backupkey_service.dart'; import 'package:at_contacts_flutter/services/contact_service.dart'; import 'package:at_onboarding_flutter/at_onboarding_flutter.dart'; import 'package:at_onboarding_flutter/at_onboarding_services.dart'; +import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; @@ -123,7 +129,34 @@ class CustomTextButton extends StatelessWidget { // break; case CustomListTileType.backupYourKey: if (context.mounted) { - BackupKeyWidget(atsign: ContactService().currentAtsign).showBackupDialog(context); + var atsign = context.read().getAtSign(); + // Build file data + var aesEncryptedKeys = await BackUpKeyService.getEncryptedKeys(atsign); + var keyString = jsonEncode(aesEncryptedKeys); + final List codeUnits = keyString.codeUnits; + final Uint8List data = Uint8List.fromList(codeUnits); + + // Get file path to write to + String? outputFile = await FilePicker.platform.saveFile( + dialogTitle: 'Please select a file to export to:', + fileName: '${atsign}_key.atKeys', + ); + if (outputFile == null) return; + // Create and write the file + try { + var f = File(outputFile); + await f.create(recursive: true); + await f.writeAsBytes(data); + } catch (e) { + if (!context.mounted) return; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: Colors.red, + // TODO localize + content: Text("Failed to save the atKeys file: $e"), + ), + ); + } } break; case CustomListTileType.resetAtsign: diff --git a/packages/dart/npt_flutter/pubspec.lock b/packages/dart/npt_flutter/pubspec.lock index 63bb02684..c21c06e3a 100644 --- a/packages/dart/npt_flutter/pubspec.lock +++ b/packages/dart/npt_flutter/pubspec.lock @@ -72,13 +72,13 @@ packages: source: hosted version: "2.0.7" at_backupkey_flutter: - dependency: transitive + dependency: "direct main" description: name: at_backupkey_flutter - sha256: "91425f34aabec7fc37f61259af690676aae6c1776c2feac7bfea5f7ea7fc3812" + sha256: "674d5ebf8443e0848c86cd14e25c326e33d7fef54a2a9732c4328a138f6c4fa5" url: "https://pub.dev" source: hosted - version: "4.0.15" + version: "4.0.16" at_base2e15: dependency: transitive description: diff --git a/packages/dart/npt_flutter/pubspec.yaml b/packages/dart/npt_flutter/pubspec.yaml index 2650d2b35..0c0d6861b 100644 --- a/packages/dart/npt_flutter/pubspec.yaml +++ b/packages/dart/npt_flutter/pubspec.yaml @@ -30,6 +30,7 @@ environment: dependencies: adaptive_theme: ^3.6.0 at_auth: ^2.0.7 + at_backupkey_flutter: ^4.0.16 at_client_mobile: ^3.2.18 at_contact: ^3.0.8 at_contacts_flutter: ^4.0.15