diff --git a/example/.gitignore b/example/.gitignore index 2ddde2a5..ae1f1838 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -24,50 +24,14 @@ **/doc/api/ .dart_tool/ .flutter-plugins +.flutter-plugins-dependencies .packages .pub-cache/ .pub/ /build/ -# Android related -**/android/**/gradle-wrapper.jar -**/android/.gradle -**/android/captures/ -**/android/gradlew -**/android/gradlew.bat -**/android/local.properties -**/android/**/GeneratedPluginRegistrant.java - -# iOS/XCode related -**/ios/**/*.mode1v3 -**/ios/**/*.mode2v3 -**/ios/**/*.moved-aside -**/ios/**/*.pbxuser -**/ios/**/*.perspectivev3 -**/ios/**/*sync/ -**/ios/**/.sconsign.dblite -**/ios/**/.tags* -**/ios/**/.vagrant/ -**/ios/**/DerivedData/ -**/ios/**/Icon? -**/ios/**/Pods/ -**/ios/**/.symlinks/ -**/ios/**/profile -**/ios/**/xcuserdata -**/ios/.generated/ -**/ios/Flutter/App.framework -**/ios/Flutter/Flutter.framework -**/ios/Flutter/Generated.xcconfig -**/ios/Flutter/app.flx -**/ios/Flutter/app.zip -**/ios/Flutter/flutter_assets/ -**/ios/Flutter/flutter_export_environment.sh -**/ios/ServiceDefinitions.json -**/ios/Runner/GeneratedPluginRegistrant.* +# Web related +lib/generated_plugin_registrant.dart # Exceptions to above rules. -!**/ios/**/default.mode1v3 -!**/ios/**/default.mode2v3 -!**/ios/**/default.pbxuser -!**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages diff --git a/example/.metadata b/example/.metadata index fea404f4..361e1e4c 100644 --- a/example/.metadata +++ b/example/.metadata @@ -4,7 +4,7 @@ # This file should be version controlled and should not be manually edited. version: - revision: 68587a0916366e9512a78df22c44163d041dd5f3 - channel: stable + revision: 18cd7a3601bcffb36fdf2f679f763b5e827c2e8e + channel: beta project_type: app diff --git a/example/android/.gitignore b/example/android/.gitignore new file mode 100644 index 00000000..bc2100d8 --- /dev/null +++ b/example/android/.gitignore @@ -0,0 +1,7 @@ +gradle-wrapper.jar +/.gradle +/captures/ +/gradlew +/gradlew.bat +/local.properties +GeneratedPluginRegistrant.java diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index cc584e27..29db49b0 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -43,7 +43,7 @@ android { targetSdkVersion 28 versionCode flutterVersionCode.toInteger() versionName flutterVersionName - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -62,6 +62,6 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' - androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + androidTestImplementation 'androidx.test:runner:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' } diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 0f3a2ee1..093e7a15 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - - + + diff --git a/example/android/app/src/main/kotlin/com/example/ui_kit_example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/ui_kit_example/MainActivity.kt index 749c5b37..f1a2581a 100644 --- a/example/android/app/src/main/kotlin/com/example/ui_kit_example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/example/ui_kit_example/MainActivity.kt @@ -1,13 +1,12 @@ package com.example.ui_kit_example -import android.os.Bundle - -import io.flutter.app.FlutterActivity +import androidx.annotation.NonNull; +import io.flutter.embedding.android.FlutterActivity +import io.flutter.embedding.engine.FlutterEngine import io.flutter.plugins.GeneratedPluginRegistrant class MainActivity: FlutterActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - GeneratedPluginRegistrant.registerWith(this) - } + override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) { + GeneratedPluginRegistrant.registerWith(flutterEngine); + } } diff --git a/example/android/build.gradle b/example/android/build.gradle index b7faad8f..3100ad2d 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.2.71' + ext.kotlin_version = '1.3.50' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.5.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/example/android/gradle.properties b/example/android/gradle.properties index 2bd6f4fd..38c8d454 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -1,2 +1,4 @@ org.gradle.jvmargs=-Xmx1536M - +android.enableR8=true +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 2819f022..296b146b 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-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip diff --git a/example/ios/.gitignore b/example/ios/.gitignore new file mode 100644 index 00000000..e96ef602 --- /dev/null +++ b/example/ios/.gitignore @@ -0,0 +1,32 @@ +*.mode1v3 +*.mode2v3 +*.moved-aside +*.pbxuser +*.perspectivev3 +**/*sync/ +.sconsign.dblite +.tags* +**/.vagrant/ +**/DerivedData/ +Icon? +**/Pods/ +**/.symlinks/ +profile +xcuserdata +**/.generated/ +Flutter/App.framework +Flutter/Flutter.framework +Flutter/Flutter.podspec +Flutter/Generated.xcconfig +Flutter/app.flx +Flutter/app.zip +Flutter/flutter_assets/ +Flutter/flutter_export_environment.sh +ServiceDefinitions.json +Runner/GeneratedPluginRegistrant.* + +# Exceptions to above rules. +!default.mode1v3 +!default.mode2v3 +!default.pbxuser +!default.perspectivev3 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 37f64343..86bdbd60 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 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 */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; @@ -153,7 +152,7 @@ TargetAttributes = { 97C146ED1CF9000F007C117D = { CreatedOnToolsVersion = 7.3.1; - LastSwiftMigration = 0910; + LastSwiftMigration = 1100; }; }; }; @@ -182,7 +181,6 @@ files = ( 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */, 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */, - 9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */, 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */, 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */, ); @@ -298,6 +296,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -324,7 +323,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.example.uiKitExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Profile; @@ -430,6 +429,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; @@ -458,7 +458,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Debug; @@ -484,7 +484,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.example.uiKitExample; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; name = Release; @@ -513,7 +513,6 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ - }; rootObject = 97C146E61CF9000F007C117D /* Project object */; } diff --git a/example/lib/assets/fav.png b/example/lib/assets/fav.png deleted file mode 100644 index 953d3b01..00000000 Binary files a/example/lib/assets/fav.png and /dev/null differ diff --git a/example/lib/assets/food.png b/example/lib/assets/food.png deleted file mode 100644 index 7557e510..00000000 Binary files a/example/lib/assets/food.png and /dev/null differ diff --git a/example/lib/assets/pizza.jpeg b/example/lib/assets/pizza.jpeg deleted file mode 100644 index 15c1cd54..00000000 Binary files a/example/lib/assets/pizza.jpeg and /dev/null differ diff --git a/example/lib/main.dart b/example/lib/main.dart index b52a897c..a61dfa18 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -43,47 +43,64 @@ class _MyHomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar( - title: Text(widget.title), - ), - body: SingleChildScrollView( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - - - GFCard( - boxFit: BoxFit.cover, - colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.67), BlendMode.darken), - image: Image.asset("lib/assets/pizza.jpeg"), + appBar: AppBar( + title: Text(widget.title), + ), + body: SingleChildScrollView( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + GFCard( + boxFit: BoxFit.cover, + colorFilter: new ColorFilter.mode( + Colors.black.withOpacity(0.67), BlendMode.darken), + image: Image.asset("lib/assets/pizza.jpeg"), // imageOverlay: AssetImage("lib/assets/pizza.jpeg"), - titlePosition: GFPosition.end, - title: GFTitleBar( - avatar: GFAvatar( - child: Text("tb"), - ), - title: Text('title', style: TextStyle(color: Colors.grey),), - subTitle: Text('subtitle', style: TextStyle(color: Colors.grey),), - icon: GFIconButton( - onPressed: null, - icon: Icon(Icons.favorite_border), - type: GFType.transparent, + titlePosition: GFPosition.end, + title: GFTitleBar( + avatar: GFAvatar( + child: Text("tb"), + ), + title: Text( + 'title', + style: TextStyle(color: Colors.grey), + ), + subTitle: Text( + 'subtitle', + style: TextStyle(color: Colors.grey), + ), + icon: GFIconButton( + onPressed: null, + icon: Icon(Icons.favorite_border), + type: GFType.transparent, + ), ), - ), - content: Text("Flutter " + content: Text( + "Flutter " "Flutter is Google's mobile UI framework for crafting" " high-quality native interfaces on iOS and Android in " - "Flutter ", style: TextStyle(color: Colors.grey), ), - buttonBar: GFButtonBar( - mainAxisSize: MainAxisSize.min, - children: [ - GFButton(onPressed: null, child: Text("favorite"), icon: Icon(Icons.favorite_border), type: GFType.transparent, ), - GFButton(onPressed: null, child: Text("share"), icon: Icon(Icons.share), type: GFType.outline, ), - ], + "Flutter ", + style: TextStyle(color: Colors.grey), + ), + buttonBar: GFButtonBar( + mainAxisSize: MainAxisSize.min, + children: [ + GFButton( + onPressed: null, + child: Text("favorite"), + icon: Icon(Icons.favorite_border), + type: GFType.transparent, + ), + GFButton( + onPressed: null, + child: Text("share"), + icon: Icon(Icons.share), + type: GFType.outline, + ), + ], + ), ), - ), - // GFButtonBar( // mainAxisSize: MainAxisSize.min, @@ -107,51 +124,70 @@ class _MyHomePageState extends State { // ), // ), - GFImageOverlay( - width: MediaQuery.of(context).size.width, - margin: EdgeInsets.all(16.0), - padding: EdgeInsets.all(16.0), - child: Column( - children: [ - new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ),new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ), - new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ),new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ), - new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ),new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ), - new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ),new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ), - new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ),new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ), - new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ),new Text( - 'Hello world', style: TextStyle(color: Colors.white), - ), - ], - ), + GFImageOverlay( + width: MediaQuery.of(context).size.width, + margin: EdgeInsets.all(16.0), + padding: EdgeInsets.all(16.0), + child: Column( + children: [ + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + new Text( + 'Hello world', + style: TextStyle(color: Colors.white), + ), + ], + ), // color: Colors.orange, - image: AssetImage("lib/assets/pizza.jpeg"), - boxFit: BoxFit.cover, - colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.6), BlendMode.darken), - borderRadius: new BorderRadius.circular(5.0), + image: AssetImage("lib/assets/pizza.jpeg"), + boxFit: BoxFit.cover, + colorFilter: new ColorFilter.mode( + Colors.black.withOpacity(0.6), BlendMode.darken), + borderRadius: new BorderRadius.circular(5.0), // border: Border.all(color: Colors.pink, width: 2.0), - ), + ), // // GFAvatar( @@ -251,9 +287,8 @@ class _MyHomePageState extends State { //// borderSide: BorderSide(color: Colors.pink, width: 1.0, style: BorderStyle.solid), //// borderShape: RoundedRectangleBorder(side: BorderSide(color: Colors.pink, width: 2.0, style: BorderStyle.solid), borderRadius: BorderRadius.zero), // ), - ], - ), - ) - ); + ], + ), + )); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index e1f021d1..57c5df30 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,13 +1,27 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" cupertino_icons: dependency: "direct main" description: @@ -46,20 +74,27 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: 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.7" + version: "1.1.8" path: dependency: transitive description: @@ -74,6 +109,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: @@ -127,7 +169,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -149,5 +191,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index b04ca605..95eca7a1 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -9,17 +9,14 @@ environment: dependencies: flutter: sdk: flutter - cupertino_icons: ^0.1.2 ui_kit: path: ../ + cupertino_icons: ^0.1.2 + dev_dependencies: flutter_test: sdk: flutter flutter: - uses-material-design: true - assets: - - lib/assets/fav.png - - lib/assets/food.png - - lib/assets/pizza.jpeg + uses-material-design: true \ No newline at end of file diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index dc7ca7c9..1ceafff3 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -1,13 +1,5 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter_test/flutter_test.dart'; - -void main() { +import 'package:flutter_test/flutter_test.dart';void main() { testWidgets('Basic test', (WidgetTester tester) async { prints('Test paassed'); }); diff --git a/example/web/index.html b/example/web/index.html new file mode 100644 index 00000000..6b8b893c --- /dev/null +++ b/example/web/index.html @@ -0,0 +1,10 @@ + + + + + ui_kit_example + + + + + diff --git a/lib/components/toggle/gf_toggle.dart b/lib/components/toggle/gf_toggle.dart new file mode 100644 index 00000000..167c2619 --- /dev/null +++ b/lib/components/toggle/gf_toggle.dart @@ -0,0 +1,632 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import '../../types/gf_toggle_type.dart'; + + + + + +class GFToggle extends StatelessWidget { + GFToggle({Key key, + @required this.onChanged, + @required this.value, + this.activeColor, +// this.inactiveColor, + this.inactiveTrackColor, + this.inactiveThumbColor, + this.activeThumbColor, + this.focusColor, + this.hoverColor, + this.type, + this.height, + this.width, + this.onText, + this.offText, + this.minWidth + }) :super(key: key); + + +// /// Button type of [GFToggleType] i.e, androidSwitch, iosSwitch, labeledSwitch, animatedSWitch + GFToggleType type; + + ///A androidSwitch + /// + /// The color to use on the track when this switch is on. + final Color activeColor; + + + /// Whether this switch is on or off. + /// + /// This property must not be null. + final bool value; + + ///the state used to toggle the switch for true or false + final ValueChanged onChanged; + + /// The color to use on the track when this switch is off. + final Color inactiveTrackColor; + + /// Defaults to the colors described in the Material design specification. + final Color inactiveThumbColor; + + /// Defaults to the colors described in the Material design specification when switch is on. + final Color activeThumbColor; + + + /// The color for the button's [Material] when it has the input focus. + final Color focusColor; + + /// The color for the button's [Material] when a pointer is hovering over it. + final Color hoverColor; + + + ///height of the ios button + final double height; + + ///width of the track button + final double width; + + +///text for the labeled Switch when it is true + final String onText; + +///text for the labled switch when it is false + final String offText; + + + ///minwidth of the switch for labeled switch + final bool minWidth; + + + @override + Widget build(BuildContext context) { + if (type == GFToggleType.androidSwitch) { + return Switch( + value: value, + activeColor: activeColor, + inactiveThumbColor: inactiveTrackColor, + inactiveTrackColor: inactiveTrackColor, + hoverColor: hoverColor, + focusColor: focusColor, + onChanged: onChanged, + + + ); + } else if (type == GFToggleType.iosSwitch) { + return CupertinoSwitch( + value: value, + onChanged: onChanged, + activeColor: activeColor, + + + ); + + } else if (type == GFToggleType.labeledSwitch){ + return Switch(value: value, onChanged: onChanged, + + + + ); + + + } + } +} +// +//enum TextTransitionTypes { ROTATE, SCALE, FADE, SIZE } +// +//class LabeledToggle extends StatefulWidget { +// final Widget child; +// final String onText; +// final String offText; +// final Color onTextColor; +// final Color offTextColor; +// final Color onThumbColor; +// final Color offThumbColor; +// final Color onBorderColor; +// final Color offBorderColor; +// final Color onBkColor; +// final Color offBkColor; +// final bool value; +// final double thumbSize; +// final double borderSize; +// final Duration duration; +// final Curve curve; +// final ValueChanged onChanged; +// final bool forceWidth; +// final bool rounded; +// final TextTransitionTypes transitionType; +// final bool rotationAnimation; +// +// const LabeledToggle( +// {Key key, +// this.value = false, +// this.onText = "", +// this.offText = "", +// this.onThumbColor, +// this.offThumbColor, +// this.onBorderColor, +// this.offBorderColor, +// this.onBkColor, +// this.offBkColor, +// this.onChanged, +// @required this.thumbSize, +// this.duration = const Duration(milliseconds: 400), +// this.curve = Curves.linear, +// this.forceWidth = false, +// this.onTextColor = Colors.black, +// this.offTextColor = Colors.black, +// this.rounded = true, +// this.borderSize = 1.0, +// this.transitionType = TextTransitionTypes.SCALE, +// this.rotationAnimation = false, +// this.child}) +// : assert(thumbSize != null), +// super(key: key); +// +// const LabeledToggle.theme( +// {Key key, +// this.value = false, +// this.onText = "", +// this.offText = "", +// @required onColor, +// @required offColor, +// this.onChanged, +// @required this.thumbSize, +// this.duration = const Duration(milliseconds: 400), +// this.curve = Curves.linear, +// this.forceWidth = false, +// this.rounded = true, +// this.borderSize = 1.0, +// this.transitionType = TextTransitionTypes.SCALE, +// this.rotationAnimation = false, +// this.child}) +// : assert(thumbSize != null), +// onThumbColor = offColor, +// onBorderColor = offColor, +// onBkColor = onColor, +// offThumbColor = onColor, +// offBorderColor = onColor, +// offBkColor = offColor, +// onTextColor = offColor, +// offTextColor = onColor, +// super(key: key); +// +// @override +// _LabeledToggleState createState() => _LabeledToggleState(); +//} +// +//class _LabeledToggleState extends State +// with SingleTickerProviderStateMixin { +// bool _value; +// AnimationController animationController; +// Animation animation; +// +// @override +// void initState() { +// super.initState(); +// _value = widget.value; +// animationController = +// AnimationController(vsync: this, duration: widget.duration); +// CurvedAnimation curvedAnimation = +// CurvedAnimation(parent: animationController, curve: widget.curve); +// animation = Tween(begin: 0.0, end: 180.0).animate(curvedAnimation) +// ..addListener(() { +// setState(() {}); +// }); +// } +// +// @override +// void dispose() { +// animationController.dispose(); +// +// super.dispose(); +// } +// +// @override +// void didUpdateWidget(LabeledToggle oldWidget) { +// super.didUpdateWidget(oldWidget); +// _value = widget.value; +// } +// +// @override +// Widget build(BuildContext context) { +// return GestureDetector( +// onTap: () { +// widget.onChanged == null ? print("") : widget.onChanged(!_value); +// if (widget.rotationAnimation) { +// if (animationController.status == AnimationStatus.completed) { +// animationController.reverse(); +// } else { +// animationController.forward(); +// } +// } +// }, +// child: Opacity( +// opacity: widget.onChanged == null ? 0.3 : 1.0, +// child: AnimatedContainer( +// duration: widget.duration, +// height: widget.thumbSize, +// width: widget.forceWidth ? widget.thumbSize * 1.7 : null, +// child: Stack( +// children: [ +// Padding( +// padding: const EdgeInsets.only(top:1.5, bottom: 1.5), +// child: AnimatedAlign( +// curve: widget.curve, +// +// alignment: _value ? Alignment.centerRight : Alignment.centerLeft, +// duration: widget.duration, +// child: RotationTransition( +// turns: AlwaysStoppedAnimation(animation.value / 360), +// child: AnimatedContainer( +// duration: widget.duration, +// width: widget.thumbSize, +// height: widget.thumbSize, +// child: widget?.child, +// decoration: BoxDecoration( +// shape: widget.rounded ? BoxShape.circle : BoxShape.rectangle, +// color: _value ? widget.onThumbColor : widget.offThumbColor, +// ), +// ), +// ), +// ), +// ), +// Padding( +// padding: EdgeInsets.only( +// right: _value ? widget.thumbSize : 1, +// left: _value ? 1.0 : widget.thumbSize), +// child: Row( +// children: [ +//// Expanded(child: Text('l')), +// Expanded( +// child: Padding( +// padding: const EdgeInsets.all(0), +// child: Container( +// height: widget.thumbSize, +// child: FittedBox( +// child: Center( +// child: AnimatedSwitcher( +// duration: widget.duration, +// switchInCurve: widget.curve, +// switchOutCurve: widget.curve, +// transitionBuilder: +// (Widget child, Animation animation) { +// switch (widget.transitionType) { +// case TextTransitionTypes.ROTATE: +// { +// return RotationTransition( +// child: child, +// turns: animation, +// ); +// } +// break; +// case TextTransitionTypes.FADE: +// { +// return FadeTransition( +// child: child, +// opacity: animation, +// ); +// } +// break; +// +// case TextTransitionTypes.SIZE: +// { +// return SizeTransition( +// child: child, +// sizeFactor: animation, +// axisAlignment: widget.value ? -5.0 : 5.0, +// axis: Axis.horizontal, +// ); +// } +// break; +// +// case TextTransitionTypes.SCALE: +// { +// return ScaleTransition( +// child: child, +// scale: animation, +// ); +// } +// break; +// } +// }, +// child: Text( +// _value ? widget.onText : widget.offText, +// key: ValueKey(_value), +// style: TextStyle( +// color: _value +// ? widget.onTextColor +// : widget.offTextColor), +// ), +// ), +// ), +// ), +// ), +// ), +// ), +// ], +// ), +// ) +// ], +// ), +// decoration: BoxDecoration( +// border: Border.all( +// color: widget.onChanged == null +// ? Color(0xFFD3D3D3) +// : _value +// ? (widget.onBorderColor ?? widget.onThumbColor) +// : (widget.offBorderColor ?? widget.offThumbColor), +// width: widget.borderSize), +// color: _value ? widget.onBkColor : widget.offBkColor, +// borderRadius: +// BorderRadius.circular(widget.rounded ? 100.0 : 0.0)), +// ), +// ), +// ); +// } +// +// +// } + + + + +enum TextTransitionTypes { ROTATE, SCALE, FADE, SIZE } + +class LabeledToggle extends StatefulWidget { + final Widget child; + final String onText; + final String offText; + final Color onTextColor; + final Color offTextColor; + final Color onThumbColor; + final Color offThumbColor; + final Color onBorderColor; + final Color offBorderColor; + final Color onBkColor; + final Color offBkColor; + final bool value; + final double thumbSize; + final double borderSize; + final Duration duration; + final Curve curve; + final ValueChanged onChanged; + final bool forceWidth; + final bool rounded; + final TextTransitionTypes transitionType; + final bool rotationAnimation; + + const LabeledToggle( + {Key key, + this.value = false, + this.onText = "", + this.offText = "", + this.onThumbColor, + this.offThumbColor, + this.onBorderColor, + this.offBorderColor, + this.onBkColor, + this.offBkColor, + this.onChanged, + @required this.thumbSize, + this.duration = const Duration(milliseconds: 400), + this.curve = Curves.linear, + this.forceWidth = false, + this.onTextColor = Colors.black, + this.offTextColor = Colors.black, + this.rounded = true, + this.borderSize = 1.0, + this.transitionType = TextTransitionTypes.SCALE, + this.rotationAnimation = false, + this.child}) + : assert(thumbSize != null), + super(key: key); + + const LabeledToggle.theme( + {Key key, + this.value = false, + this.onText = "", + this.offText = "", + @required onColor, + @required offColor, + this.onChanged, + @required this.thumbSize, + this.duration = const Duration(milliseconds: 400), + this.curve = Curves.linear, + this.forceWidth = false, + this.rounded = true, + this.borderSize = 1.0, + this.transitionType = TextTransitionTypes.SCALE, + this.rotationAnimation = false, + this.child}) + : assert(thumbSize != null), + onThumbColor = offColor, + onBorderColor = offColor, + onBkColor = onColor, + offThumbColor = onColor, + offBorderColor = onColor, + offBkColor = offColor, + onTextColor = offColor, + offTextColor = onColor, + super(key: key); + + @override + _LabeledToggleState createState() => _LabeledToggleState(); +} + +class _LabeledToggleState extends State + with SingleTickerProviderStateMixin { + bool _value; + AnimationController animationController; + Animation animation; + + @override + void initState() { + super.initState(); + _value = widget.value; + animationController = + AnimationController(vsync: this, duration: widget.duration); + CurvedAnimation curvedAnimation = + CurvedAnimation(parent: animationController, curve: widget.curve); + animation = Tween(begin: 0.0, end: 180.0).animate(curvedAnimation) + ..addListener(() { + setState(() {}); + }); + } + + @override + void dispose() { + animationController.dispose(); + + super.dispose(); + } + + @override + void didUpdateWidget(LabeledToggle oldWidget) { + super.didUpdateWidget(oldWidget); + _value = widget.value; + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: () { + widget.onChanged == null ? print("") : widget.onChanged(!_value); + if (widget.rotationAnimation) { + if (animationController.status == AnimationStatus.completed) { + animationController.reverse(); + } else { + animationController.forward(); + } + } + }, + child: + + Opacity( + opacity: widget.onChanged == null ? 0.3 : 1.0, + child: AnimatedContainer( + duration: widget.duration, + height: 20, + width: 40, +// width: widget.forceWidth ? widget.thumbSize * 1.4 : null, + child: Stack( + children: [ + AnimatedAlign( + curve: widget.curve, + alignment: _value ? Alignment.centerRight : Alignment.centerLeft, + duration: widget.duration, + child: RotationTransition( + turns: AlwaysStoppedAnimation(animation.value / 360), + child: AnimatedContainer( + + duration: widget.duration, + width: widget.thumbSize, + height: 150, + child: widget?.child, + decoration: BoxDecoration( + shape: widget.rounded ? BoxShape.circle : BoxShape.rectangle, + color: _value ? widget.onThumbColor : widget.offThumbColor, + ), + ), + ), + ), + Positioned( + + child: Padding( + padding: EdgeInsets.only( + right: _value ? widget.thumbSize : 1, + left: _value ? 2.0 : widget.thumbSize), + child: Row( + children: [ +// Expanded(child: Text('l')), + Expanded( + child: Padding( + padding: const EdgeInsets.all(0), + child: Container( + width: 80, + height: 100, + child: FittedBox( + child: Center( + child: AnimatedSwitcher( + duration: widget.duration, + switchInCurve: widget.curve, + switchOutCurve: widget.curve, + transitionBuilder: + (Widget child, Animation animation) { + switch (widget.transitionType) { + case TextTransitionTypes.ROTATE: + { + return RotationTransition( + child: child, + turns: animation, + ); + } + break; + case TextTransitionTypes.FADE: + { + return FadeTransition( + child: child, + opacity: animation, + ); + } + break; + + case TextTransitionTypes.SIZE: + { + return SizeTransition( + child: child, + sizeFactor: animation, + axisAlignment: widget.value ? -5.0 : 5.0, + axis: Axis.horizontal, + ); + } + break; + + case TextTransitionTypes.SCALE: + { + return ScaleTransition( + child: child, + scale: animation, + ); + } + break; + } + }, + child: Text( + _value ? widget.onText : widget.offText, + key: ValueKey(_value), + style: TextStyle( + color: _value + ? widget.onTextColor + : widget.offTextColor), + ), + ), + ), + ), + ), + ), + ), + ], + ), + )) + ], + ), + decoration: BoxDecoration( + border: Border.all( + color: widget.onChanged == null + ? Color(0xFFD3D3D3) + : _value + ? (widget.onBorderColor ?? widget.onThumbColor) + : (widget.offBorderColor ?? widget.offThumbColor), + width: widget.borderSize), + color: _value ? widget.onBkColor : widget.offBkColor, + borderRadius: + BorderRadius.circular(widget.rounded ? 100.0 : 0.0)), + ), + ), + ); + } + + +} diff --git a/lib/types/gf_toggle_type.dart b/lib/types/gf_toggle_type.dart new file mode 100644 index 00000000..629c424d --- /dev/null +++ b/lib/types/gf_toggle_type.dart @@ -0,0 +1 @@ +enum GFToggleType { androidSwitch, iosSwitch, labeledSwitch, animatedSwitch, } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index aebdafa4..67a7df16 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,27 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + archive: + dependency: transitive + description: + name: archive + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.11" + args: + dependency: transitive + description: + name: args + url: "https://pub.dartlang.org" + source: hosted + version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.3.0" + version: "2.4.0" boolean_selector: dependency: transitive description: @@ -29,6 +43,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.14.11" + convert: + dependency: transitive + description: + name: convert + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.1" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.3" flutter: dependency: "direct main" description: flutter @@ -39,20 +67,27 @@ packages: description: flutter source: sdk version: "0.0.0" + image: + dependency: transitive + description: + name: image + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" matcher: dependency: transitive description: 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.7" + version: "1.1.8" path: dependency: transitive description: @@ -67,6 +102,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" + petitparser: + dependency: transitive + description: + name: petitparser + url: "https://pub.dartlang.org" + source: hosted + version: "2.4.0" quiver: dependency: transitive description: @@ -120,7 +162,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.5" + version: "0.2.11" typed_data: dependency: transitive description: @@ -135,5 +177,12 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.8" + xml: + dependency: transitive + description: + name: xml + url: "https://pub.dartlang.org" + source: hosted + version: "3.5.0" sdks: - dart: ">=2.2.2 <3.0.0" + dart: ">=2.4.0 <3.0.0"