-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[file_selector] initial implementation #3140
Conversation
Change some variables to final, condense for loops and some if statements.
Also some refactoring of plugin code to accomplish tests
new fromData constructor in XFile class
Those tests should and will be added as part as each platform implementation. |
Every plugin I've implemented for desktop here has integration tests at both layers. Why would we do less testing in this plugin? Examples: |
@stuartmorgan most plugins so far have a purely programmatic API that never leaves the Flutter App under test. In this case, the test would need to drive native OS dialogs (I don't know if that's doable?) or bypass all that altogether by adding a mock method channel handler (which wouldn't work for the web case). I don't see how this end of the plugin can be integration-tested in a way that is somewhat platform agnostic. Do you have any idea about that? As a bad example, look at the tests for the image picker ;) |
Oh, right. I wasn't thinking about the fact that this is UI based; sorry about that. Yes, that does probably mean integration tests can't live at this layer. (We should still unit test the app-facing API though, using a mock platform interface implementaiton, per my other comments.) |
@stuartmorgan yes, those should be easy to add; it's just verify that the mock platform methods are being called (if done with Mockito and a Mock platform implementation) or by doing the method logging technique. |
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.
Thanks for addressing this! I think it's ready to go, even though, there's a small change incoming regarding the cross_file
package (we should be able to hide that fact from the platform_interface package, possibly!)
If Stuart is happy with the current implementation, let's get this merged!
import 'package:file_selector/file_selector.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Screen that shows an example of openFile(s) |
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 screen shows an example of getDirectoryPath, it seems :P
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.
Great catch! Fixed here and (hopefully) everywhere.
Note to all: |
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.
Thanks for the expanded test coverage and examples! LGTM with some minor nits.
class GetDirectoryPage extends StatelessWidget { | ||
void _getDirectoryPath(BuildContext context) async { | ||
final String initialDirectory = '~/Desktop'; | ||
final String confirmButtonText = 'Choose a cool directory'; |
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.
Nit: This is a lot of text for a button. Maybe pick something more realistic to demonstrate, like "Choose"?
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.
Done!
/// Screen that shows an example of openFile(s) | ||
class GetDirectoryPage extends StatelessWidget { | ||
void _getDirectoryPath(BuildContext context) async { | ||
final String initialDirectory = '~/Desktop'; |
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.
Do the various OS file dialogs actually expand "~"? The robust way to do this would be to use path_provider
; if we don't want to depend on that I would suggest we just don't set a starting directory in the example.
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.
That is a good point. I'm not sure if ~
gets actually expanded so I will play safe here and remove it.
Thanks @stuartmorgan :)!
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.
Note that path_provider
doesn't work in web at all AFAIK (U_U)
extensions: ['jpg', 'jpeg'], | ||
); | ||
final XTypeGroup pngTypeGroup = XTypeGroup( | ||
extensions: ['png'], |
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.
Why no label?
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.
Fixed!
class OpenMultipleImagesPage extends StatelessWidget { | ||
void _openImageFile(BuildContext context) async { | ||
final XTypeGroup jpgsTypeGroup = XTypeGroup( | ||
label: 'images', |
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.
It seems odd to call this "images" rather than "JPEGs" given that the other option is also an image type.
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.
Done!
flutter/flutter#70950 to track the integration. Thanks for the heads up :)! |
Let's go with this one! Thanks all for the hard work! |
While doing manual testing on Windows with the example I noticed that none of the example calls handle the user pressing cancel (in which case the returned path will be null). Right now canceling any dialog in the example will throw an exception. |
@stuartmorgan that's an interesting "edge" case for the web; in web you never get called back if the user cancels the selection (no events, null path... nothing!) |
Co-authored-by: Jason Panelli <[email protected]>
Co-authored-by: Jason Panelli <[email protected]>
Description
Add the API for the file_selector plugin.
Related Issues
flutter/flutter#65403
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?