Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve issue 359 #413

Conversation

Sarath191181208
Copy link

Selecting a hive persistence folder

The flow of the app is as follows:

  • on app init the user is prompted to give a save location
  • The folder is picked using file_picker package.
  • The folder is saved using shared_preferences.

NOTE: On Linux file_picker requires the zenity package for picking files.

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I have run the tests (flutter test) and all tests are passing, except one test in /apidash/test/models/response_model_test.dart due to invalid SSL certificate of https://api.apidash.dev/

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes
  • No

@ashitaprasad
Copy link
Member

Check file_selector we already use this package for picking files in API Dash and it does not requires the zenity package for picking files on Linux.

@Sarath191181208
Copy link
Author

I am extremely sorry if this is because of me using arch but it requires zenity a system package for picking files and gives this error if zenity isn't found on path while giving this error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Couldn't find the executable zenity in the path.
#0      isExecutableOnPath (package:file_picker/src/utils.dart:60:5)
<asynchronous suspension>
#1      FilePickerLinux._getPathToExecutable (package:file_picker/src/linux/file_picker_linux.dart:123:14)
<asynchronous suspension>
#2      FilePickerLinux.getDirectoryPath (package:file_picker/src/linux/file_picker_linux.dart:67:24)
<asynchronous suspension>
#3      HiveDirectorySelectorState.selectFolder (package:apidash/widgets/hive_directory_selector.dart:18:33)
<asynchronous suspension>

@ashitaprasad
Copy link
Member

Did you read my comment above?

@ashitaprasad
Copy link
Member

@Sarath191181208 is this PR ready for review?

@Sarath191181208
Copy link
Author

Yes

///
/// You can provide a [subDir] where the boxes should be stored.
Future<void> initHiveWithRootFolder(String appDir, [String? subDir]) async {
WidgetsFlutterBinding.ensureInitialized();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WidgetsFlutterBinding.ensureInitialized(); should not be hidden in this function. It should be in main() as it is currently.


init(join(appDir, subDir));
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this extension. This task can be done by a hive utility function.

@@ -0,0 +1,30 @@
// Store hive save folder path.
Copy link
Member

@ashitaprasad ashitaprasad Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not models. They are shared_preferences utility functions.

Future<void> openBoxes() async {
await Hive.initFlutter();
Future<void> openBoxes(String hiveSaveFolder) async {
await Hive.initHiveWithRootFolder(hiveSaveFolder);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will get changed according to the comment above

import 'package:apidash/services/hive_services.dart';
import 'package:flutter/material.dart';

class HiveDirectorySelector extends StatefulWidget {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it require a Stateful Widget or Stateless can work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving state never terminates if persistent files cannot be accessed / modified
2 participants