From b0d9775aaa75b13d5d77abe4c8fe3129d1e8d03f Mon Sep 17 00:00:00 2001 From: georgiani Date: Fri, 15 May 2020 16:41:44 +0200 Subject: [PATCH 1/2] Fixed the constructor --- example/ios/Flutter/.last_build_id | 1 + example/ios/Flutter/Flutter.podspec | 18 ++++++ .../ios/Flutter/flutter_export_environment.sh | 14 ++++ example/ios/Runner.xcodeproj/project.pbxproj | 17 +---- example/pubspec.lock | 48 +++++++------- lib/custom_switch.dart | 64 +++++++++++-------- pubspec.lock | 48 +++++++------- 7 files changed, 118 insertions(+), 92 deletions(-) create mode 100644 example/ios/Flutter/.last_build_id create mode 100644 example/ios/Flutter/Flutter.podspec create mode 100755 example/ios/Flutter/flutter_export_environment.sh diff --git a/example/ios/Flutter/.last_build_id b/example/ios/Flutter/.last_build_id new file mode 100644 index 0000000..4f784ad --- /dev/null +++ b/example/ios/Flutter/.last_build_id @@ -0,0 +1 @@ +868ea102ee9ef1697b13fce0327eac25 \ No newline at end of file diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec new file mode 100644 index 0000000..5ca3041 --- /dev/null +++ b/example/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# 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/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh new file mode 100755 index 0000000..30ace25 --- /dev/null +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# This is a generated file; do not edit or check into version control. +export "FLUTTER_ROOT=/Users/georgiani/Documents/paths/flutter" +export "FLUTTER_APPLICATION_PATH=/Users/georgiani/Documents/GitHub/CustomSwitch/example" +export "FLUTTER_TARGET=/Users/georgiani/Documents/GitHub/CustomSwitch/example/lib/main.dart" +export "FLUTTER_BUILD_DIR=build" +export "SYMROOT=${SOURCE_ROOT}/../build/ios" +export "OTHER_LDFLAGS=$(inherited) -framework Flutter" +export "FLUTTER_FRAMEWORK_DIR=/Users/georgiani/Documents/paths/flutter/bin/cache/artifacts/engine/ios" +export "FLUTTER_BUILD_NAME=1.0.0" +export "FLUTTER_BUILD_NUMBER=1" +export "DART_OBFUSCATION=false" +export "TRACK_WIDGET_CREATION=true" +export "TREE_SHAKE_ICONS=false" diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 556383d..ffec437 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -9,10 +9,6 @@ /* Begin PBXBuildFile section */ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; }; - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; }; - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; }; 978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; }; 97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; }; @@ -28,8 +24,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - 3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */, - 9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -40,13 +34,11 @@ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; 7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = ""; }; 9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = ""; }; - 9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = ""; }; 97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; }; 97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -60,8 +52,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */, - 3B80C3941E831B6300D905FE /* App.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -71,9 +61,7 @@ 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( - 3B80C3931E831B6300D905FE /* App.framework */, 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */, - 9740EEBA1CF902C7004384FC /* Flutter.framework */, 9740EEB21CF90195004384FC /* Debug.xcconfig */, 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, 9740EEB31CF90195004384FC /* Generated.xcconfig */, @@ -206,7 +194,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin"; + shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; @@ -259,7 +247,6 @@ /* Begin XCBuildConfiguration section */ 249021D3217E4FDB00AE95B9 /* Profile */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -333,7 +320,6 @@ }; 97C147031CF9000F007C117D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -389,7 +375,6 @@ }; 97C147041CF9000F007C117D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; diff --git a/example/pubspec.lock b/example/pubspec.lock index 5607628..b2298db 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,28 +7,35 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" cupertino_icons: dependency: "direct main" description: @@ -43,6 +50,13 @@ packages: relative: true source: path version: "0.0.1" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -59,35 +73,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted version: "1.7.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" sky_engine: dependency: transitive description: flutter @@ -99,7 +99,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: transitive description: @@ -120,7 +120,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -134,7 +134,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.15" typed_data: dependency: transitive description: @@ -150,4 +150,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.6.0 <3.0.0" diff --git a/lib/custom_switch.dart b/lib/custom_switch.dart index c9cf4bf..b0f3d1d 100644 --- a/lib/custom_switch.dart +++ b/lib/custom_switch.dart @@ -6,22 +6,22 @@ class CustomSwitch extends StatefulWidget { final bool value; final ValueChanged onChanged; final Color activeColor; - final Color inactiveColor = Colors.grey; - final String activeText = 'On'; - final String inactiveText = 'Off'; - final Color activeTextColor = Colors.white70; - final Color inactiveTextColor = Colors.white70; + final Color inactiveColor; + final String activeText; + final String inactiveText; + final Color activeTextColor; + final Color inactiveTextColor; - const CustomSwitch({ - Key key, - this.value, - this.onChanged, - this.activeColor, - this.inactiveColor, - this.activeText, - this.inactiveText, - this.activeTextColor, - this.inactiveTextColor}) + const CustomSwitch( + {Key key, + this.value, + this.onChanged, + this.activeColor, + this.inactiveColor = Colors.grey, + this.activeText = 'On', + this.inactiveText = 'Off', + this.activeTextColor = Colors.white70, + this.inactiveTextColor = Colors.white70}) : super(key: key); @override @@ -36,13 +36,18 @@ class _CustomSwitchState extends State @override void initState() { super.initState(); - _animationController = - AnimationController(vsync: this, duration: Duration(milliseconds: 60)); + + _animationController = AnimationController( + vsync: this, + duration: Duration(milliseconds: 40), + ); + _circleAnimation = AlignmentTween( - begin: widget.value ? Alignment.centerRight : Alignment.centerLeft, - end: widget.value ? Alignment.centerLeft : Alignment.centerRight) - .animate(CurvedAnimation( - parent: _animationController, curve: Curves.linear)); + begin: widget.value ? Alignment.centerRight : Alignment.centerLeft, + end: widget.value ? Alignment.centerLeft : Alignment.centerRight, + ).animate( + CurvedAnimation(parent: _animationController, curve: Curves.linear), + ); } @override @@ -52,14 +57,17 @@ class _CustomSwitchState extends State builder: (context, child) { return GestureDetector( onTap: () { - if (_animationController.isCompleted) { - _animationController.reverse(); - } else { - _animationController.forward(); + if (!_animationController.isAnimating) { + if (_animationController.isCompleted) { + _animationController.reverse(); + } else { + _animationController.forward(); + } + + widget.value == false + ? widget.onChanged(true) + : widget.onChanged(false); } - widget.value == false - ? widget.onChanged(true) - : widget.onChanged(false); }, child: Container( width: 70.0, diff --git a/pubspec.lock b/pubspec.lock index 2e19e22..4211cac 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,28 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.2.0" + version: "2.4.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" + version: "1.1.3" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.14.12" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -45,35 +59,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.5" + version: "0.12.6" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.1.8" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.2" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted version: "1.7.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.3" sky_engine: dependency: transitive description: flutter @@ -85,7 +85,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.7.0" stack_trace: dependency: transitive description: @@ -106,7 +106,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "1.0.5" term_glyph: dependency: transitive description: @@ -120,7 +120,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.15" typed_data: dependency: transitive description: @@ -136,4 +136,4 @@ packages: source: hosted version: "2.0.8" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.6.0 <3.0.0" From 911353de143e45782ba0b69b30a114c92a4413db Mon Sep 17 00:00:00 2001 From: georgiani Date: Fri, 15 May 2020 17:08:43 +0200 Subject: [PATCH 2/2] Code rearrangement and removed custom text --- .vscode/launch.json | 14 +++++++++ lib/custom_switch.dart | 65 +++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 35 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9f8693f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Flutter", + "request": "launch", + "type": "dart", + "program": "example/lib/main.dart" + } + ] +} \ No newline at end of file diff --git a/lib/custom_switch.dart b/lib/custom_switch.dart index b0f3d1d..7d2e7ea 100644 --- a/lib/custom_switch.dart +++ b/lib/custom_switch.dart @@ -7,19 +7,18 @@ class CustomSwitch extends StatefulWidget { final ValueChanged onChanged; final Color activeColor; final Color inactiveColor; - final String activeText; - final String inactiveText; final Color activeTextColor; final Color inactiveTextColor; + final String activeText = "On"; + final String inactiveText = "Off"; + const CustomSwitch( {Key key, this.value, this.onChanged, this.activeColor, this.inactiveColor = Colors.grey, - this.activeText = 'On', - this.inactiveText = 'Off', this.activeTextColor = Colors.white70, this.inactiveTextColor = Colors.white70}) : super(key: key); @@ -63,37 +62,26 @@ class _CustomSwitchState extends State } else { _animationController.forward(); } - - widget.value == false - ? widget.onChanged(true) - : widget.onChanged(false); + + !widget.value ? widget.onChanged(true) : widget.onChanged(false); } }, child: Container( width: 70.0, height: 35.0, decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20.0), - color: _circleAnimation.value == Alignment.centerLeft - ? widget.inactiveColor - : widget.activeColor), + borderRadius: BorderRadius.circular(20.0), + color: _circleAnimation.value == Alignment.centerLeft + ? widget.inactiveColor + : widget.activeColor, + ), child: Padding( - padding: const EdgeInsets.only( - top: 4.0, bottom: 4.0, right: 4.0, left: 4.0), + padding: const EdgeInsets.all(4.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ _circleAnimation.value == Alignment.centerRight - ? Padding( - padding: const EdgeInsets.only(left: 4.0, right: 4.0), - child: Text( - widget.activeText, - style: TextStyle( - color: widget.activeTextColor, - fontWeight: FontWeight.w900, - fontSize: 16.0), - ), - ) + ? _getText(true) : Container(), Align( alignment: _circleAnimation.value, @@ -101,20 +89,13 @@ class _CustomSwitchState extends State width: 25.0, height: 25.0, decoration: BoxDecoration( - shape: BoxShape.circle, color: Colors.white), + shape: BoxShape.circle, + color: Colors.white, + ), ), ), _circleAnimation.value == Alignment.centerLeft - ? Padding( - padding: const EdgeInsets.only(left: 4.0, right: 5.0), - child: Text( - widget.inactiveText, - style: TextStyle( - color: widget.inactiveTextColor, - fontWeight: FontWeight.w900, - fontSize: 16.0), - ), - ) + ? _getText(false) : Container(), ], ), @@ -124,4 +105,18 @@ class _CustomSwitchState extends State }, ); } + + _getText(bool active) { + return Padding( + padding: const EdgeInsets.only(left: 4.0, right: 4.0), + child: Text( + active ? widget.activeText : widget.inactiveText, + style: TextStyle( + color: active ? widget.activeTextColor : widget.inactiveTextColor, + fontWeight: FontWeight.w900, + fontSize: 16.0, + ), + ), + ); + } }