-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[file_selector_web] migrate to pkg:web #5413
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
adafc76
wip
kevmoo 59c8103
Attempt at URL launcher
kevmoo 821a8c1
url_launcher_web: move to latest pkg:web, use stream helper for events
kevmoo f381872
Bump shared_preferences pkg:web beta dep
kevmoo 88e6820
Bump pkg:web versions
kevmoo 3e07c86
file_selector_web: moved to pkg:web
kevmoo 000b986
merge
kevmoo 598fee4
Merge remote-tracking branch 'origin/HEAD' into pkg_web_wip
kevmoo 43d204b
update pubspec and changelog
kevmoo 4844d30
support wide range
kevmoo 31afe98
revert changes to file_selector
kevmoo d22b3f9
put back flutter constraints
kevmoo 94cecca
whitelist pkg:web
kevmoo 09055d0
Merge remote-tracking branch 'origin/HEAD' into pkg_web_wip
kevmoo a867202
more flutter version silly
kevmoo c897a6c
flutter version fix
kevmoo d1af42f
smaller diff
kevmoo d575456
ugh
kevmoo 97aecf9
update _dartSdkForFlutterSdk
kevmoo 3c137b0
Merge remote-tracking branch 'origin/HEAD' into pkg_web_wip
kevmoo 11d4fb1
revert changes for shared_prefs to unblock
kevmoo 3d30805
cast to handle two versions of pkg:web
kevmoo 315ad9b
another cast
kevmoo e7bbc7f
more lint fighting
kevmoo 2865d92
just file things
kevmoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.9.3 | ||
|
||
* Updates minimum supported SDK version to Dart 3.2. | ||
|
||
## 0.9.2+1 | ||
|
||
* Adds pub topics to package metadata. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ dependencies: | |
path: ../ | ||
flutter: | ||
sdk: flutter | ||
web: '>=0.3.0 <0.5.0' | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,41 +3,46 @@ | |
// found in the LICENSE file. | ||
|
||
import 'dart:async'; | ||
import 'dart:html'; | ||
import 'dart:js_interop'; | ||
|
||
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart'; | ||
import 'package:flutter/foundation.dart' show visibleForTesting; | ||
import 'package:flutter/services.dart'; | ||
import 'package:web/helpers.dart'; | ||
|
||
/// Class to manipulate the DOM with the intention of reading files from it. | ||
class DomHelper { | ||
/// Default constructor, initializes the container DOM element. | ||
DomHelper() { | ||
final Element body = querySelector('body')!; | ||
body.children.add(_container); | ||
body.appendChild(_container); | ||
} | ||
|
||
final Element _container = Element.tag('file-selector'); | ||
final Element _container = createElementTag('file-selector'); | ||
|
||
/// Sets the <input /> attributes and waits for a file to be selected. | ||
Future<List<XFile>> getFiles({ | ||
String accept = '', | ||
bool multiple = false, | ||
@visibleForTesting FileUploadInputElement? input, | ||
@visibleForTesting HTMLInputElement? input, | ||
}) { | ||
final Completer<List<XFile>> completer = Completer<List<XFile>>(); | ||
final FileUploadInputElement inputElement = | ||
input ?? FileUploadInputElement(); | ||
final HTMLInputElement inputElement = | ||
input ?? (createElementTag('input') as HTMLInputElement) | ||
..type = 'file'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice if this asserted that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not worried about this, since it's text only |
||
_container.children.add( | ||
_container.appendChild( | ||
inputElement | ||
..accept = accept | ||
..multiple = multiple, | ||
); | ||
|
||
inputElement.onChange.first.then((_) { | ||
final List<XFile> files = | ||
inputElement.files!.map(_convertFileToXFile).toList(); | ||
final List<XFile> files = Iterable<File>.generate( | ||
inputElement.files!.length, | ||
(int i) => inputElement.files!.item(i)!) | ||
.map(_convertFileToXFile) | ||
.toList(); | ||
inputElement.remove(); | ||
completer.complete(files); | ||
}); | ||
|
@@ -52,10 +57,13 @@ class DomHelper { | |
completer.completeError(platformException); | ||
}); | ||
|
||
inputElement.addEventListener('cancel', (Event event) { | ||
inputElement.remove(); | ||
completer.complete(<XFile>[]); | ||
}); | ||
inputElement.addEventListener( | ||
'cancel', | ||
(Event event) { | ||
inputElement.remove(); | ||
completer.complete(<XFile>[]); | ||
}.toJS, | ||
); | ||
|
||
// TODO(dit): Reimplement this with the showPicker() API, https://github.com/flutter/flutter/issues/130365 | ||
inputElement.click(); | ||
|
@@ -64,10 +72,12 @@ class DomHelper { | |
} | ||
|
||
XFile _convertFileToXFile(File file) => XFile( | ||
Url.createObjectUrl(file), | ||
// TODO(srujzs): This is necessary in order to support package:web 0.4.0. | ||
// This was not needed with 0.3.0, hence the lint. | ||
// ignore: unnecessary_cast | ||
URL.createObjectURL(file as JSObject), | ||
name: file.name, | ||
length: file.size, | ||
lastModified: DateTime.fromMillisecondsSinceEpoch( | ||
file.lastModified ?? DateTime.now().millisecondsSinceEpoch), | ||
lastModified: DateTime.fromMillisecondsSinceEpoch(file.lastModified), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
- test_api | ||
- vm_service | ||
- wasm | ||
- web | ||
- yaml | ||
# Google-owned packages | ||
- _discoveryapis_commons | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
🤷 – for the most part, this is not a user visible change so I omitted that bit.