From bb64f705ac92800209c9eeb0ec488fb70001f21d Mon Sep 17 00:00:00 2001 From: Johannes Fahrenkrug Date: Wed, 9 Oct 2024 13:41:58 +0200 Subject: [PATCH] chore: Update Android gradle config, resolve some linting issues (#67) Followed this guide to update Android gradle config to new recommended settings: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply Updated sdk version in example app's pubspec. Fixed some linting issues after locally updating the flutter_lints package to 5.0.0, most notably using super parameters. However, that change to use version 5.0.0 could not be committed because we still support Dart 2.19, which is tied to flutter_lints 2.0.3. --- example/android/app/build.gradle | 19 ++++-------- example/android/build.gradle | 13 -------- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle | 30 ++++++++++++++----- example/lib/async_demo_page.dart | 4 +-- example/lib/main.dart | 8 ++--- example/pubspec.yaml | 2 +- lib/easy_image_viewer.dart | 2 +- lib/src/easy_image_view.dart | 4 +-- lib/src/easy_image_view_pager.dart | 4 +-- .../easy_image_viewer_dismissible_dialog.dart | 5 ++-- 11 files changed, 43 insertions(+), 50 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 6e0cebe..3732810 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,10 +22,6 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { compileSdkVersion flutter.compileSdkVersion @@ -62,7 +59,3 @@ android { flutter { source '../..' } - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} diff --git a/example/android/build.gradle b/example/android/build.gradle index 0a2d6a1..bc157bd 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,16 +1,3 @@ -buildscript { - ext.kotlin_version = '1.6.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58a..cfe88f6 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bc..7d06449 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "7.3.0" apply false + id "org.jetbrains.kotlin.android" version "1.7.10" apply false +} + +include ":app" \ No newline at end of file diff --git a/example/lib/async_demo_page.dart b/example/lib/async_demo_page.dart index c4ae40b..f9c862f 100644 --- a/example/lib/async_demo_page.dart +++ b/example/lib/async_demo_page.dart @@ -3,10 +3,10 @@ import 'package:flutter/material.dart'; /// Simple example of how to use EasyImageViewer with a FutureBuilder class AsyncDemoPage extends StatefulWidget { - const AsyncDemoPage({Key? key}) : super(key: key); + const AsyncDemoPage({super.key}); @override - _AsyncDemoPageState createState() => _AsyncDemoPageState(); + State createState() => _AsyncDemoPageState(); } class _AsyncDemoPageState extends State { diff --git a/example/lib/main.dart b/example/lib/main.dart index 1b941e6..5a2727b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { @@ -25,12 +25,12 @@ class MyHomePage extends StatefulWidget { final String title; const MyHomePage({ - Key? key, + super.key, required this.title, - }) : super(key: key); + }); @override - _MyHomePageState createState() => _MyHomePageState(); + State createState() => _MyHomePageState(); } class _MyHomePageState extends State { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 52027ad..156323f 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: ">=2.16.1 <3.0.0" + sdk: ">=2.19.0 <4.0.0" # This implies at least Dart 2.19, which comes with Flutter 3.7.0 # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions diff --git a/lib/easy_image_viewer.dart b/lib/easy_image_viewer.dart index d772f47..a23a097 100644 --- a/lib/easy_image_viewer.dart +++ b/lib/easy_image_viewer.dart @@ -1,6 +1,6 @@ /// A library to easily display images in a full-screen dialog. /// It supports pinch & zoom, and paging through multiple images. -library easy_image_viewer; +library; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; diff --git a/lib/src/easy_image_view.dart b/lib/src/easy_image_view.dart index db504c1..50907d4 100644 --- a/lib/src/easy_image_view.dart +++ b/lib/src/easy_image_view.dart @@ -39,12 +39,12 @@ class EasyImageView extends StatefulWidget { /// The optional [doubleTapZoomable] boolean defaults to false and allows double tap to zoom. const EasyImageView.imageWidget( this.imageWidget, { - Key? key, + super.key, this.minScale = 1.0, this.maxScale = 5.0, this.doubleTapZoomable = false, this.onScaleChanged, - }) : super(key: key); + }); @override State createState() => _EasyImageViewState(); diff --git a/lib/src/easy_image_view_pager.dart b/lib/src/easy_image_view_pager.dart index aa23ccf..8cace8b 100644 --- a/lib/src/easy_image_view_pager.dart +++ b/lib/src/easy_image_view_pager.dart @@ -27,13 +27,13 @@ class EasyImageViewPager extends StatefulWidget { /// and the [pageController] to control the initial image index to display. /// The optional [doubleTapZoomable] boolean defaults to false and allows double tap to zoom. const EasyImageViewPager({ - Key? key, + super.key, required this.easyImageProvider, required this.pageController, this.doubleTapZoomable = false, this.onScaleChanged, this.infinitelyScrollable = false, - }) : super(key: key); + }); @override State createState() => _EasyImageViewPagerState(); diff --git a/lib/src/easy_image_viewer_dismissible_dialog.dart b/lib/src/easy_image_viewer_dismissible_dialog.dart index 7832591..01d5f99 100644 --- a/lib/src/easy_image_viewer_dismissible_dialog.dart +++ b/lib/src/easy_image_viewer_dismissible_dialog.dart @@ -22,7 +22,7 @@ class EasyImageViewerDismissibleDialog extends StatefulWidget { /// Refer to [showImageViewerPager] for the arguments const EasyImageViewerDismissibleDialog(this.imageProvider, - {Key? key, + {super.key, this.immersive = true, this.onPageChanged, this.onViewerDismissed, @@ -31,8 +31,7 @@ class EasyImageViewerDismissibleDialog extends StatefulWidget { this.infinitelyScrollable = false, required this.backgroundColor, required this.closeButtonTooltip, - required this.closeButtonColor}) - : super(key: key); + required this.closeButtonColor}); @override State createState() =>