From 0f0c36e3d231e285ab05c0d0023528a1d72dab96 Mon Sep 17 00:00:00 2001 From: aman Date: Sat, 25 Sep 2021 00:22:56 +0530 Subject: [PATCH] made it null safety --- example/.flutter-plugins-dependencies | 1 + example/ios/Flutter/Debug.xcconfig | 1 + example/ios/Flutter/Release.xcconfig | 1 + .../ios/Flutter/flutter_export_environment.sh | 14 +++++++ example/ios/Podfile | 38 +++++++++++++++++++ example/lib/main.dart | 13 ++++--- lib/thumbnails.dart | 14 +++---- lib/validators.dart | 9 ++--- pubspec.yaml | 4 +- 9 files changed, 75 insertions(+), 20 deletions(-) create mode 100644 example/.flutter-plugins-dependencies create mode 100755 example/ios/Flutter/flutter_export_environment.sh create mode 100644 example/ios/Podfile diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies new file mode 100644 index 0000000..a8666c1 --- /dev/null +++ b/example/.flutter-plugins-dependencies @@ -0,0 +1 @@ +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"thumbnails","path":"/Users/Macky/Downloads/Flutter_Thumbnails/","dependencies":[]}],"android":[{"name":"thumbnails","path":"/Users/Macky/Downloads/Flutter_Thumbnails/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"thumbnails","dependencies":[]}],"date_created":"2021-09-25 00:21:14.941774","version":"2.2.3"} \ No newline at end of file diff --git a/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/example/ios/Flutter/Debug.xcconfig +++ b/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/example/ios/Flutter/Release.xcconfig +++ b/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..5efcdcb --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/Macky/Macky/applications/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/Macky/Downloads/Flutter_Thumbnails/example" +export "COCOAPODS_PARALLEL_CODE_SIGN=true" +export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=false" +export "TREE_SHAKE_ICONS=false" +export "PACKAGE_CONFIG=.packages" diff --git a/example/ios/Podfile b/example/ios/Podfile new file mode 100644 index 0000000..f7d6a5e --- /dev/null +++ b/example/ios/Podfile @@ -0,0 +1,38 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/example/lib/main.dart b/example/lib/main.dart index ffeeee0..351e2cd 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -12,10 +12,11 @@ class _MyAppState extends State { // Fetch thumbnail and store in a specified output folder void _toUserFolder() async { String thumb = await Thumbnails.getThumbnail( - thumbnailFolder: '/storage/emulated/0/Videos/Thumbnails', - videoFile: '/storage/emulated/0/Videos/Testvideo.mp4', - imageType: ThumbFormat.PNG, - quality: 30); + thumbnailFolder: '/storage/emulated/0/Videos/Thumbnails', + videoFile: '/storage/emulated/0/Videos/Testvideo.mp4', + imageType: ThumbFormat.PNG, + quality: 30, + ); print('path to File: $thumb'); } @@ -38,9 +39,9 @@ class _MyAppState extends State { body: new Center( child: Column( children: [ - RaisedButton( + ElevatedButton( onPressed: _toUserFolder, child: Text('To Specified Folder')), - RaisedButton( + ElevatedButton( onPressed: _noFolder, child: Text('No Folder Specified')), ], ), diff --git a/lib/thumbnails.dart b/lib/thumbnails.dart index dee72a7..9abbc42 100644 --- a/lib/thumbnails.dart +++ b/lib/thumbnails.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:thumbnails/validators.dart'; @@ -8,18 +7,19 @@ enum ThumbFormat { PNG, JPEG, WEBP } class Thumbnails { static const MethodChannel _channel = const MethodChannel('thumbnails'); - static Future getThumbnail( - {@required String videoFile, - String thumbnailFolder, - ThumbFormat imageType, - int quality}) async { + static Future getThumbnail( + {required String videoFile, + String? thumbnailFolder, + ThumbFormat? imageType, + required int? quality}) async { var utilMap = { 'videoFilePath': videoFile, 'thumbFilePath': thumbnailFolder, 'thumbnailFormat': validateType(imageType), 'thumbnailQuality': validateQuality(quality) }; - String thumbnailPath = await _channel.invokeMethod('getThumbnail', utilMap); + String? thumbnailPath = + await _channel.invokeMethod('getThumbnail', utilMap); return thumbnailPath; } } diff --git a/lib/validators.dart b/lib/validators.dart index fb8b286..1f883f5 100644 --- a/lib/validators.dart +++ b/lib/validators.dart @@ -3,23 +3,20 @@ import 'package:thumbnails/thumbnails.dart'; const DEFAULT_THUMB_QUALITY = 50; const DEFAULT_IMAGE_TYPE = ThumbFormat.JPEG; -int validateQuality(int choice) { - if (choice < 10 || choice > 100 || choice == null) +int validateQuality(int? choice) { + if (choice == null || choice < 10 || choice > 100) return DEFAULT_THUMB_QUALITY; return choice; } -int validateType(ThumbFormat type) { +int validateType(ThumbFormat? type) { if (type == null) return 1; switch (type) { case ThumbFormat.JPEG: return 1; - break; case ThumbFormat.PNG: return 2; - break; case ThumbFormat.WEBP: return 3; } - return 1; } diff --git a/pubspec.yaml b/pubspec.yaml index ce8dc6f..2003fa3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ author: AsapJay homepage: https://github.com/asapJ/Flutter_Thumbnails environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: @@ -19,6 +19,8 @@ flutter: plugin: androidPackage: com.asapjay.thumbnails pluginClass: ThumbnailsPlugin +dev_dependencies: + test: ^1.17.12 # To add assets to your plugin package, add an assets section, like this: # assets: