diff --git a/.gitignore b/.gitignore
index 8f98511..fbfc20c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,7 +30,7 @@ example/.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
-pubspec.lock
+#pubspec.lock
/build/
# Android related
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7c5d5c..c843604 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,13 @@
+## 1.3.0
+* Added null support for initialLabelIndex ([PR 39](https://github.com/PramodJoshi/toggle_switch/pull/39/commits)).
+* Added double tap support to de-select/de-activate active switch ([PR 41](https://github.com/PramodJoshi/toggle_switch/pull/41)):
+ - parameter:
+ - doubleTapDisable (optional, type bool - default false)
+* Added animation duration support:
+ - parameter:
+ - animationDuration (optional, type int - default 800)
+* Added package test
+
## 1.2.0
* Added custom icons support:
- parameter:
diff --git a/README.md b/README.md
index 8d92f76..503976f 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
- toggle_switch: ^1.2.0
+ toggle_switch: ^1.3.0
```
Import it:
diff --git a/example/README.md b/example/README.md
index 8d92f76..503976f 100644
--- a/example/README.md
+++ b/example/README.md
@@ -9,7 +9,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
- toggle_switch: ^1.2.0
+ toggle_switch: ^1.3.0
```
Import it:
diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist
index 6b4c0f7..f2872cf 100644
--- a/example/ios/Flutter/AppFrameworkInfo.plist
+++ b/example/ios/Flutter/AppFrameworkInfo.plist
@@ -21,6 +21,6 @@
CFBundleVersion
1.0
MinimumOSVersion
- 8.0
+ 9.0
diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec
deleted file mode 100644
index 5ca3041..0000000
--- a/example/ios/Flutter/Flutter.podspec
+++ /dev/null
@@ -1,18 +0,0 @@
-#
-# NOTE: This podspec is NOT to be published. It is only used as a local source!
-#
-
-Pod::Spec.new do |s|
- s.name = 'Flutter'
- s.version = '1.0.0'
- s.summary = 'High-performance, high-fidelity mobile apps.'
- s.description = <<-DESC
-Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
- DESC
- s.homepage = 'https://flutter.io'
- s.license = { :type => 'MIT' }
- 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 = '8.0'
- s.vendored_frameworks = 'Flutter.framework'
-end
diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj
index 6888140..aa8cad9 100644
--- a/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/example/ios/Runner.xcodeproj/project.pbxproj
@@ -282,7 +282,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
@@ -363,7 +363,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
@@ -412,7 +412,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
- IPHONEOS_DEPLOYMENT_TARGET = 8.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 6db2681..e24ae6c 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
- version: "2.5.0"
+ version: "2.8.1"
boolean_selector:
dependency: transitive
description:
@@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
clock:
dependency: transitive
description:
@@ -87,7 +87,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
- version: "1.3.0"
+ version: "1.7.0"
path:
dependency: transitive
description:
@@ -106,7 +106,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
- version: "1.8.0"
+ version: "1.8.1"
stack_trace:
dependency: transitive
description:
@@ -141,14 +141,14 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
- version: "0.2.19"
+ version: "0.4.2"
toggle_switch:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
- version: "1.2.0"
+ version: "1.3.0"
typed_data:
dependency: transitive
description:
diff --git a/lib/toggle_switch.dart b/lib/toggle_switch.dart
index 6a26183..a9cc1c0 100644
--- a/lib/toggle_switch.dart
+++ b/lib/toggle_switch.dart
@@ -70,6 +70,9 @@ class ToggleSwitch extends StatefulWidget {
/// Set animation
final bool animate;
+ /// Set animation duration
+ final int animationDuration;
+
/// Set radius style
final bool radiusStyle;
@@ -79,6 +82,7 @@ class ToggleSwitch extends StatefulWidget {
/// Initial label index, set to null for no chosen initial value (all options inactive)
int? initialLabelIndex;
+ /// Tap active switch to de-activate/de-select
bool doubleTapDisable;
ToggleSwitch(
@@ -103,6 +107,7 @@ class ToggleSwitch extends StatefulWidget {
this.customTextStyles,
this.customIcons,
this.animate = false,
+ this.animationDuration = 800,
this.curve = Curves.easeIn,
this.radiusStyle = false,
this.fontSize = 14.0,
@@ -149,7 +154,7 @@ class _ToggleSwitchState extends State
/// Assigns active foreground color to default accent text theme color if it's null/not provided.
activeFgColor = widget.activeFgColor == null
- ? Theme.of(context).accentTextTheme.bodyText1!.color
+ ? Theme.of(context).primaryTextTheme.bodyText1!.color
: widget.activeFgColor;
/// Assigns inactive background color to default disabled theme color if it's null/not provided.
@@ -299,7 +304,9 @@ class _ToggleSwitchState extends State
end: Alignment.bottomRight,
),
),
- duration: Duration(milliseconds: widget.animate ? 800 : 0),
+ duration: Duration(
+ milliseconds:
+ widget.animate ? widget.animationDuration : 0),
curve: widget.curve,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
diff --git a/pubspec.lock b/pubspec.lock
new file mode 100644
index 0000000..8077d23
--- /dev/null
+++ b/pubspec.lock
@@ -0,0 +1,146 @@
+# Generated by pub
+# See https://dart.dev/tools/pub/glossary#lockfile
+packages:
+ async:
+ dependency: transitive
+ description:
+ name: async
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.8.1"
+ boolean_selector:
+ dependency: transitive
+ description:
+ name: boolean_selector
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.1.0"
+ characters:
+ dependency: transitive
+ description:
+ name: characters
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
+ charcode:
+ dependency: transitive
+ description:
+ name: charcode
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.3.1"
+ clock:
+ dependency: transitive
+ description:
+ name: clock
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
+ collection:
+ dependency: transitive
+ description:
+ name: collection
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.15.0"
+ fake_async:
+ dependency: transitive
+ description:
+ name: fake_async
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.2.0"
+ flutter:
+ dependency: "direct main"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ flutter_test:
+ dependency: "direct dev"
+ description: flutter
+ source: sdk
+ version: "0.0.0"
+ matcher:
+ dependency: transitive
+ description:
+ name: matcher
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.12.10"
+ meta:
+ dependency: transitive
+ description:
+ name: meta
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.7.0"
+ path:
+ dependency: transitive
+ description:
+ name: path
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.8.0"
+ sky_engine:
+ dependency: transitive
+ description: flutter
+ source: sdk
+ version: "0.0.99"
+ source_span:
+ dependency: transitive
+ description:
+ name: source_span
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.8.1"
+ stack_trace:
+ dependency: transitive
+ description:
+ name: stack_trace
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.10.0"
+ stream_channel:
+ dependency: transitive
+ description:
+ name: stream_channel
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.1.0"
+ string_scanner:
+ dependency: transitive
+ description:
+ name: string_scanner
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.1.0"
+ term_glyph:
+ dependency: transitive
+ description:
+ name: term_glyph
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.2.0"
+ test_api:
+ dependency: transitive
+ description:
+ name: test_api
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.4.2"
+ typed_data:
+ dependency: transitive
+ description:
+ name: typed_data
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "1.3.0"
+ vector_math:
+ dependency: transitive
+ description:
+ name: vector_math
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.1.0"
+sdks:
+ dart: ">=2.12.0 <3.0.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index 52d1c6c..be56900 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: toggle_switch
description: Toggle Switch - A simple toggle switch widget. It can be fully customized with desired icons, width, colors, text, corner radius etc. It also maintains selection state.
-version: 1.2.0
+version: 1.3.0
homepage: https://github.com/PramodJoshi/toggle_switch
environment:
diff --git a/test/toggle_switch_test.dart b/test/toggle_switch_test.dart
new file mode 100644
index 0000000..534050b
--- /dev/null
+++ b/test/toggle_switch_test.dart
@@ -0,0 +1,145 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:toggle_switch/toggle_switch.dart';
+
+void main() {
+ testWidgets('Can set active background color', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ totalSwitches: 2,
+ activeBgColor: [Colors.blue],
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.activeBgColor, equals([Colors.blue]));
+ });
+
+ testWidgets('Can set inactive background color', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ totalSwitches: 2,
+ inactiveBgColor: Colors.grey,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.inactiveBgColor, equals(Colors.grey));
+ });
+
+ testWidgets('Can set active foreground color', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ activeFgColor: Colors.white70,
+ totalSwitches: 3,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.activeFgColor, equals(Colors.white70));
+ });
+
+ testWidgets('Can set inactive foreground color', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ inactiveFgColor: Colors.black,
+ totalSwitches: 3,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.inactiveFgColor, equals(Colors.black));
+ });
+
+ testWidgets('Can set number of total switches', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ totalSwitches: 5,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.totalSwitches, equals(5));
+ });
+
+ testWidgets('Can set icons', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(totalSwitches: 2, icons: [Icons.add, Icons.clear]),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.icons, equals([Icons.add, Icons.clear]));
+ });
+
+ testWidgets('Can set default active switch', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ totalSwitches: 2,
+ initialLabelIndex: 1,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.initialLabelIndex, equals(1));
+ });
+
+ testWidgets('Can set minimum height', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ totalSwitches: 2,
+ minHeight: 50.0,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.minHeight, equals(50.0));
+ });
+
+ testWidgets('Can set minimum width', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MediaQuery(
+ data: new MediaQueryData(),
+ child: MaterialApp(
+ home: ToggleSwitch(
+ totalSwitches: 2,
+ minWidth: 40.0,
+ ),
+ ),
+ ),
+ );
+ final widget = tester.widget(find.byType(ToggleSwitch));
+ expect(widget.minWidth, equals(40.0));
+ });
+}