diff --git a/example/.metadata b/example/.metadata index 005e7c9..128495f 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,7 +4,27 @@ # This file should be version controlled and should not be manually edited. version: - revision: a849daf2836d653ef80e01f428531b3f787671cb - channel: unknown + revision: "d8a9f9a52e5af486f80d932e838ee93861ffd863" + channel: "[user-branch]" project_type: app + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863 + base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863 + - platform: android + create_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863 + base_revision: d8a9f9a52e5af486f80d932e838ee93861ffd863 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/example/android/.gitignore b/example/android/.gitignore index 6f56801..55afd91 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -7,7 +7,7 @@ gradle-wrapper.jar GeneratedPluginRegistrant.java # Remember to never publicly share your keystore. -# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +# See https://flutter.dev/to/reference-keystore key.properties **/*.keystore **/*.jks diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 5fe3c92..27145d6 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,68 +1,44 @@ -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -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' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' +plugins { + id "com.android.application" + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion flutter.compileSdkVersion + namespace = "com.example.flutter_spinbox_example" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } kotlinOptions { - jvmTarget = '1.8' - } - - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + jvmTarget = JavaVersion.VERSION_1_8 } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.example" - minSdkVersion flutter.minSdkVersion - targetSdkVersion flutter.targetSdkVersion - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName + applicationId = "com.example.flutter_spinbox_example" + // You can update the following values to match your application needs. + // For more information, see: https://flutter.dev/to/review-gradle-config. + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig = signingConfigs.debug } } } flutter { - source '../..' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + source = "../.." } diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index c208884..399f698 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,6 +1,6 @@ - - diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 3f41384..1d0d2de 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,13 +1,13 @@ - - + + + + + + + + diff --git a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt deleted file mode 100644 index e793a00..0000000 --- a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.example - -import io.flutter.embedding.android.FlutterActivity - -class MainActivity: FlutterActivity() { -} diff --git a/example/android/app/src/main/kotlin/com/example/flutter_spinbox_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/flutter_spinbox_example/MainActivity.kt new file mode 100644 index 0000000..fd50586 --- /dev/null +++ b/example/android/app/src/main/kotlin/com/example/flutter_spinbox_example/MainActivity.kt @@ -0,0 +1,5 @@ +package com.example.flutter_spinbox_example + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() diff --git a/example/android/app/src/main/res/values-night/styles.xml b/example/android/app/src/main/res/values-night/styles.xml index 3db14bb..06952be 100644 --- a/example/android/app/src/main/res/values-night/styles.xml +++ b/example/android/app/src/main/res/values-night/styles.xml @@ -3,7 +3,7 @@ diff --git a/example/android/build.gradle b/example/android/build.gradle index 4256f91..d2ffbff 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() @@ -18,14 +5,14 @@ allprojects { } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(':app') + 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 94adc3a..2597170 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,3 +1,3 @@ -org.gradle.jvmargs=-Xmx1536M +org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError 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 0e5abae..7bb2df6 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bc..b9e43bd 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 "8.1.0" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false +} + +include ":app" diff --git a/example/lib/main.dart b/example/lib/main.dart index 4a8ed80..f698c6a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -119,14 +119,14 @@ class VerticalSpinBoxPage extends StatelessWidget { textStyle: TextStyle(fontSize: 48), incrementIcon: Icon(Icons.keyboard_arrow_up, size: 64), decrementIcon: Icon(Icons.keyboard_arrow_down, size: 64), - iconColor: MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.disabled)) { + iconColor: WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.disabled)) { return Colors.grey; } - if (states.contains(MaterialState.error)) { + if (states.contains(WidgetState.error)) { return Colors.red; } - if (states.contains(MaterialState.focused)) { + if (states.contains(WidgetState.focused)) { return Colors.blue; } return Colors.black; diff --git a/lib/flutter_spinbox.dart b/lib/flutter_spinbox.dart index 4f192c1..6ac78b0 100644 --- a/lib/flutter_spinbox.dart +++ b/lib/flutter_spinbox.dart @@ -44,7 +44,7 @@ /// /// SpinBox for Flutter comes in two variants. It provides implementations for /// both designs in Flutter, Material and Cupertino (iOS). -library flutter_spinbox; +library; export 'cupertino.dart'; export 'material.dart'; diff --git a/lib/src/base_spin_box.dart b/lib/src/base_spin_box.dart index fd986d6..e38d4d3 100644 --- a/lib/src/base_spin_box.dart +++ b/lib/src/base_spin_box.dart @@ -28,7 +28,7 @@ import 'spin_formatter.dart'; // ignore_for_file: public_member_api_docs abstract class BaseSpinBox extends StatefulWidget { - const BaseSpinBox({Key? key}) : super(key: key); + const BaseSpinBox({super.key}); double get min; double get max; diff --git a/lib/src/cupertino/spin_box.dart b/lib/src/cupertino/spin_box.dart index 5acdbd4..b57b93f 100644 --- a/lib/src/cupertino/spin_box.dart +++ b/lib/src/cupertino/spin_box.dart @@ -48,7 +48,7 @@ part 'third_party/default_rounded_border.dart'; class CupertinoSpinBox extends BaseSpinBox { /// Creates a spinbox. CupertinoSpinBox({ - Key? key, + super.key, this.min = 0, this.max = 100, this.step = 1, @@ -96,8 +96,7 @@ class CupertinoSpinBox extends BaseSpinBox { incrementIcon = incrementIcon ?? const Icon(CupertinoIcons.plus_circled), decrementIcon = - decrementIcon ?? const Icon(CupertinoIcons.minus_circled), - super(key: key); + decrementIcon ?? const Icon(CupertinoIcons.minus_circled); /// The minimum value the user can enter. /// diff --git a/lib/src/cupertino/spin_button.dart b/lib/src/cupertino/spin_button.dart index e42c952..2e0f084 100644 --- a/lib/src/cupertino/spin_button.dart +++ b/lib/src/cupertino/spin_button.dart @@ -30,7 +30,7 @@ const double kSpinPadding = 16; class CupertinoSpinButton extends StatelessWidget { const CupertinoSpinButton({ - Key? key, + super.key, required this.icon, this.color, this.enabled = true, @@ -38,7 +38,7 @@ class CupertinoSpinButton extends StatelessWidget { this.acceleration, required this.interval, required this.onStep, - }) : super(key: key); + }); final Icon icon; final Color? color; diff --git a/lib/src/material/spin_box.dart b/lib/src/material/spin_box.dart index 5758c5d..2ff6169 100644 --- a/lib/src/material/spin_box.dart +++ b/lib/src/material/spin_box.dart @@ -49,7 +49,7 @@ import 'spin_button.dart'; class SpinBox extends BaseSpinBox { /// Creates a spinbox. SpinBox({ - Key? key, + super.key, this.min = 0, this.max = 100, this.step = 1, @@ -95,8 +95,7 @@ class SpinBox extends BaseSpinBox { ), enabled = (enabled ?? true) && min < max, incrementIcon = incrementIcon ?? const Icon(Icons.add), - decrementIcon = decrementIcon ?? const Icon(Icons.remove), - super(key: key); + decrementIcon = decrementIcon ?? const Icon(Icons.remove); /// The minimum value the user can enter. /// @@ -194,7 +193,7 @@ class SpinBox extends BaseSpinBox { /// /// If `null`, then the value of [SpinBoxThemeData.iconColor] is used. If /// that is also `null`, then pre-defined defaults are used. - final MaterialStateProperty? iconColor; + final WidgetStateProperty? iconColor; /// Whether the increment and decrement buttons are shown. /// @@ -281,14 +280,10 @@ class SpinBoxState extends State with SpinBoxMixin { if (!widget.enabled) return theme.disabledColor; if (hasFocus && errorText == null) return theme.colorScheme.primary; - switch (theme.brightness) { - case Brightness.dark: - return Colors.white70; - case Brightness.light: - return Colors.black45; - default: - return theme.iconTheme.color; - } + return switch (theme.brightness) { + Brightness.dark => Colors.white70, + Brightness.light => Colors.black45, + }; } double _textHeight(String? text, TextStyle style) { @@ -318,19 +313,19 @@ class SpinBoxState extends State with SpinBoxMixin { final iconColor = widget.iconColor ?? spinBoxTheme?.iconColor ?? - MaterialStateProperty.all(_iconColor(theme, errorText)); + WidgetStateProperty.all(_iconColor(theme, errorText)); - final states = { - if (!widget.enabled) MaterialState.disabled, - if (hasFocus) MaterialState.focused, - if (errorText != null) MaterialState.error, + final states = { + if (!widget.enabled) WidgetState.disabled, + if (hasFocus) WidgetState.focused, + if (errorText != null) WidgetState.error, }; - final decrementStates = Set.of(states); - if (value <= widget.min) decrementStates.add(MaterialState.disabled); + final decrementStates = Set.of(states); + if (value <= widget.min) decrementStates.add(WidgetState.disabled); - final incrementStates = Set.of(states); - if (value >= widget.max) incrementStates.add(MaterialState.disabled); + final incrementStates = Set.of(states); + if (value >= widget.max) incrementStates.add(WidgetState.disabled); var bottom = 0.0; final isHorizontal = widget.direction == Axis.horizontal; diff --git a/lib/src/material/spin_box_theme.dart b/lib/src/material/spin_box_theme.dart index 942dcdd..a2d4009 100644 --- a/lib/src/material/spin_box_theme.dart +++ b/lib/src/material/spin_box_theme.dart @@ -23,12 +23,12 @@ class SpinBoxThemeData with Diagnosticable { /// The color to use for [SpinBox.incrementIcon] and [SpinBox.decrementIcon]. /// /// Resolves in the following states: - /// * [MaterialState.focused]. - /// * [MaterialState.disabled]. - /// * [MaterialState.error]. + /// * [WidgetState.focused]. + /// * [WidgetState.disabled]. + /// * [WidgetState.error]. /// /// If specified, overrides the default value of [SpinBox.iconColor]. - final MaterialStateProperty? iconColor; + final WidgetStateProperty? iconColor; /// See [TextField.decoration]. /// @@ -39,7 +39,7 @@ class SpinBoxThemeData with Diagnosticable { /// new values. SpinBoxThemeData copyWith({ double? iconSize, - MaterialStateProperty? iconColor, + WidgetStateProperty? iconColor, InputDecoration? decoration, }) { return SpinBoxThemeData( @@ -73,7 +73,7 @@ class SpinBoxThemeData with Diagnosticable { ), ); properties.add( - DiagnosticsProperty>( + DiagnosticsProperty>( 'iconColor', iconColor, defaultValue: null, @@ -103,10 +103,10 @@ class SpinBoxTheme extends InheritedWidget { /// Constructs a checkbox theme that configures all descendant [SpinBox] /// widgets. const SpinBoxTheme({ - Key? key, + super.key, required this.data, - required Widget child, - }) : super(key: key, child: child); + required super.child, + }); /// The properties used for all descendant [SpinBox] widgets. final SpinBoxThemeData data; diff --git a/lib/src/material/spin_button.dart b/lib/src/material/spin_button.dart index 18d44ab..b54e3b0 100644 --- a/lib/src/material/spin_button.dart +++ b/lib/src/material/spin_button.dart @@ -28,7 +28,7 @@ import '../spin_gesture.dart'; class SpinButton extends StatelessWidget { const SpinButton({ - Key? key, + super.key, required this.icon, this.iconSize, this.color, @@ -37,7 +37,7 @@ class SpinButton extends StatelessWidget { this.acceleration, required this.interval, required this.onStep, - }) : super(key: key); + }); final Icon icon; final double? iconSize; diff --git a/lib/src/spin_gesture.dart b/lib/src/spin_gesture.dart index 12ebbee..7230740 100644 --- a/lib/src/spin_gesture.dart +++ b/lib/src/spin_gesture.dart @@ -28,14 +28,14 @@ import 'package:flutter/material.dart'; class SpinGesture extends StatefulWidget { const SpinGesture({ - Key? key, + super.key, this.enabled = true, required this.child, required this.step, this.acceleration, required this.interval, required this.onStep, - }) : super(key: key); + }); final bool enabled; final Widget child; diff --git a/pubspec.yaml b/pubspec.yaml index 0d6ad30..77521d5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,8 +8,8 @@ repository: https://github.com/jpnurmi/flutter_spinbox issue_tracker: https://github.com/jpnurmi/flutter_spinbox/issues environment: - sdk: ">=2.14.0 <4.0.0" - flutter: ">=3.7.0" + sdk: ">=3.6.0 <4.0.0" + flutter: ">=3.27.0" dependencies: cupertino_icons: ^1.0.2 diff --git a/test/cupertino_spinbox_test.dart b/test/cupertino_spinbox_test.dart index 68597ee..cb92f19 100644 --- a/test/cupertino_spinbox_test.dart +++ b/test/cupertino_spinbox_test.dart @@ -4,8 +4,8 @@ import 'package:flutter_spinbox/cupertino.dart'; import 'test_spinbox.dart'; class TestApp extends CupertinoApp { - TestApp({Key? key, required Widget widget}) - : super(key: key, home: CupertinoPageScaffold(child: widget)); + TestApp({super.key, required Widget widget}) + : super(home: CupertinoPageScaffold(child: widget)); } void main() { diff --git a/test/material_spinbox_test.dart b/test/material_spinbox_test.dart index 9581408..9fc0ffe 100644 --- a/test/material_spinbox_test.dart +++ b/test/material_spinbox_test.dart @@ -5,8 +5,8 @@ import 'package:flutter_test/flutter_test.dart'; import 'test_spinbox.dart'; class TestApp extends MaterialApp { - TestApp({Key? key, required Widget widget}) - : super(key: key, home: Scaffold(body: widget)); + TestApp({super.key, required Widget widget}) + : super(home: Scaffold(body: widget)); } void main() { @@ -83,10 +83,10 @@ void main() { }); group('icon color', () { - final iconColor = MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.disabled)) return Colors.yellow; - if (states.contains(MaterialState.error)) return Colors.red; - if (states.contains(MaterialState.focused)) return Colors.blue; + final iconColor = WidgetStateProperty.resolveWith((states) { + if (states.contains(WidgetState.disabled)) return Colors.yellow; + if (states.contains(WidgetState.error)) return Colors.red; + if (states.contains(WidgetState.focused)) return Colors.blue; return Colors.green; }); @@ -198,7 +198,7 @@ void main() { TestApp( widget: SpinBoxTheme( data: SpinBoxThemeData( - iconColor: MaterialStateProperty.all(Colors.black), + iconColor: WidgetStateProperty.all(Colors.black), ), child: SpinBox(iconColor: iconColor), ), diff --git a/test/test_spinbox.dart b/test/test_spinbox.dart index 1ab4e9c..5436cf0 100644 --- a/test/test_spinbox.dart +++ b/test/test_spinbox.dart @@ -335,11 +335,11 @@ void testCallbacks(TestChangeBuilder builder) { group('callbacks', () { late StreamController controller; - setUp(() async { + setUp(() { controller = StreamController(); }); - tearDown(() async { + tearDown(() { controller.close(); }); @@ -373,11 +373,11 @@ void testLongPress(TestChangeBuilder builder) { group('long press', () { late StreamController controller; - setUp(() async { + setUp(() { controller = StreamController(); }); - tearDown(() async { + tearDown(() { controller.close(); });