This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[cross_file] Migrate to null-safety. #3452
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
dea2935
[cross_file] Migrate to null-safety.
ditman 5281ca0
Address PR feedback.
ditman 31f16de
Remove tests from stable
ditman 23fdd1c
Format changelog
ditman 4ae4755
Skip platform_interface packages
ditman 5f649cb
Exclude some more pkgs
ditman fb59b3f
Get the build going in stable
ditman be62759
Undo some changes that are not needed.
ditman 393b8ce
Merge branch 'master' into cross-file-null-safe
ditman 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
Next
Next commit
[cross_file] Migrate to null-safety.
- Loading branch information
commit dea2935d63f81e219f526c9e975a21cf211415b6
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
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
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 |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ | |
| import 'dart:convert'; | ||
| import 'dart:typed_data'; | ||
|
|
||
| import 'package:http/http.dart' as http show readBytes; | ||
|
Member
Author
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. No null-safe version of |
||
| import 'package:meta/meta.dart'; | ||
| import 'dart:html'; | ||
|
|
||
|
|
@@ -16,16 +15,17 @@ import './base.dart'; | |
| /// | ||
| /// It wraps the bytes of a selected file. | ||
| class XFile extends XFileBase { | ||
| String path; | ||
| late String? path; | ||
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| final String mimeType; | ||
| final Uint8List _data; | ||
| final int _length; | ||
| final String name; | ||
| final DateTime _lastModified; | ||
| Element _target; | ||
| final String? mimeType; | ||
| final Uint8List? _data; | ||
| final int? _length; | ||
| final String? name; | ||
| final DateTime? _lastModified; | ||
|
|
||
| final CrossFileTestOverrides _overrides; | ||
| late Element _target; | ||
|
|
||
| final CrossFileTestOverrides? _overrides; | ||
|
|
||
| bool get _hasTestOverrides => _overrides != null; | ||
|
|
||
|
|
@@ -40,10 +40,10 @@ class XFile extends XFileBase { | |
| this.path, { | ||
| this.mimeType, | ||
| this.name, | ||
| int length, | ||
| Uint8List bytes, | ||
| DateTime lastModified, | ||
| @visibleForTesting CrossFileTestOverrides overrides, | ||
| int? length, | ||
| Uint8List? bytes, | ||
| DateTime? lastModified, | ||
| @visibleForTesting CrossFileTestOverrides? overrides, | ||
| }) : _data = bytes, | ||
| _length = length, | ||
| _overrides = overrides, | ||
|
|
@@ -55,10 +55,10 @@ class XFile extends XFileBase { | |
| Uint8List bytes, { | ||
| this.mimeType, | ||
| this.name, | ||
| int length, | ||
| DateTime lastModified, | ||
| int? length, | ||
| DateTime? lastModified, | ||
| this.path, | ||
| @visibleForTesting CrossFileTestOverrides overrides, | ||
| @visibleForTesting CrossFileTestOverrides? overrides, | ||
| }) : _data = bytes, | ||
| _length = length, | ||
| _overrides = overrides, | ||
|
|
@@ -72,17 +72,20 @@ class XFile extends XFileBase { | |
|
|
||
| @override | ||
| Future<DateTime> lastModified() async { | ||
| if (_lastModified != null) { | ||
| return Future.value(_lastModified); | ||
| } | ||
| return null; | ||
| return Future.value(_lastModified); | ||
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| Future<Uint8List> get _bytes async { | ||
| if (_data != null) { | ||
| return Future.value(UnmodifiableUint8ListView(_data)); | ||
| return Future.value(UnmodifiableUint8ListView(_data!)); | ||
| } | ||
| return http.readBytes(path); | ||
|
|
||
| // We can force 'response' to be a byte buffer by passing responseType: | ||
| ByteBuffer? response = | ||
| (await HttpRequest.request(path!, responseType: 'arraybuffer')) | ||
| .response; | ||
|
|
||
| return response?.asUint8List() ?? Uint8List(0); | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -101,7 +104,7 @@ class XFile extends XFileBase { | |
| } | ||
|
|
||
| @override | ||
| Stream<Uint8List> openRead([int start, int end]) async* { | ||
| Stream<Uint8List> openRead([int? start, int? end]) async* { | ||
| final bytes = await _bytes; | ||
| yield bytes.sublist(start ?? 0, end ?? bytes.length); | ||
| } | ||
|
|
@@ -114,10 +117,10 @@ class XFile extends XFileBase { | |
|
|
||
| // Create an <a> tag with the appropriate download attributes and click it | ||
| // May be overridden with CrossFileTestOverrides | ||
| final AnchorElement element = | ||
| (_hasTestOverrides && _overrides.createAnchorElement != null) | ||
| ? _overrides.createAnchorElement(this.path, this.name) | ||
| : createAnchorElement(this.path, this.name); | ||
| final AnchorElement element = _hasTestOverrides | ||
| ? _overrides!.createAnchorElement(this.path!, this.name ?? '') | ||
ditman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| as AnchorElement | ||
| : createAnchorElement(this.path!, this.name ?? ''); | ||
|
|
||
| // Clear the children in our container so we can add an element to click | ||
| _target.children.clear(); | ||
|
|
@@ -132,5 +135,5 @@ class CrossFileTestOverrides { | |
| Element Function(String href, String suggestedName) createAnchorElement; | ||
|
|
||
| /// Default constructor for overrides | ||
| CrossFileTestOverrides({this.createAnchorElement}); | ||
| CrossFileTestOverrides({required this.createAnchorElement}); | ||
| } | ||
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
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
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
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 |
|---|---|---|
| @@ -1,19 +1,18 @@ | ||
| name: cross_file | ||
| description: An abstraction to allow working with files across multiple platforms. | ||
| homepage: https://github.com/flutter/plugins/tree/master/packages/cross_file | ||
| version: 0.2.0 | ||
| version: 0.3.0-nullsafety | ||
|
|
||
| dependencies: | ||
| flutter: | ||
| sdk: flutter | ||
| http: ^0.12.0+1 | ||
| meta: ^1.0.5 | ||
| meta: ^1.3.0-nullsafety.6 | ||
|
|
||
| dev_dependencies: | ||
| flutter_test: | ||
| sdk: flutter | ||
| pedantic: ^1.8.0 | ||
| pedantic: ^1.10.0-nullsafety.3 | ||
|
|
||
| environment: | ||
| sdk: ">=2.1.0 <3.0.0" | ||
| sdk: ">=2.12.0-0 <3.0.0" | ||
| flutter: ">=1.22.0" |
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
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
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.