Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[file_selector_platform_interface] File selector nnbd #3509

Merged
merged 5 commits into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety.0

* Migration to null-safety

## 1.0.3+1

* Bump the [cross_file](https://pub.dev/packages/cross_file) package version.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,57 @@ class MethodChannelFileSelector extends FileSelectorPlatform {

/// Load a file from user's computer and return it as an XFile
@override
Future<XFile> openFile({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String confirmButtonText,
Future<XFile?> openFile({
List<XTypeGroup>? acceptedTypeGroups,
String? initialDirectory,
String? confirmButtonText,
}) async {
final List<String> path = await _channel.invokeListMethod<String>(
final List<String>? path = await _channel.invokeListMethod<String>(
'openFile',
<String, dynamic>{
'acceptedTypeGroups':
acceptedTypeGroups?.map((group) => group.toJSON())?.toList(),
acceptedTypeGroups?.map((group) => group.toJSON()).toList(),
'initialDirectory': initialDirectory,
'confirmButtonText': confirmButtonText,
'multiple': false,
},
);
return path == null ? null : XFile(path?.first);
return path == null ? null : XFile(path.first);
}

/// Load multiple files from user's computer and return it as an XFile
@override
Future<List<XFile>> openFiles({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String confirmButtonText,
List<XTypeGroup>? acceptedTypeGroups,
String? initialDirectory,
String? confirmButtonText,
}) async {
final List<String> pathList = await _channel.invokeListMethod<String>(
final List<String>? pathList = await _channel.invokeListMethod<String>(
'openFile',
<String, dynamic>{
'acceptedTypeGroups':
acceptedTypeGroups?.map((group) => group.toJSON())?.toList(),
acceptedTypeGroups?.map((group) => group.toJSON()).toList(),
'initialDirectory': initialDirectory,
'confirmButtonText': confirmButtonText,
'multiple': true,
},
);
return pathList?.map((path) => XFile(path))?.toList() ?? [];
return pathList?.map((path) => XFile(path)).toList() ?? [];
}

/// Gets the path from a save dialog
@override
Future<String> getSavePath({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String suggestedName,
String confirmButtonText,
Future<String?> getSavePath({
List<XTypeGroup>? acceptedTypeGroups,
String? initialDirectory,
String? suggestedName,
String? confirmButtonText,
}) async {
return _channel.invokeMethod<String>(
'getSavePath',
<String, dynamic>{
'acceptedTypeGroups':
acceptedTypeGroups?.map((group) => group.toJSON())?.toList(),
acceptedTypeGroups?.map((group) => group.toJSON()).toList(),
'initialDirectory': initialDirectory,
'suggestedName': suggestedName,
'confirmButtonText': confirmButtonText,
Expand All @@ -79,9 +79,9 @@ class MethodChannelFileSelector extends FileSelectorPlatform {

/// Gets a directory path from a dialog
@override
Future<String> getDirectoryPath({
String initialDirectory,
String confirmButtonText,
Future<String?> getDirectoryPath({
String? initialDirectory,
String? confirmButtonText,
}) async {
return _channel.invokeMethod<String>(
'getDirectoryPath',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,40 @@ abstract class FileSelectorPlatform extends PlatformInterface {
}

/// Open file dialog for loading files and return a file path
Future<XFile> openFile({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String confirmButtonText,
/// Returns `null` if user cancels the operation.
Future<XFile?> openFile({
List<XTypeGroup>? acceptedTypeGroups,
String? initialDirectory,
String? confirmButtonText,
}) {
throw UnimplementedError('openFile() has not been implemented.');
}

/// Open file dialog for loading files and return a list of file paths
Future<List<XFile>> openFiles({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String confirmButtonText,
List<XTypeGroup>? acceptedTypeGroups,
String? initialDirectory,
String? confirmButtonText,
}) {
throw UnimplementedError('openFiles() has not been implemented.');
}

/// Open file dialog for saving files and return a file path at which to save
Future<String> getSavePath({
List<XTypeGroup> acceptedTypeGroups,
String initialDirectory,
String suggestedName,
String confirmButtonText,
/// Returns `null` if user cancels the operation.
Future<String?> getSavePath({
List<XTypeGroup>? acceptedTypeGroups,
String? initialDirectory,
String? suggestedName,
String? confirmButtonText,
}) {
throw UnimplementedError('getSavePath() has not been implemented.');
}

/// Open file dialog for loading directories and return a directory path
Future<String> getDirectoryPath({
String initialDirectory,
String confirmButtonText,
/// Returns `null` if user cancels the operation.
Future<String?> getDirectoryPath({
String? initialDirectory,
String? confirmButtonText,
}) {
throw UnimplementedError('getDirectoryPath() has not been implemented.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ class XTypeGroup {
});

/// The 'name' or reference to this group of types
final String label;
final String? label;

/// The extensions for this group
final List<String> extensions;
final List<String>? extensions;

/// The MIME types for this group
final List<String> mimeTypes;
final List<String>? mimeTypes;

/// The UTIs for this group
final List<String> macUTIs;
final List<String>? macUTIs;

/// The web wild cards for this group (ex: image/*, video/*)
final List<String> webWildCards;
final List<String>? webWildCards;

/// Converts this object into a JSON formatted object
Map<String, dynamic> toJSON() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:html';

/// Create anchor element with download attribute
AnchorElement createAnchorElement(String href, String suggestedName) {
AnchorElement createAnchorElement(String href, String? suggestedName) {
final element = AnchorElement(href: href);

if (suggestedName == null) {
Expand All @@ -27,7 +27,7 @@ Element ensureInitialized(String id) {
if (target == null) {
final Element targetElement = Element.tag('flt-x-file')..id = id;

querySelector('body').children.add(targetElement);
querySelector('body')!.children.add(targetElement);
target = targetElement;
}
return target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ description: A common platform interface for the file_selector plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/file_selector/file_selector_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.0.3+1
version: 2.0.0-nullsafety.0

dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
http: ^0.12.0+1
plugin_platform_interface: ^1.0.1
cross_file: ^0.2.0
http: ^0.13.0-nullsafety.0
plugin_platform_interface: ^1.1.0-nullsafety.2
cross_file: ^0.3.0-nullsafety

dev_dependencies:
test: ^1.15.0
flutter_test:
sdk: flutter
mockito: ^4.1.1
mockito: ^5.0.0-nullsafety.5
pedantic: ^1.8.0

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0-0 <3.0.0'
flutter: ">=1.9.1+hotfix.4"
4 changes: 2 additions & 2 deletions packages/file_selector/file_selector_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^4.1.1
pedantic: ^1.8.0
mockito: ^5.0.0-nullsafety.5
pedantic: ^1.10.0-nullsafety.3
Comment on lines -25 to +26
Copy link
Member

Choose a reason for hiding this comment

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

I think this shouldn't have been pushed in this change. Apologies, I just noticed!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, not sure how I missed that. Want to push a quick revert on of this?

Copy link
Member

Choose a reason for hiding this comment

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

Here's the revert: #3528

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'm sorry my bad 🥺

Copy link
Member

Choose a reason for hiding this comment

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

@SirusCodes not at all, I should have published my comment wayyyyy earlier :)

integration_test:
path: ../../integration_test

Expand Down
2 changes: 1 addition & 1 deletion script/nnbd_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readonly NNBD_PLUGINS_LIST=(
"connectivity"
"cross_file"
"device_info"
"file_selector"
"flutter_plugin_android_lifecycle"
"flutter_webview"
"google_sign_in"
Expand All @@ -30,7 +31,6 @@ readonly NNBD_PLUGINS_LIST=(
readonly NON_NNBD_PLUGINS_LIST=(
# "android_alarm_manager"
"camera"
# "file_selector"
# "google_maps_flutter"
# "image_picker"
# "in_app_purchase"
Expand Down