From e416ac4481f5d46e9699180b5283e65429862b29 Mon Sep 17 00:00:00 2001 From: vutran Date: Mon, 2 Jun 2025 10:31:54 +0700 Subject: [PATCH 1/4] refactor: migrate to new version of gradle --- example/android/app/build.gradle | 65 +++++++------------ example/android/build.gradle | 17 +---- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/android/settings.gradle | 30 ++++++--- example/pubspec.yaml | 2 +- pubspec.yaml | 1 + 6 files changed, 51 insertions(+), 66 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 5530072..33cab93 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,66 +12,43 @@ 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' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" +def flutterVersionCode = localProperties.getProperty('flutter.versionCode') ?: '1' +def flutterVersionName = localProperties.getProperty('flutter.versionName') ?: '1.0' android { - compileSdkVersion flutter.compileSdkVersion + namespace 'com.example.convexappbar' + compileSdk flutter.compileSdkVersion ndkVersion flutter.ndkVersion - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + defaultConfig { + applicationId "com.example.convexappbar" + minSdk flutter.minSdkVersion + targetSdk flutter.targetSdkVersion + versionCode flutterVersionCode.toInteger() + versionName flutterVersionName } - kotlinOptions { - jvmTarget = '1.8' + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + kotlinOptions { + 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.convexappbar" - // You can update the following values to match your application needs. - // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. - minSdkVersion flutter.minSdkVersion - targetSdkVersion flutter.targetSdkVersion - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName - } 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 + shrinkResources false + minifyEnabled false } } + } 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 83ae220..ad89b89 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:7.1.2' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() @@ -26,6 +13,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register("clean", Delete) { + delete rootProject.layout.buildDirectory } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index cc5527d..fb5eb59 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-7.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bc..353abab 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" // apply true + id "com.android.application" version "8.3.0" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false +} + +include ":app" \ No newline at end of file diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a1662fc..3ced5da 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: diff --git a/pubspec.yaml b/pubspec.yaml index 2836104..f46b545 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,6 +9,7 @@ environment: dependencies: flutter: sdk: flutter + cupertino_icons: ^1.0.8 dev_dependencies: flutter_test: From 4db13a4e41b276bae214eecb78b22969cfeb10d4 Mon Sep 17 00:00:00 2001 From: vutran Date: Mon, 2 Jun 2025 10:32:59 +0700 Subject: [PATCH 2/4] feature: and curIndex to constructor, active with go_router shell branch tab --- lib/src/bar.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/bar.dart b/lib/src/bar.dart index 1373f9a..6d9e999 100644 --- a/lib/src/bar.dart +++ b/lib/src/bar.dart @@ -147,6 +147,9 @@ class ConvexAppBar extends StatefulWidget { /// The curve to use in the forward direction. Only works when tab style is not fixed. final Curve curve; + /// Current selected index + final int? curIndex; + /// Construct a new appbar with internal style. /// /// ```dart @@ -209,6 +212,7 @@ class ConvexAppBar extends StatefulWidget { TabStyle? style, Curve? curve, ChipBuilder? chipBuilder, + int? curIndex, }) : this.builder( key: key, itemBuilder: supportedStyle( @@ -225,7 +229,7 @@ class ConvexAppBar extends StatefulWidget { backgroundColor: backgroundColor, shadowColor: shadowColor, count: items.length, - initialActiveIndex: initialActiveIndex, + initialActiveIndex: curIndex ?? initialActiveIndex ?? 0, disableDefaultTabController: disableDefaultTabController ?? false, gradient: gradient, height: height, @@ -271,6 +275,7 @@ class ConvexAppBar extends StatefulWidget { this.cornerRadius, this.curve = Curves.easeInOut, this.chipBuilder, + this.curIndex, }) : assert(top == null || top <= 0, 'top should be negative'), assert(initialActiveIndex == null || initialActiveIndex < count, 'initial index should < $count'), @@ -369,6 +374,7 @@ class ConvexAppBar extends StatefulWidget { class ConvexAppBarState extends State with TickerProviderStateMixin { int? _currentIndex; + /// get index int? get currentIndex => _currentIndex; int _warpUnderwayCount = 0; From 327dc764fddd4e920f3195aed01ec730b446e43d Mon Sep 17 00:00:00 2001 From: vutran Date: Mon, 2 Jun 2025 11:18:04 +0700 Subject: [PATCH 3/4] feature: fix animation does not work --- example/pubspec.yaml | 1 + lib/src/bar.dart | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 3ced5da..42ffa3c 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -13,6 +13,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 + go_router: ^15.1.2 dev_dependencies: flutter_test: diff --git a/lib/src/bar.dart b/lib/src/bar.dart index 6d9e999..795554b 100644 --- a/lib/src/bar.dart +++ b/lib/src/bar.dart @@ -239,6 +239,7 @@ class ConvexAppBar extends StatefulWidget { cornerRadius: cornerRadius, curve: curve ?? Curves.easeInOut, chipBuilder: chipBuilder, + curIndex: curIndex, ); /// Define a custom tab style by implement a [DelegateBuilder]. @@ -532,6 +533,23 @@ class ConvexAppBarState extends State _updateTabController(); _resetState(); } + // Update active index when curIndex changes from parent + if (widget.curIndex != null && widget.curIndex != _currentIndex) { + final previousIndex = _currentIndex ?? 0; + _currentIndex = widget.curIndex!; + + // Animate the convex part to the new position + if (!isFixed()) { + _updateAnimation( + from: previousIndex, + to: _currentIndex, + duration: Duration(milliseconds: _TRANSITION_DURATION), + ); + _animationController?.forward(); + } + + setState(() {}); + } } @override From 478c5c07482aa712c96d00e990f538c8e78a96a8 Mon Sep 17 00:00:00 2001 From: vutran Date: Mon, 2 Jun 2025 11:18:46 +0700 Subject: [PATCH 4/4] feature: remove go_router to test --- example/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 42ffa3c..3ced5da 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -13,7 +13,6 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 - go_router: ^15.1.2 dev_dependencies: flutter_test: