Skip to content
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

More customisation added, All pull request has been added. #53

Open
wants to merge 2 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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[![pub package](https://img.shields.io/pub/v/flutter_switch.svg)](https://pub.dev/packages/flutter_switch) [![pub points](https://badges.bar/flutter_switch/pub%20points)](https://pub.dev/packages/flutter_switch/score) [![popularity](https://badges.bar/flutter_switch/popularity)](https://pub.dev/packages/flutter_switch/score) [![likes](https://badges.bar/flutter_switch/likes)](https://pub.dev/packages/flutter_switch/score) <a href="https://github.com/boringdeveloper/FlutterSwitch/actions"><img src="https://img.shields.io/github/workflow/status/boringdeveloper/FlutterSwitch/Widget%20Test?label=build"></a>

An easy to implement custom switch created for Flutter. Give it a custom height and width, border for the switch and toggle, border radius, colors, toggle size, a choice to display an 'On' and 'Off' text and able to add an icon inside the toggle.
An easy to implement custom switch created for Flutter. Give it a custom height and width, border for the switch and toggle, border radius, colors, toggle size, a choice to display an 'On' and 'Off' text and able to add an icon inside the toggle. You can also use your own custom widget to display instead of displaying an 'On' and 'Off' text.

[![GitHub followers](https://img.shields.io/github/followers/boringdeveloper.svg?style=social&label=Follow)](https://github.com/boringdeveloper) <a href="https://www.linkedin.com/in/nichole-john-talban-romero/"><img src="https://img.icons8.com/doodle/452/linkedin--v2.png" width="20"></a> <a href="https://twitter.com/nickrdev"><img src="https://img.icons8.com/doodle/452/twitter--v1.png" width="20"></a>

Expand All @@ -22,7 +22,7 @@ Add this to your package's `pubspec.yaml` file:

```yaml
dependencies:
flutter_switch: ^0.3.1
flutter_switch: ^0.3.3
```

You can install packages from the command line with Flutter:
Expand Down Expand Up @@ -77,10 +77,10 @@ class _MyHomePageState extends State<MyHomePage> {

## Want to Contribute?

Contributions to this project is very much welcome. Let's work together to maintain and improve the project
Contributions to this project is very much welcome. Let's work together to maintain and improve this project.
Simply Fork the repository, Commit and Push your changes and create a new Pull Request.

Don't forget to try out the example project under the ./example folder.
Don't forget to try out the example project under the [./example](https://github.com/boringdeveloper/FlutterSwitch/tree/master/example) folder.

Also test your changes by running this command.
```bash
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -15,6 +15,7 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:exported="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
11 changes: 5 additions & 6 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.21'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}


task clean(type: Delete) {
delete rootProject.buildDir
}
1 change: 0 additions & 1 deletion example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
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-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
89 changes: 69 additions & 20 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class _MyHomePageState extends State<MyHomePage> {
bool status6 = false;
bool status7 = false;
bool status8 = false;
bool status9 = false;
bool isSwitchOn = false;

Color _textColor = Colors.black;
Expand Down Expand Up @@ -129,16 +130,40 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
SizedBox(height: 20.0),
Text("With 'On' and 'Off' text and custom text colors"),
Text("Custom Decoration"),
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlutterSwitch(
showOnOff: true,
activeTextColor: Colors.black,
inactiveTextColor: Colors.blue[50],
width: 100.0,
height: 55.0,
toggleSize: 45.0,
value: status3,
padding: 2.0,
toggleColor: Color.fromRGBO(225, 225, 225, 1),
toggleBorder: Border.all(
color: Color.fromRGBO(2, 107, 206, 1),
width: 5.0,
),
activeDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
gradient: LinearGradient(
colors: [
Colors.red,
Colors.orange,
],
),
),
inactiveDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
gradient: LinearGradient(
colors: [
Colors.blue,
Colors.orange,
],
),
),
onToggle: (val) {
setState(() {
status3 = val;
Expand All @@ -154,6 +179,31 @@ class _MyHomePageState extends State<MyHomePage> {
],
),
SizedBox(height: 20.0),
Text("With 'On' and 'Off' text and custom text colors"),
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlutterSwitch(
showOnOff: true,
activeTextColor: Colors.black,
inactiveTextColor: Colors.blue.shade50,
value: status4,
onToggle: (val) {
setState(() {
status4 = val;
});
},
),
Container(
alignment: Alignment.centerRight,
child: Text(
"Value: $status4",
),
),
],
),
SizedBox(height: 20.0),
Text("Custom size"),
SizedBox(height: 10.0),
Row(
Expand All @@ -164,17 +214,17 @@ class _MyHomePageState extends State<MyHomePage> {
height: 25.0,
valueFontSize: 12.0,
toggleSize: 18.0,
value: status4,
value: status5,
onToggle: (val) {
setState(() {
status4 = val;
status5 = val;
});
},
),
Container(
alignment: Alignment.centerRight,
child: Text(
"Value: $status4",
"Value: $status5",
),
),
],
Expand All @@ -190,20 +240,20 @@ class _MyHomePageState extends State<MyHomePage> {
height: 55.0,
valueFontSize: 25.0,
toggleSize: 45.0,
value: status5,
value: status6,
borderRadius: 30.0,
padding: 8.0,
showOnOff: true,
onToggle: (val) {
setState(() {
status5 = val;
status6 = val;
});
},
),
Container(
alignment: Alignment.centerRight,
child: Text(
"Value: $status5",
"Value: $status6",
),
),
],
Expand All @@ -217,21 +267,21 @@ class _MyHomePageState extends State<MyHomePage> {
FlutterSwitch(
activeText: "All Good. Negative.",
inactiveText: "Under Quarantine.",
value: status6,
value: status7,
valueFontSize: 10.0,
width: 110,
borderRadius: 30.0,
showOnOff: true,
onToggle: (val) {
setState(() {
status6 = val;
status7 = val;
});
},
),
Container(
alignment: Alignment.centerRight,
child: Text(
"Value: $status6",
"Value: $status7",
),
),
],
Expand All @@ -253,7 +303,7 @@ class _MyHomePageState extends State<MyHomePage> {
width: 100.0,
height: 55.0,
toggleSize: 45.0,
value: status7,
value: status8,
borderRadius: 30.0,
padding: 2.0,
activeToggleColor: Color(0xFF6E40C9),
Expand All @@ -278,8 +328,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
onToggle: (val) {
setState(() {
status7 = val;

status8 = val;
if (val) {
_textColor = Colors.white;
_appBarColor = Color.fromRGBO(22, 27, 34, 1);
Expand All @@ -294,7 +343,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
Container(
alignment: Alignment.centerRight,
child: Text("Value: $status7"),
child: Text("Value: $status8"),
),
],
),
Expand All @@ -308,7 +357,7 @@ class _MyHomePageState extends State<MyHomePage> {
width: 100.0,
height: 55.0,
toggleSize: 45.0,
value: status8,
value: status9,
borderRadius: 30.0,
padding: 2.0,
activeToggleColor: Color(0xFF0082C8),
Expand All @@ -331,13 +380,13 @@ class _MyHomePageState extends State<MyHomePage> {
),
onToggle: (val) {
setState(() {
status8 = val;
status9 = val;
});
},
),
Container(
alignment: Alignment.centerRight,
child: Text("Value: $status8"),
child: Text("Value: $status9"),
),
],
),
Expand Down
Loading