-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[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
[path_provider] added android support for getDownloadsDirectory #4317
Conversation
There was a problem hiding this 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).
808147b
to
8217e19
Compare
if (paths != null && paths.isNotEmpty) { | ||
return paths.first; | ||
} | ||
return null; | ||
} |
There was a problem hiding this comment.
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); | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
2931de4
to
2f469e1
Compare
912ce61
to
48f94bb
Compare
@@ -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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
53597d6
to
247d1ba
Compare
flutter_test: | ||
sdk: flutter | ||
integration_test: | ||
sdk: flutter | ||
mockito: 5.4.1 | ||
pigeon: ^9.2.4 |
There was a problem hiding this comment.
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); | ||
}); |
There was a problem hiding this comment.
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.
@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. |
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
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.