Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Add null safety to library and example
Browse files Browse the repository at this point in the history
  • Loading branch information
percula committed Mar 12, 2021
1 parent 97a2596 commit 7278fb6
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 71 deletions.
16 changes: 9 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,25 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
String heicUrl = 'https://filesamples.com/samples/image/heic/sample1.heic';
String jpeg;
String? jpeg;
bool initialized = false;

// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
if (initialized) return;
initialized = true;
WidgetsBinding.instance.addPostFrameCallback((Duration timeStamp) async {
String tmp = await showDialog(
context: context, child: FutureProgressDialog(downloadAndConvert()));
WidgetsBinding.instance!.addPostFrameCallback((Duration timeStamp) async {
String? tmp = await showDialog(
builder: (context) => FutureProgressDialog(downloadAndConvert()),
context: context,
);
setState(() {
jpeg = tmp;
});
});
}

Future<String> downloadAndConvert() async {
Future<String?> downloadAndConvert() async {
File heicFile = await _downloadFile(heicUrl, 'a.heic');
String convertedPath = (await getTemporaryDirectory()).path + "/b.heic";
return HeicToJpg.convert(heicFile.path, jpgPath: convertedPath);
Expand All @@ -47,8 +49,8 @@ class _MyAppState extends State<MyApp> {
title: const Text('Plugin example app'),
),
body: Center(
child: (jpeg != null && jpeg.isNotEmpty)
? Image.file(File(jpeg))
child: (jpeg != null && jpeg!.isNotEmpty)
? Image.file(File(jpeg!))
: Text('No Image'),
),
);
Expand Down
104 changes: 73 additions & 31 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,63 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.5.0-nullsafety.1"
version: "2.5.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
characters:
dependency: transitive
description:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.3"
version: "1.1.0"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
clock:
dependency: transitive
description:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0-nullsafety.3"
cupertino_icons:
dependency: "direct main"
version: "1.15.0"
fake_async:
dependency: transitive
description:
name: cupertino_icons
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.3"
fake_async:
version: "1.2.0"
ffi:
dependency: transitive
description:
name: fake_async
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
file:
dependency: transitive
description:
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "6.1.0"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -87,56 +94,77 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10-nullsafety.1"
version: "0.12.10"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.1"
version: "1.8.0"
path_provider:
dependency: "direct main"
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.8"
version: "2.0.1"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4+2"
version: "2.0.0"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "2.0.1"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
version: "3.0.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "2.0.0"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -148,56 +176,70 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0-nullsafety.2"
version: "1.8.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
version: "1.10.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.1"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0-nullsafety.1"
version: "1.1.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
version: "1.2.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19-nullsafety.2"
version: "0.2.19"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0-nullsafety.3"
version: "2.1.0"
win32:
dependency: transitive
description:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
dart: ">=2.12.0 <3.0.0"
flutter: ">=2.0.0"
10 changes: 3 additions & 7 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ publish_to: 'none'


environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
path_provider: ^1.6.8

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
path_provider: ^2.0.1

dev_dependencies:
flutter_test:
Expand All @@ -22,7 +18,7 @@ dev_dependencies:
heic_to_jpg:
path: ../

future_progress_dialog: ^0.1.1
future_progress_dialog: ^0.1.1 # Not null safe, so need to run example with flutter run --no-sound-null-safety

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
2 changes: 1 addition & 1 deletion example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main() {
expect(
find.byWidgetPredicate(
(Widget widget) => widget is Text &&
widget.data.startsWith('Running on:'),
widget.data!.startsWith('Running on:'),
),
findsOneWidget,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/heic_to_jpg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class HeicToJpg {
/// Get [heicPath] path as an input and return [jpg] path.
/// You can set [jpgPath] if you want to set the output file path.
/// If you don't set it the output file path is made in cache directory of each platform.
static Future<String> convert(String heicPath, {String jpgPath}) async {
final String jpg = await _channel
static Future<String?> convert(String heicPath, {String? jpgPath}) async {
final String? jpg = await _channel
.invokeMethod('convert', {"heicPath": heicPath, "jpgPath": jpgPath});
return jpg;
}
Expand Down
Loading

0 comments on commit 7278fb6

Please sign in to comment.