From 6cfa862b304ad2bc17a1901527b6171374545360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wr=C3=B3blewski?= Date: Fri, 1 Sep 2023 20:46:59 +0200 Subject: [PATCH] AGP 8, Flutter 3, Dart 3 support --- android/build.gradle | 15 +++++++---- example/android/app/build.gradle | 15 +++++++---- .../android/app/src/main/AndroidManifest.xml | 26 +++++++++++------- .../imagecropexample/MainActivity.java | 13 --------- .../marcin/imagecropexample/MainActivity.java | 4 +++ .../app/src/main/res/values/styles.xml | 5 ++++ example/android/build.gradle | 8 +++--- example/android/gradle.properties | 5 ++++ .../gradle/wrapper/gradle-wrapper.properties | 3 +-- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Flutter/Flutter.podspec | 12 ++++----- example/ios/Podfile | 2 +- example/ios/Runner.xcodeproj/project.pbxproj | 11 +++++--- example/ios/Runner/Info.plist | 4 +++ example/lib/main.dart | 27 ++++++++++--------- example/pubspec.yaml | 5 ++-- lib/image_crop_plus.dart | 2 -- lib/src/crop.dart | 7 ++--- lib/src/image_crop_plus.dart | 2 +- pubspec.yaml | 2 +- 20 files changed, 97 insertions(+), 73 deletions(-) delete mode 100755 example/android/app/src/main/java/com/lykhonis/imagecropexample/MainActivity.java create mode 100755 example/android/app/src/main/java/eu/wroblewscy/marcin/imagecropexample/MainActivity.java diff --git a/android/build.gradle b/android/build.gradle index 9c73bf0..4115ca9 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -4,25 +4,30 @@ version '1.0-SNAPSHOT' buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:7.4.2' } } rootProject.allprojects { repositories { google() - jcenter() + mavenCentral() } } apply plugin: 'com.android.library' android { - compileSdkVersion 28 + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'eu.wroblewscy.marcin.imagecrop' + } + + compileSdkVersion 33 defaultConfig { minSdkVersion 16 @@ -34,5 +39,5 @@ android { } dependencies { - implementation 'androidx.exifinterface:exifinterface:1.0.0' + implementation 'androidx.exifinterface:exifinterface:1.3.6' } diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 64f9d21..05d8e1c 100755 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -25,17 +25,19 @@ apply plugin: 'com.android.application' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 28 - - lintOptions { - disable 'InvalidPackage' + // Conditional for compatibility with AGP <4.2. + if (project.android.hasProperty("namespace")) { + namespace 'eu.wroblewscy.marcin.imagecropexample' } + compileSdkVersion 33 + + defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "eu.wroblewscy.marcin.imagecropexample" minSdkVersion 16 - targetSdkVersion 28 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -48,6 +50,9 @@ android { signingConfig signingConfigs.debug } } + lint { + disable 'InvalidPackage' + } } flutter { diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index cf33cce..5139be9 100755 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + - + android:windowSoftInputMode="adjustResize" + android:exported="true"> + + + android:name="io.flutter.embedding.android.SplashScreenDrawable" + android:resource="@drawable/launch_background" /> + + + + diff --git a/example/android/app/src/main/java/com/lykhonis/imagecropexample/MainActivity.java b/example/android/app/src/main/java/com/lykhonis/imagecropexample/MainActivity.java deleted file mode 100755 index a0da4be..0000000 --- a/example/android/app/src/main/java/com/lykhonis/imagecropexample/MainActivity.java +++ /dev/null @@ -1,13 +0,0 @@ -package eu.wroblewscy.marcin.imagecropexample; - -import android.os.Bundle; -import io.flutter.app.FlutterActivity; -import io.flutter.plugins.GeneratedPluginRegistrant; - -public class MainActivity extends FlutterActivity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - GeneratedPluginRegistrant.registerWith(this); - } -} diff --git a/example/android/app/src/main/java/eu/wroblewscy/marcin/imagecropexample/MainActivity.java b/example/android/app/src/main/java/eu/wroblewscy/marcin/imagecropexample/MainActivity.java new file mode 100755 index 0000000..a5b0396 --- /dev/null +++ b/example/android/app/src/main/java/eu/wroblewscy/marcin/imagecropexample/MainActivity.java @@ -0,0 +1,4 @@ +package eu.wroblewscy.marcin.imagecropexample; + +import io.flutter.embedding.android.FlutterActivity; +public class MainActivity extends FlutterActivity { } diff --git a/example/android/app/src/main/res/values/styles.xml b/example/android/app/src/main/res/values/styles.xml index 00fa441..65df8e0 100755 --- a/example/android/app/src/main/res/values/styles.xml +++ b/example/android/app/src/main/res/values/styles.xml @@ -5,4 +5,9 @@ Flutter draws its first frame --> @drawable/launch_background + diff --git a/example/android/build.gradle b/example/android/build.gradle index 1b33616..de36c4b 100755 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,18 +1,18 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:7.4.2' } } allprojects { repositories { google() - jcenter() + mavenCentral() } } @@ -24,6 +24,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register('clean', Delete) { delete rootProject.buildDir } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 8bd86f6..0c0f4ce 100755 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1 +1,6 @@ +android.defaults.buildfeatures.buildconfig=true +android.nonFinalResIds=false +android.nonTransitiveRClass=false org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 6f68eed..8049c68 100755 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Jun 01 05:20:09 PDT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 8d4492f..9625e10 100755 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 9.0 + 11.0 diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec index 663d5b2..29758b7 100644 --- a/example/ios/Flutter/Flutter.podspec +++ b/example/ios/Flutter/Flutter.podspec @@ -1,17 +1,17 @@ # -# NOTE: This podspec is NOT to be published. It is only used as a local source! -# This is a generated file; do not edit or check into version control. +# This podspec is NOT to be published. It is only used as a local source! +# This is a generated file; do not edit or check into version control. # Pod::Spec.new do |s| s.name = 'Flutter' s.version = '1.0.0' - s.summary = 'High-performance, high-fidelity mobile apps.' - s.homepage = 'https://flutter.io' - s.license = { :type => 'MIT' } + s.summary = 'A UI toolkit for beautiful and fast apps.' + s.homepage = 'https://flutter.dev' + s.license = { :type => 'BSD' } s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } - s.ios.deployment_target = '9.0' + s.ios.deployment_target = '11.0' # Framework linking is handled by Flutter tooling, not CocoaPods. # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. s.vendored_frameworks = 'path/to/nothing' diff --git a/example/ios/Podfile b/example/ios/Podfile index f7d6a5e..d207307 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '9.0' +# platform :ios, '11.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 03e284a..9e3d5e9 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -164,7 +164,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0910; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = "The Chromium Authors"; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -227,10 +227,12 @@ }; 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -241,6 +243,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -333,7 +336,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -380,7 +383,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index d113f18..94a8473 100755 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -45,5 +45,9 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/main.dart b/example/lib/main.dart index 703da3f..469b993 100755 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -24,9 +24,9 @@ class MyApp extends StatefulWidget { class _MyAppState extends State { final cropKey = GlobalKey(); - File _file; - File _sample; - File _lastCropped; + File? _file; + File? _sample; + File? _lastCropped; @override void dispose() { @@ -59,7 +59,7 @@ class _MyAppState extends State { children: [ Expanded( child: Crop.file( - _sample, + _sample!, key: cropKey, ), ), @@ -74,8 +74,8 @@ class _MyAppState extends State { 'Crop Image', style: Theme.of(context) .textTheme - .button - .copyWith(color: Colors.white), + .labelLarge + ?.copyWith(color: Colors.white), ), onPressed: () => _cropImage(), ), @@ -91,7 +91,10 @@ class _MyAppState extends State { return TextButton( child: Text( 'Open Image', - style: Theme.of(context).textTheme.button.copyWith(color: Colors.white), + style: Theme.of(context) + .textTheme + .labelLarge + ?.copyWith(color: Colors.white), ), onPressed: () => _openImage(), ); @@ -100,10 +103,10 @@ class _MyAppState extends State { Future _openImage() async { final pickedFile = await ImagePicker().getImage(source: ImageSource.gallery); - final file = File(pickedFile.path); + final file = File(pickedFile!.path); final sample = await ImageCrop.sampleImage( file: file, - preferredSize: context.size.longestSide.toInt() * 2, + preferredSize: context.size!.longestSide.toInt() * 2, ); _sample?.delete(); @@ -116,8 +119,8 @@ class _MyAppState extends State { } Future _cropImage() async { - final scale = cropKey.currentState.scale; - final area = cropKey.currentState.area; + final scale = cropKey.currentState!.scale; + final area = cropKey.currentState!.area; if (area == null) { // cannot crop, widget is not setup return; @@ -126,7 +129,7 @@ class _MyAppState extends State { // scale up to use maximum possible number of pixels // this will sample image in higher resolution to make cropped image larger final sample = await ImageCrop.sampleImage( - file: _file, + file: _file!, preferredSize: (2000 / scale).round(), ); diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 49e6e71..a53efe1 100755 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,16 +1,15 @@ name: image_crop_plus_example description: Demonstrates how to use the image_crop_plus plugin. -version: 1.0.0+1 +version: 2.0.0 environment: - sdk: ">=2.0.0-dev.68.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: flutter: sdk: flutter - cupertino_icons: ^0.1.3 image_picker: ^0.7.4 dev_dependencies: diff --git a/lib/image_crop_plus.dart b/lib/image_crop_plus.dart index a6d55d0..251ffd3 100755 --- a/lib/image_crop_plus.dart +++ b/lib/image_crop_plus.dart @@ -5,8 +5,6 @@ import 'dart:io'; import 'dart:math'; import 'dart:ui' as ui; -import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter/services.dart'; diff --git a/lib/src/crop.dart b/lib/src/crop.dart index 75d27b5..4feba3c 100755 --- a/lib/src/crop.dart +++ b/lib/src/crop.dart @@ -17,6 +17,7 @@ const _kSettleAnimationDuration = const Duration(seconds: 1); const _kSettleAnimationCurve = Curves.fastLinearToSlowEaseIn; enum _CropAction { none, moving, cropping, scaling } + enum _CropHandleSide { none, topLeft, @@ -75,7 +76,7 @@ class Crop extends StatefulWidget { context.findAncestorStateOfType(); } -class CropState extends State with TickerProviderStateMixin, Drag { +class CropState extends State with TickerProviderStateMixin { final _surfaceKey = GlobalKey(); late final AnimationController _activeController; @@ -311,7 +312,7 @@ class CropState extends State with TickerProviderStateMixin, Drag { } void _updateImage(ImageInfo imageInfo, bool synchronousCall) { - WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { + WidgetsBinding.instance.addPostFrameCallback((timeStamp) { final boundaries = _boundaries; if (boundaries == null) { return; @@ -347,7 +348,7 @@ class CropState extends State with TickerProviderStateMixin, Drag { }); }); - WidgetsBinding.instance?.ensureVisualUpdate(); + WidgetsBinding.instance.ensureVisualUpdate(); } _CropHandleSide _hitCropHandle(Offset? localPoint) { diff --git a/lib/src/image_crop_plus.dart b/lib/src/image_crop_plus.dart index b317a04..e00f423 100755 --- a/lib/src/image_crop_plus.dart +++ b/lib/src/image_crop_plus.dart @@ -10,7 +10,7 @@ class ImageOptions { }); @override - int get hashCode => hashValues(width, height); + int get hashCode => Object.hash(width, height); @override bool operator ==(other) => diff --git a/pubspec.yaml b/pubspec.yaml index 1dd90ec..d35a0fa 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.6.1 homepage: https://github.com/wrbl606/image_crop environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ">=3.0.0 <4.0.0" flutter: ">=1.12.13+hotfix.6" dependencies: