-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[cross_file_platform_interface] Platform interface implementation of cross_file
#12825
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
Open
bparrishMines
wants to merge
8
commits into
flutter:main
Choose a base branch
from
bparrishMines:cross_file_intf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc45cb5
move out platform interface
bparrishMines 4b2e6e7
Merge branch 'main' of https://github.com/flutter/packages into cross…
bparrishMines 7068e73
remove publish to
bparrishMines 3bacba8
fix doc comments
bparrishMines 05f8326
fix uri creation for file system
bparrishMines d8cbef4
tests and improved extension requirements
bparrishMines c10a95e
Merge branch 'main' of https://github.com/flutter/packages into cross…
bparrishMines 2403174
unused import
bparrishMines 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Below is a list of people and organizations that have contributed | ||
| # to the Flutter project. Names should be added to the list like so: | ||
| # | ||
| # Name/Organization <email address> | ||
|
|
||
| Google LLC |
3 changes: 3 additions & 0 deletions
3
packages/cross_file/cross_file_platform_interface/CHANGELOG.md
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## 0.1.0 | ||
|
|
||
| * Initial release. |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| Copyright 2013 The Flutter Authors | ||
|
|
||
| Redistribution and use in source and binary forms, with or without modification, | ||
| are permitted provided that the following conditions are met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer in the documentation and/or other materials provided | ||
| with the distribution. | ||
| * Neither the name of Google Inc. nor the names of its | ||
| contributors may be used to endorse or promote products derived | ||
| from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
| ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
21 changes: 21 additions & 0 deletions
21
packages/cross_file/cross_file_platform_interface/README.md
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # cross_file_platform_interface | ||
|
|
||
| A common platform interface for the [`cross_file`](https://pub.dev/packages/cross_file) plugin. | ||
|
|
||
| This interface allows platform implementations of the `cross_file` plugin, as well as the plugin | ||
| itself, to ensure they are supporting the same interface. | ||
|
|
||
| # Usage | ||
|
|
||
| To implement a new platform implementation of `cross_file`, extend | ||
| [`CrossFilePlatform`](lib/src/cross_file_platform.dart) with an implementation that performs the | ||
| platform-specific behavior, and when you register your plugin, set the default | ||
| `CrossFilePlatform` by calling `CrossFilePlatform.instance = CrossFileMyPlatform()`. | ||
|
|
||
| # Note on breaking changes | ||
|
|
||
| Strongly prefer non-breaking changes (such as adding a method to the interface) | ||
| over breaking changes for this package. | ||
|
|
||
| See https://flutter.dev/go/platform-interface-breaking-changes for a discussion on why a less-clean | ||
| interface is preferable to a breaking change. |
12 changes: 12 additions & 0 deletions
12
packages/cross_file/cross_file_platform_interface/lib/cross_file_platform_interface.dart
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| export 'src/cross_file_platform.dart'; | ||
| export 'src/file_system/platform_file_system_cross_directory.dart'; | ||
| export 'src/file_system/platform_file_system_cross_file.dart'; | ||
| export 'src/platform_cross_directory.dart'; | ||
| export 'src/platform_cross_entity.dart'; | ||
| export 'src/platform_cross_file.dart'; | ||
| export 'src/scoped_storage/platform_scoped_storage_cross_directory.dart'; | ||
| export 'src/scoped_storage/platform_scoped_storage_cross_file.dart'; |
161 changes: 161 additions & 0 deletions
161
packages/cross_file/cross_file_platform_interface/lib/src/cross_file_platform.dart
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'dart:convert'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'file_system/platform_file_system_cross_directory.dart'; | ||
| import 'file_system/platform_file_system_cross_file.dart'; | ||
| import 'platform_cross_directory.dart'; | ||
| import 'platform_cross_entity.dart'; | ||
| import 'scoped_storage/platform_scoped_storage_cross_directory.dart'; | ||
| import 'scoped_storage/platform_scoped_storage_cross_file.dart'; | ||
|
|
||
| /// Interface for a platform implementation of `cross_file`. | ||
| abstract base class CrossFilePlatform { | ||
| /// The instance of [CrossFilePlatform] to be used. | ||
| /// | ||
| /// Platform implementations packages should set this with their own | ||
| /// implementation of [CrossFilePlatform] when they register themselves. | ||
| static CrossFilePlatform? instance; | ||
|
|
||
| /// Creates a new [PlatformFileSystemXFile]. | ||
| PlatformFileSystemXFile createPlatformFileSystemXFile( | ||
| PlatformFileSystemXFileCreationParams params, | ||
| ) { | ||
| return _DefaultFileSystemXFile(params); | ||
| } | ||
|
|
||
| /// Creates a new [PlatformFileSystemXDirectory]. | ||
| PlatformFileSystemXDirectory createPlatformFileSystemXDirectory( | ||
| PlatformFileSystemXDirectoryCreationParams params, | ||
| ) { | ||
| return _DefaultFileSystemXDirectory(params); | ||
| } | ||
|
|
||
| /// Creates a new [PlatformScopedStorageXFile]. | ||
| PlatformScopedStorageXFile createPlatformScopedStorageXFile( | ||
| PlatformScopedStorageXFileCreationParams params, | ||
| ) { | ||
| return _DefaultScopedStorageXFile(params); | ||
| } | ||
|
|
||
| /// Creates a new [PlatformScopedStorageXDirectory]. | ||
| PlatformScopedStorageXDirectory createPlatformScopedStorageXDirectory( | ||
| PlatformScopedStorageXDirectoryCreationParams params, | ||
| ) { | ||
| return _DefaultScopedStorageXDirectory(params); | ||
| } | ||
| } | ||
|
|
||
| /// Implementation of [PlatformFileSystemXFile] that represents a resource that | ||
| /// does not exist. | ||
| final class _DefaultFileSystemXFile extends PlatformFileSystemXFile { | ||
| _DefaultFileSystemXFile(super.params) : super.implementation(); | ||
|
|
||
| @override | ||
| Future<bool> exists() async => false; | ||
|
|
||
| @override | ||
| Future<DateTime?> lastModified() async => null; | ||
|
|
||
| @override | ||
| Future<int?> length() async => null; | ||
|
|
||
| @override | ||
| Future<String?> name() async => null; | ||
|
|
||
| @override | ||
| Stream<Uint8List> openRead([int? start, int? end]) async* { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<Uint8List> readAsBytes() { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<String> readAsString({Encoding encoding = utf8}) { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<PlatformFileSystemXFile> writeAsBytes(PlatformWriteAsBytesParams params) { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
| } | ||
|
|
||
| /// Implementation of [PlatformFileSystemXDirectory] that represents a directory | ||
| /// that does not exist. | ||
| final class _DefaultFileSystemXDirectory extends PlatformFileSystemXDirectory { | ||
| _DefaultFileSystemXDirectory(super.params) : super.implementation(); | ||
|
|
||
| @override | ||
| Future<bool> exists() async => false; | ||
|
|
||
| @override | ||
| Stream<PlatformXEntity> list(PlatformListParams params) async* { | ||
| throw UnsupportedError('This instance does not represent any directory.'); | ||
| } | ||
| } | ||
|
|
||
| /// Implementation of [PlatformScopedStorageXFile] that represents a resource | ||
| /// that does not exist. | ||
| final class _DefaultScopedStorageXFile extends PlatformScopedStorageXFile { | ||
| _DefaultScopedStorageXFile(super.params) : super.implementation(); | ||
|
|
||
| @override | ||
| Future<bool> canRead() async => false; | ||
|
|
||
| @override | ||
| Future<bool> exists() async => false; | ||
|
|
||
| @override | ||
| Future<DateTime?> lastModified() async => null; | ||
|
|
||
| @override | ||
| Future<int?> length() async => null; | ||
|
|
||
| @override | ||
| Future<String?> name() async => null; | ||
|
|
||
| @override | ||
| Stream<Uint8List> openRead([int? start, int? end]) async* { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<Uint8List> readAsBytes() { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<String> readAsString({Encoding encoding = utf8}) { | ||
| throw UnsupportedError('This instance does not represent any resource.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> dispose() async {} | ||
| } | ||
|
|
||
| /// Implementation of [PlatformScopedStorageXDirectory] that represents a | ||
| /// directory that does not exist. | ||
| final class _DefaultScopedStorageXDirectory extends PlatformScopedStorageXDirectory { | ||
| _DefaultScopedStorageXDirectory(super.params) : super.implementation(); | ||
|
|
||
| @override | ||
| Future<bool> exists() async => false; | ||
|
|
||
| @override | ||
| Future<bool> canRead() async => false; | ||
|
|
||
| @override | ||
| Stream<PlatformXEntity> list(PlatformListParams params) async* { | ||
| throw UnsupportedError('This instance does not represent any directory.'); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> dispose() async {} | ||
| } |
110 changes: 110 additions & 0 deletions
110
...oss_file_platform_interface/lib/src/file_system/platform_file_system_cross_directory.dart
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // Copyright 2013 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/foundation.dart'; | ||
|
|
||
| import '../cross_file_platform.dart'; | ||
| import '../platform_cross_directory.dart'; | ||
|
|
||
| /// Object specifying creation parameters for creating a [PlatformFileSystemXDirectory]. | ||
| /// | ||
| /// Platform-specific implementations can add additional fields by extending | ||
| /// this class. | ||
| /// | ||
| /// This example demonstrates how to extend the [PlatformFileSystemXDirectoryCreationParams] to | ||
| /// provide additional platform-specific parameters. | ||
| /// | ||
| /// When extending [PlatformFileSystemXDirectoryCreationParams] additional parameters | ||
| /// should always accept `null` or have a default value to prevent breaking | ||
| /// changes. | ||
| /// | ||
| /// ```dart | ||
| /// base class AndroidFileSystemXDirectoryCreationParams | ||
| /// extends PlatformFileSystemXDirectoryCreationParams { | ||
| /// AndroidFileSystemXDirectoryCreationParams({required super.uri, this.platformValue}); | ||
| /// | ||
| /// factory AndroidFileSystemXDirectoryCreationParams.fromCreationParams( | ||
| /// PlatformFileSystemXDirectoryCreationParams params, { | ||
| /// Object? platformValue, | ||
| /// }) { | ||
| /// return AndroidFileSystemXDirectoryCreationParams( | ||
| /// uri: params.uri, | ||
| /// platformValue: platformValue, | ||
| /// ); | ||
| /// } | ||
| /// | ||
| /// final Object? platformValue; | ||
| /// } | ||
| /// ``` | ||
| @immutable | ||
| base class PlatformFileSystemXDirectoryCreationParams extends PlatformXDirectoryCreationParams { | ||
| /// Constructs a [PlatformFileSystemXDirectoryCreationParams]. | ||
| PlatformFileSystemXDirectoryCreationParams(this.path) | ||
| : super( | ||
| uri: Uri.directory( | ||
| path, | ||
| windows: defaultTargetPlatform == TargetPlatform.windows, | ||
| ).toString(), | ||
| ); | ||
|
|
||
| /// The path of the directory. | ||
| final String path; | ||
| } | ||
|
|
||
| /// Base mixin used to provide platform-specific features for implementations of | ||
| /// [PlatformFileSystemXDirectory]. | ||
| /// | ||
| /// When providing platform specific features, platform implementations are | ||
| /// expected to declare a mixin that implements this mixin and return an | ||
| /// instance with [PlatformFileSystemXDirectory.extension]. | ||
| /// | ||
| /// ```dart | ||
| /// base class AndroidFileSystemXDirectory extends PlatformFileSystemXDirectory with AndroidFileSystemXDirectoryExtension { | ||
| /// // ... | ||
| /// @override | ||
| /// PlatformFileSystemXDirectoryExtension? get extension => this; | ||
| /// | ||
| /// Future<void> platformMethod() { | ||
| /// // ... | ||
| /// } | ||
| /// } | ||
| /// | ||
| /// mixin AndroidFileSystemXDirectoryExtension implements PlatformFileSystemXDirectoryExtension { | ||
| /// Future<void> platformMethod(); | ||
| /// } | ||
| /// ``` | ||
| mixin PlatformFileSystemXDirectoryExtension implements PlatformXDirectoryExtension {} | ||
|
|
||
| /// Interface for a reference to a directory (or folder) on the file system. | ||
| abstract base class PlatformFileSystemXDirectory extends PlatformXDirectory { | ||
| /// Creates a new [PlatformFileSystemXDirectory] | ||
| factory PlatformFileSystemXDirectory(PlatformFileSystemXDirectoryCreationParams params) { | ||
| assert( | ||
| CrossFilePlatform.instance != null, | ||
| 'A platform implementation for `cross_file` has not been set. Please ' | ||
| 'ensure that an implementation of `CrossFilePlatform` has been set to ' | ||
| '`CrossFilePlatform.instance` before use. For unit testing, ' | ||
| '`CrossFilePlatform.instance` can be set with your own test implementation.', | ||
| ); | ||
| return CrossFilePlatform.instance!.createPlatformFileSystemXDirectory(params); | ||
| } | ||
|
|
||
| /// Used by the platform implementation to create a new | ||
| /// [PlatformFileSystemXDirectory]. | ||
| /// | ||
| /// Should only be used by platform implementations because they can't extend | ||
| /// a class that only contains a factory constructor. | ||
| @protected | ||
| PlatformFileSystemXDirectory.implementation( | ||
| PlatformFileSystemXDirectoryCreationParams super.params, | ||
| ); | ||
|
|
||
| @override | ||
| PlatformFileSystemXDirectoryCreationParams get params => | ||
| super.params as PlatformFileSystemXDirectoryCreationParams; | ||
|
|
||
| /// Extension for providing platform-specific features. | ||
| @override | ||
| PlatformFileSystemXDirectoryExtension? get extension => null; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.