Skip to content

[path_provider] added android support for getDownloadsDirectory #4317

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

Conversation

zopagaduanjr
Copy link
Contributor

Followed step 3. of this approach flutter/plugins#4559 (review)

Fixes flutter/flutter#93198

originally from #4167 , but I renamed the branch hence it was closed

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

This comment is still unaddressed (both the missing test, and the implementation bug that the missing test would demonstrate).

@zopagaduanjr zopagaduanjr force-pushed the path_provider/downloads-directory branch from 808147b to 8217e19 Compare June 27, 2023 09:11
if (paths != null && paths.isNotEmpty) {
return paths.first;
}
return null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this one I've updated to catch the stateError scenario when externalStoragePaths returns empty list.

//TODO: override externalStoragePaths as empty
test('getDownloadsPath null', () async {
final String? path = await pathProvider.getDownloadsPath();
expect(path, null);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can check this one if its going in the right direction? I'm trying to add a case for the null externalStoragePaths, but if I override it to empty list then it will affect other tests

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll either have to modify kExternalStoragePaths and set it back or override _Api or TestPathProviderApi with the desired behavior and set your test to use that implementation like here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the null test

Copy link
Contributor

Choose a reason for hiding this comment

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

This approach seems okay to me but perhaps you can move this test to a different group and set up the TestPathProviderApi with TestPathProviderApi.setup(_ApiNull()) just for that group of tests, so that it doesn't conflict with any tests in this group?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I had an answer to the original question that I didn't realize I'd never actually published, and was still Pending. It would be much simpler to make the test implementation return configurable values, rather than have two different implementations and test groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the getDownloads test to use mockito, so we can configure values for normal path and null path

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe Stuart was suggesting making _Api return a configurable value (i.e. modifying kExternalStoragePaths) versus mocking TestPathProviderApi, but please correct me if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I was suggesting making the values returned by _Api configurable rather than hard-coded constants. Usually we do that by making the return values public fields of the fake implementation.

I'm okay with mockito instead (although I think it's overkill here), but not with having two different ways of structuring these tests; if you really want to use mockito then all of the tests need to be rewritten to use mockito and _Api removed.

@zopagaduanjr zopagaduanjr force-pushed the path_provider/downloads-directory branch 4 times, most recently from 2931de4 to 2f469e1 Compare July 6, 2023 04:20
@zopagaduanjr zopagaduanjr force-pushed the path_provider/downloads-directory branch 3 times, most recently from 912ce61 to 48f94bb Compare July 13, 2023 01:38
@@ -41,4 +41,6 @@ abstract class PathProviderApi {
List<String?> getExternalCachePaths();
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
List<String?> getExternalStoragePaths(StorageDirectory directory);
@TaskQueue(type: TaskQueueType.serialBackgroundThread)
String? getDownloadsPath();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this change is causing the test failures since getDownloadsPath() doesn't need to be implemented on the native side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it, i have removed getDownloadsPath

@zopagaduanjr zopagaduanjr force-pushed the path_provider/downloads-directory branch 2 times, most recently from 53597d6 to 247d1ba Compare July 19, 2023 01:59
flutter_test:
sdk: flutter
integration_test:
sdk: flutter
mockito: 5.4.1
pigeon: ^9.2.4
Copy link
Contributor

Choose a reason for hiding this comment

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

@stuartmorgan I assume these should be removed before being merged?

//TODO: override externalStoragePaths as empty
test('getDownloadsPath null', () async {
final String? path = await pathProvider.getDownloadsPath();
expect(path, null);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe Stuart was suggesting making _Api return a configurable value (i.e. modifying kExternalStoragePaths) versus mocking TestPathProviderApi, but please correct me if I'm wrong.

@reidbaker
Copy link
Contributor

@zopagaduanjr thank you for your contribution this appears to have been taken over by #4708 so I am going to close this PR to remove it from our queue.

@reidbaker reidbaker closed this Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[path_provider] getDownloadsDirectory() doesn't work for iOS and Android.
4 participants