Skip to content
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

💪 null-safety implementation #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.flutter-plugins
.flutter-plugins-dependencies
.dart_tool/package_config.json
.dart_tool/package_config_subset
.dart_tool/version
android/local.properties
android/local.properties
android/local.properties
ios/Flutter/Generated.xcconfig
ios/Runner/GeneratedPluginRegistrant.h
ios/Runner/GeneratedPluginRegistrant.m
ios/Flutter/flutter_export_environment.sh
android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
android/local.properties
.packages
44 changes: 20 additions & 24 deletions lib/picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ class Picker {
///
/// In Android, the MainActivity can be destroyed for various reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
static Future<File> pickImage(
{@required ImageSource source,
double maxWidth,
double maxHeight,
int imageQuality}) async {
assert(source != null);
static Future<File?> pickImage(
{required ImageSource source,
double? maxWidth,
double? maxHeight,
int? imageQuality}) async {
assert(imageQuality == null || (imageQuality >= 0 && imageQuality <= 100));

if (maxWidth != null && maxWidth < 0) {
Expand All @@ -57,7 +56,7 @@ class Picker {
throw ArgumentError.value(maxHeight, 'maxHeight cannot be negative');
}

final String path = await _channel.invokeMethod<String>(
final String? path = await _channel.invokeMethod<String>(
'pickImage',
<String, dynamic>{
'source': source.index,
Expand All @@ -77,11 +76,10 @@ class Picker {
///
/// In Android, the MainActivity can be destroyed for various fo reasons. If that happens, the result will be lost
/// in this call. You can then call [retrieveLostData] when your app relaunches to retrieve the lost data.
static Future<File> pickVideo({
@required ImageSource source,
static Future<File?> pickVideo({
required ImageSource source,
}) async {
assert(source != null);
final String path = await _channel.invokeMethod<String>(
final String? path = await _channel.invokeMethod<String>(
'pickVideo',
<String, dynamic>{
'source': source.index,
Expand All @@ -91,17 +89,15 @@ class Picker {
}

static Future<String> saveFile(
{@required Uint8List fileData, String title, String description}) async {
assert(fileData != null);

String filePath = await _channel.invokeMethod(
{required Uint8List fileData, String? title, String? description}) async {
String filePath = (await _channel.invokeMethod(
'saveFile',
<String, dynamic>{
'fileData': fileData,
'title': title,
'description': description
},
);
))!;
debugPrint("saved filePath:" + filePath);
//process ios return filePath
if (filePath.startsWith("file://")) {
Expand All @@ -124,30 +120,30 @@ class Picker {
/// * [LostDataResponse], for what's included in the response.
/// * [Android Activity Lifecycle](https://developer.android.com/reference/android/app/Activity.html), for more information on MainActivity destruction.
static Future<LostDataResponse> retrieveLostData() async {
final Map<String, dynamic> result =
final Map<String, dynamic>? result =
await _channel.invokeMapMethod<String, dynamic>('retrieve');
if (result == null) {
return LostDataResponse.empty();
}
assert(result.containsKey('path') ^ result.containsKey('errorCode'));

final String type = result['type'];
final String? type = result['type'];
assert(type == kTypeImage || type == kTypeVideo);

RetrieveType retrieveType;
RetrieveType? retrieveType;
if (type == kTypeImage) {
retrieveType = RetrieveType.image;
} else if (type == kTypeVideo) {
retrieveType = RetrieveType.video;
}

PlatformException exception;
PlatformException? exception;
if (result.containsKey('errorCode')) {
exception = PlatformException(
code: result['errorCode'], message: result['errorMessage']);
}

final String path = result['path'];
final String? path = result['path'];

return LostDataResponse(
file: path == null ? null : File(path),
Expand Down Expand Up @@ -182,7 +178,7 @@ class LostDataResponse {
/// The file that was lost in a previous [pickImage] or [pickVideo] call due to MainActivity being destroyed.
///
/// Can be null if [exception] exists.
final File file;
final File? file;

/// The exception of the last [pickImage] or [pickVideo].
///
Expand All @@ -191,10 +187,10 @@ class LostDataResponse {
/// You should handle this exception as if the [pickImage] or [pickVideo] got an exception when the MainActivity was not destroyed.
///
/// Note that it is not the exception that caused the destruction of the MainActivity.
final PlatformException exception;
final PlatformException? exception;

/// Can either be [RetrieveType.image] or [RetrieveType.video];
final RetrieveType type;
final RetrieveType? type;

bool _empty = false;
}
Expand Down
118 changes: 51 additions & 67 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,62 +1,55 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
collection:
version: "1.2.0"
clock:
dependency: transitive
description:
name: collection
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
version: "1.1.0"
collection:
dependency: transitive
description:
name: convert
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: crypto
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "1.2.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -67,55 +60,39 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
image:
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
js:
dependency: transitive
description:
name: image
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "0.6.3"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
version: "1.8.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -127,70 +104,77 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.5"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.11"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0"
video_player:
dependency: "direct dev"
description:
name: video_player
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.1+5"
xml:
version: "2.0.2"
video_player_platform_interface:
dependency: transitive
description:
name: xml
name: video_player_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
version: "4.0.0"
video_player_web:
dependency: transitive
description:
name: video_player_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
sdks:
dart: ">=2.4.0 <3.0.0"
flutter: ">=1.10.0 <2.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
Loading