Skip to content

Commit

Permalink
Merge pull request #33 from mario-bermonti:enable-exporting-data
Browse files Browse the repository at this point in the history
Enable exporting data to downloads folder
  • Loading branch information
mario-bermonti authored Jan 25, 2024
2 parents c2092c0 + 39dbb98 commit 50b8ef6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mdigit_span_tasks">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:label="mdigit_span_tasks"
android:name="${applicationName}"
Expand Down
20 changes: 9 additions & 11 deletions lib/src/export_data/controller/data_exporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,30 @@ class DataExporter {
/// with the name [dbName]. This method does not modify the original db.
Future<void> getDB() async {
final Directory dir = await getApplicationDocumentsDirectory();
dbPath = "${dir.path}/$dbName.sqlite3";
dbPath = "${dir.path}/$dbName";
db = File(dbPath);
}

/// Get destination file on which to save the db copy.
/// The destination file will be in the external storage and will have the
/// same name as the db.
/// The destination file will be in the `Download` folder and will have the
/// same name as the dbs.
/// Currently only android is supported.
Future<void> initDestinationFile() async {
Directory destinationDir = await _initDestinationDir();
final String destinationPath = '${destinationDir.path}/$dbName.sqlite3';
final String destinationPath = '${destinationDir.path}/$dbName';
destinationFile = File(destinationPath);
}

/// Gets the directory to which the db will be exported.
/// Currently only android is supported and the destination dir is a
/// directory named 'mDigitSpanTasks' in the android external storage.
/// directory named `mDigitSpanTasks` in the android `Download` folder.
/// It creates the directory with its parent dirs if these do not exist.
Future<Directory> _initDestinationDir() async {
Directory? externalDir = await getExternalStorageDirectory();
Directory downloadsDir =
Directory('/storage/emulated/0/Download/mDigitSpanTasks');
await downloadsDir.create(recursive: true);

/// TODO handle errors that will arise if [externalDir] is null
Directory dsExternalDir = Directory('${externalDir!.path}/mDigitSpanTasks');
dsExternalDir.create(recursive: true);

return dsExternalDir;
return downloadsDir;
}

/// Create copy of db in the path specified by [destinationFile].
Expand Down
3 changes: 2 additions & 1 deletion lib/src/export_data/view/export_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:mdigit_span_tasks/src/services/services/export_dbs.dart';

/// [ExportButton] Is used by the user to export the data from the app
class ExportButton extends StatelessWidget {
Expand All @@ -8,7 +9,7 @@ class ExportButton extends StatelessWidget {
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.send_to_mobile),
onPressed: () {},
onPressed: () async => await exportDBs(),
);
}
}

0 comments on commit 50b8ef6

Please sign in to comment.