Skip to content

add curIndex to style reactCircle #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 24 additions & 41 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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"
}
17 changes: 2 additions & 15 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -26,6 +13,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
tasks.register("clean", Delete) {
delete rootProject.layout.buildDirectory
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 22 additions & 8 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 25 additions & 1 deletion lib/src/bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -209,6 +212,7 @@ class ConvexAppBar extends StatefulWidget {
TabStyle? style,
Curve? curve,
ChipBuilder? chipBuilder,
int? curIndex,
}) : this.builder(
key: key,
itemBuilder: supportedStyle(
Expand All @@ -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,
Expand All @@ -235,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].
Expand Down Expand Up @@ -271,6 +276,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'),
Expand Down Expand Up @@ -369,6 +375,7 @@ class ConvexAppBar extends StatefulWidget {
class ConvexAppBarState extends State<ConvexAppBar>
with TickerProviderStateMixin {
int? _currentIndex;

/// get index
int? get currentIndex => _currentIndex;
int _warpUnderwayCount = 0;
Expand Down Expand Up @@ -526,6 +533,23 @@ class ConvexAppBarState extends State<ConvexAppBar>
_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
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.8

dev_dependencies:
flutter_test:
Expand Down