diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 6a4bd59..747ad15 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.3.3+1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.4\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.3.3+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.3.3+1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2024-05-16 18:44:01.201685","version":"3.19.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.3.3+1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.4\\\\","native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.3.3+1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"sqflite","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\sqflite-2.3.3+1\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\Micazi\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"sqflite","dependencies":[]}],"date_created":"2024-05-18 12:11:58.348151","version":"3.19.0"} \ No newline at end of file diff --git a/lib/src/Toggles/Checkbox/checkbox.toggle.dart b/lib/src/Toggles/Checkbox/checkbox.toggle.dart index 6e38839..1125b33 100644 --- a/lib/src/Toggles/Checkbox/checkbox.toggle.dart +++ b/lib/src/Toggles/Checkbox/checkbox.toggle.dart @@ -5,6 +5,8 @@ //s2 CORE import 'package:flutter/material.dart'; +import 'style.dart'; + //s2 3RD-PARTY // //s1 DEPENDENCIES @@ -26,34 +28,34 @@ class AstromicCheckboxToggle extends StatefulWidget { final void Function(bool)? onStateChanged; //s1 -- Configuration final bool? isEnabled; + final bool? withLabel; final bool? isLabelTapable; - final TextDirection textDirection; + final TextDirection? textDirection; //s1 -- Style - final double? itemSize; - final double? labelSpacing; + final AstromicCheckboxToggleStyle Function(bool isEnabled, bool isSelected) style; // //s1 -- Content - final Widget Function(bool isChecked, bool isEnabled, VoidCallback? onTap) itemBuilder; - final Widget Function(bool isChecked, bool isEnabled, VoidCallback? onTap)? labelBuilder; + final Widget Function(bool isEnabled, bool isSelected)? innerWidget; + final Widget Function(bool isEnabled, bool isSelected)? label; //!SECTION // - const AstromicCheckboxToggle( - {super.key, - //s1 -- Functionality - this.stateVariable, - this.initialState, - this.onStateChanged, - //s1 -- Configuration - this.isEnabled = true, - this.isLabelTapable = true, - this.textDirection = TextDirection.ltr, - //s1 -- Style - this.itemSize = 24, - this.labelSpacing = 6, - //s1 -- Content - required this.itemBuilder, - this.labelBuilder}) - : assert(stateVariable == null || initialState == null, "Can't define both the state variable and the initial state"); + const AstromicCheckboxToggle({ + super.key, + // + this.stateVariable, + this.initialState, + this.onStateChanged, + // + this.isEnabled = true, + this.withLabel = true, + this.isLabelTapable = true, + this.textDirection = TextDirection.ltr, + // + required this.style, + // + this.innerWidget, + this.label, + }) : assert(stateVariable == null || initialState == null, "Can't define both the state variable and the initial state"); @override State createState() => _AstromicCheckboxToggleState(); @@ -134,20 +136,31 @@ class _AstromicCheckboxToggleState extends State { //SECTION - Build Return return Directionality( - textDirection: widget.textDirection, + textDirection: widget.textDirection ?? TextDirection.ltr, child: Row( mainAxisSize: MainAxisSize.min, children: [ //S1 -- Item SizedBox( - width: widget.itemSize, - height: widget.itemSize, - child: widget.itemBuilder(isChecked, widget.isEnabled!, widget.isEnabled! ? () => _onTap() : null), - ), + width: widget.style(widget.isEnabled!, isChecked).itemSize, + height: widget.style(widget.isEnabled!, isChecked).itemSize, + child: Material( + child: InkWell( + onTap: widget.isEnabled! ? () => _onTap() : null, + child: Container( + decoration: BoxDecoration( + color: widget.style(widget.isEnabled!, isChecked).backgroundColor, + border: widget.style(widget.isEnabled!, isChecked).border, + borderRadius: widget.style(widget.isEnabled!, isChecked).borderRadius, + ), + child: widget.innerWidget != null ? widget.innerWidget!(widget.isEnabled!, isChecked) : Container(), + ), + ), + )), //S1 -- Label Spacing - if (widget.labelBuilder != null) SizedBox(width: widget.labelSpacing), + if (widget.withLabel!) SizedBox(width: widget.style(widget.isEnabled!, isChecked).labelSpacing), //S1 -- Label - if (widget.labelBuilder != null) widget.labelBuilder!(isChecked, widget.isEnabled!, widget.isEnabled! ? () => _onTap() : null), + if (widget.withLabel! && widget.label != null) GestureDetector(onTap: widget.isLabelTapable! ? _onTap() : null, child: widget.label!(widget.isEnabled!, isChecked)), ], ), ); diff --git a/lib/src/Toggles/Checkbox/style.dart b/lib/src/Toggles/Checkbox/style.dart new file mode 100644 index 0000000..d88c2f3 --- /dev/null +++ b/lib/src/Toggles/Checkbox/style.dart @@ -0,0 +1,39 @@ +// ignore_for_file: public_member_api_docs, sort_constructors_first +import 'package:flutter/material.dart'; + +class AstromicCheckboxToggleStyle { + final double? itemSize; + final double? labelSpacing; + // + final Border? border; + final BorderRadius? borderRadius; + final Color? backgroundColor; + final TextStyle? labelStyle; + + AstromicCheckboxToggleStyle({ + this.itemSize = 24.0, + this.labelSpacing = 8.0, + this.border, + this.borderRadius, + this.backgroundColor, + this.labelStyle, + }); + + AstromicCheckboxToggleStyle copyWith({ + double? itemSize, + double? labelSpacing, + Border? border, + BorderRadius? borderRadius, + Color? backgroundColor, + TextStyle? labelStyle, + }) { + return AstromicCheckboxToggleStyle( + itemSize: itemSize ?? this.itemSize, + labelSpacing: labelSpacing ?? this.labelSpacing, + border: border ?? this.border, + borderRadius: borderRadius ?? this.borderRadius, + backgroundColor: backgroundColor ?? this.backgroundColor, + labelStyle: labelStyle ?? this.labelStyle, + ); + } +} diff --git a/lib/src/Toggles/Custom/custom.toggle.dart b/lib/src/Toggles/Custom/custom.toggle.dart new file mode 100644 index 0000000..d4eb2a1 --- /dev/null +++ b/lib/src/Toggles/Custom/custom.toggle.dart @@ -0,0 +1,128 @@ +//SECTION - Imports +// +//s1 PACKAGES +//--------------- +//s2 CORE +import 'package:flutter/material.dart'; + +//s2 3RD-PARTY +// +//s1 DEPENDENCIES +//--------------- +//s2 SERVICES +//s2 MODELS +//s2 MISC +//!SECTION - Imports +// +//SECTION - Exports +//!SECTION - Exports +// +class AstromicCustomToggle extends StatefulWidget { + //SECTION - Widget Arguments + //s1 -- Functionality + /// If provided, you have to change the variable yourself in the onStateChanged! + final bool? stateVariable; + final bool? initialState; + final void Function(bool)? onStateChanged; + //s1 -- Configuration + final bool? isEnabled; + // + //s1 -- Content + final Widget Function(bool isChecked, bool isEnabled, VoidCallback? onTap) itemBuilder; + //!SECTION + // + const AstromicCustomToggle({ + super.key, + //s1 -- Functionality + this.stateVariable, + this.initialState, + this.onStateChanged, + //s1 -- Configuration + this.isEnabled = true, + //s1 -- Content + required this.itemBuilder, + }) : assert(stateVariable == null || initialState == null, "Can't define both the state variable and the initial state"); + + @override + State createState() => _AstromicCustomToggleState(); +} + +class _AstromicCustomToggleState extends State { + // + //SECTION - State Variables + //s1 --Controllers + //s1 --Controllers + // + //s1 --State + late bool currentState; + //s1 --State + // + //s1 --Constants + //s1 --Constants + //!SECTION + + @override + void initState() { + super.initState(); + // + //SECTION - State Variables initializations & Listeners + //s1 --Controllers & Listeners + //s1 --Controllers & Listeners + // + //s1 --State + currentState = widget.initialState ?? widget.stateVariable ?? false; + //s1 --State + // + //s1 --Late & Async Initializers + //s1 --Late & Async Initializers + //!SECTION + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + // + //SECTION - State Variables initializations & Listeners + //s1 --State + //s1 --State + //!SECTION + } + + @override + void didUpdateWidget(AstromicCustomToggle oldWidget) { + if (widget.stateVariable != null && widget.stateVariable != oldWidget.stateVariable) { + currentState = widget.stateVariable!; + } + super.didUpdateWidget(oldWidget); + } + + //SECTION - Stateless functions + //!SECTION + + //SECTION - Action Callbacks + _onTap() { + setState(() { + currentState = !currentState; + if (widget.onStateChanged != null) widget.onStateChanged!(currentState); + }); + } + //!SECTION + + @override + Widget build(BuildContext context) { + //SECTION - Build Setup + //s1 -Values + //double w = MediaQuery.of(context).size.width; + //double h = MediaQuery.of(context).size.height; + //s1 -Values + // + //s1 -Widgets + //s1 -Widgets + //!SECTION + + //SECTION - Build Return + return widget.itemBuilder(currentState, widget.isEnabled!, widget.isEnabled! ? () => _onTap() : null); + + //!SECTION + } +} diff --git a/lib/src/Toggles/Switcher/style.dart b/lib/src/Toggles/Switcher/style.dart new file mode 100644 index 0000000..2a1aa36 --- /dev/null +++ b/lib/src/Toggles/Switcher/style.dart @@ -0,0 +1,41 @@ +import 'package:flutter/widgets.dart'; + +class AstromicSwitcherToggleStyle { + final double width; + final double height; + final double labelSpacing; + final double toggleSize; + final double togglePadding; + final double borderRadius; + // + final Color activeColor; + final Color? activeToggleColor; + final BoxBorder? activeToggleBorder; + final BoxBorder? activeSwitchBorder; + final Widget? innerActiveWidget; + // + final Color inactiveColor; + final Color? inactiveToggleColor; + final BoxBorder? inactiveSwitchBorder; + final BoxBorder? inactiveToggleBorder; + final Widget? innerInactiveWidget; + // + const AstromicSwitcherToggleStyle({ + this.width = 70, + this.height = 35, + this.labelSpacing = 12, + this.borderRadius = 20, + this.toggleSize = 24, + this.activeColor = const Color(0xFFC71717), + this.activeToggleColor, + this.inactiveColor = const Color(0xfffefefe), + this.inactiveToggleColor, + this.togglePadding = 12, + this.activeSwitchBorder, + this.activeToggleBorder, + this.inactiveSwitchBorder, + this.inactiveToggleBorder, + this.innerActiveWidget, + this.innerInactiveWidget, + }); +} diff --git a/lib/src/Toggles/Switcher/switcher.toggle.dart b/lib/src/Toggles/Switcher/switcher.toggle.dart new file mode 100644 index 0000000..a2152ba --- /dev/null +++ b/lib/src/Toggles/Switcher/switcher.toggle.dart @@ -0,0 +1,149 @@ +// ignore_for_file: public_member_api_docs, sort_constructors_first +//s2 Core Packages Imports +import 'package:flutter/material.dart'; +import 'package:flutter_switch/flutter_switch.dart'; +//s2 Dependancies Imports +//s3 Services +//s3 Models +import 'style.dart'; +//s1 Exports +// + +// +class AstromicSwitcherToggle extends StatefulWidget { + //SECTION - Widget Arguments + //s1 -- Functionality + /// If provided, you have to change the variable yourself in the onStateChanged! + final bool? stateVariable; + final bool? initialState; + final void Function(bool)? onStateChanged; + //s1 -- Configuration + final bool? isEnabled; + final bool? withLabel; + final bool? isLabelTapable; + final TextDirection? textDirection; + //s1 -- Style + final AstromicSwitcherToggleStyle Function(bool isEnabled, bool isSelected) style; + //s1 -- Content + final Widget Function(bool isEnabled, bool isSelected)? label; + //!SECTION + // + const AstromicSwitcherToggle({ + super.key, + this.stateVariable, + this.initialState, + this.onStateChanged, + // + this.isEnabled = true, + this.withLabel = true, + this.isLabelTapable = true, + this.textDirection = TextDirection.ltr, + // + required this.style, + // + this.label, + }); + + @override + State createState() => AstromicSwitcherToggleState(); +} + +class AstromicSwitcherToggleState extends State { + // + //SECTION - State Variables + //s1 --Controllers + //s1 --Controllers + // + //s1 --State + late bool _currentState; + //s1 --State + // + //s1 --Constants + //s1 --Constants + //!SECTION + + @override + void initState() { + super.initState(); + // + //SECTION - State Variables initializations & Listeners + //s1 --Controllers & Listeners + //s1 --Controllers & Listeners + // + //s1 --State + _currentState = widget.initialState ?? widget.stateVariable ?? false; + //s1 --State + // + //s1 --Late & Async Initializers + //s1 --Late & Async Initializers + //!SECTION + } + + @override + void didUpdateWidget(AstromicSwitcherToggle oldWidget) { + if (widget.stateVariable != null && widget.stateVariable != oldWidget.stateVariable) { + _currentState = widget.stateVariable!; + } + super.didUpdateWidget(oldWidget); + } + + //SECTION - Action Callbacks + _onTap(bool newValue) { + setState(() { + _currentState = newValue; + if (widget.onStateChanged != null) widget.onStateChanged!(_currentState); + }); + } + //!SECTION + + @override + Widget build(BuildContext context) { + //SECTION - Build Setup + //s1 -Values + //s1 -Values + // + //s1 -Widgets + //s1 -Widgets + //!SECTION + + //SECTION - Build Return + return Directionality( + textDirection: widget.textDirection ?? TextDirection.ltr, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + //S1 -- Item + FlutterSwitch( + width: widget.style(widget.isEnabled!, _currentState).width, + height: widget.style(widget.isEnabled!, _currentState).height, + borderRadius: widget.style(widget.isEnabled!, _currentState).borderRadius, + value: _currentState, + toggleSize: widget.style(widget.isEnabled!, _currentState).toggleSize, + disabled: false, + // + activeColor: widget.style(widget.isEnabled!, _currentState).activeColor, + activeToggleColor: widget.style(widget.isEnabled!, _currentState).activeToggleColor, + activeSwitchBorder: widget.style(widget.isEnabled!, _currentState).activeSwitchBorder, + activeToggleBorder: widget.style(widget.isEnabled!, _currentState).activeToggleBorder, + activeIcon: widget.style(widget.isEnabled!, _currentState).innerActiveWidget, + // + inactiveColor: widget.style(widget.isEnabled!, _currentState).inactiveColor, + inactiveToggleColor: widget.style(widget.isEnabled!, _currentState).inactiveToggleColor, + inactiveSwitchBorder: widget.style(widget.isEnabled!, _currentState).inactiveSwitchBorder, + inactiveToggleBorder: widget.style(widget.isEnabled!, _currentState).inactiveToggleBorder, + inactiveIcon: widget.style(widget.isEnabled!, _currentState).innerInactiveWidget, + // + padding: widget.style(widget.isEnabled!, _currentState).togglePadding, + showOnOff: false, + onToggle: (s) => _onTap(s), + ), + //S1 -- Label Spacing + if (widget.withLabel!) SizedBox(width: widget.style(widget.isEnabled!, _currentState).labelSpacing), + //S1 -- Label + if (widget.withLabel! && widget.label != null) GestureDetector(onTap: widget.isLabelTapable! ? _onTap(!_currentState) : null, child: widget.label!(widget.isEnabled!, _currentState)), + ], + ), + ); + //!SECTION + } +} diff --git a/lib/src/Toggles/toggles.astromic.dart b/lib/src/Toggles/toggles.astromic.dart index 194aac4..433ead2 100644 --- a/lib/src/Toggles/toggles.astromic.dart +++ b/lib/src/Toggles/toggles.astromic.dart @@ -1,6 +1,14 @@ //s2 Core Packages Imports import 'package:flutter/widgets.dart'; import 'Checkbox/checkbox.toggle.dart'; +import 'Switcher/switcher.toggle.dart'; +import 'Custom/custom.toggle.dart'; +// +import 'Switcher/style.dart'; +import 'Checkbox/style.dart'; +// +export 'Switcher/style.dart'; +export 'Checkbox/style.dart'; class AstromicToggles { //S1 -- Checkbox @@ -11,26 +19,74 @@ class AstromicToggles { void Function(bool)? onStateChanged, // bool? isEnabled, + bool? withLabel, bool? isLabelTapable, TextDirection? textDirection, // - double? itemSize, - double? labelSpacing, + required AstromicCheckboxToggleStyle Function(bool isEnabled, bool isSelected) style, // + Widget Function(bool isEnabled, bool isSelected)? innerWidget, + Widget Function(bool isEnabled, bool isSelected)? label, // - required Widget Function(bool isChecked, bool isEnabled, VoidCallback? onTap) itemBuilder, - Widget Function(bool isChecked, bool isEnabled, VoidCallback? onTap)? labelBuilder, }) => AstromicCheckboxToggle( stateVariable: stateVariable, initialState: initialState, onStateChanged: onStateChanged, isEnabled: isEnabled ?? true, - isLabelTapable: isLabelTapable ?? true, + withLabel: withLabel ?? false, + isLabelTapable: isLabelTapable ?? false, textDirection: textDirection ?? TextDirection.ltr, - itemSize: itemSize ?? 24.0, - labelSpacing: labelSpacing ?? 8.0, + style: style, + innerWidget: innerWidget, + label: label, + ); + + //S1 -- Switcher + static Widget switcher({ + // + bool? stateVariable, + bool? initialState, + void Function(bool)? onStateChanged, + // + bool? isEnabled, + bool? withLabel, + bool? isLabelTapable, + TextDirection? textDirection, + // + required AstromicSwitcherToggleStyle Function(bool isEnabled, bool isSelected) style, + // + Widget Function(bool isEnabled, bool isSelected)? label, + // + }) => + AstromicSwitcherToggle( + stateVariable: stateVariable, + initialState: initialState, + onStateChanged: onStateChanged, + isEnabled: isEnabled ?? true, + withLabel: withLabel ?? false, + isLabelTapable: isLabelTapable ?? false, + textDirection: textDirection ?? TextDirection.ltr, + style: style, + label: label, + ); + + //S1 -- Custom + static Widget custom({ + // + bool? stateVariable, + bool? initialState, + void Function(bool)? onStateChanged, + // + bool? isEnabled, + // + required Widget Function(bool isChecked, bool isEnabled, VoidCallback? onTap) itemBuilder, + }) => + AstromicCustomToggle( + stateVariable: stateVariable, + initialState: initialState, + onStateChanged: onStateChanged, + isEnabled: isEnabled ?? true, itemBuilder: itemBuilder, - labelBuilder: labelBuilder, ); } diff --git a/pubspec.yaml b/pubspec.yaml index 87f7281..35a7c2f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,7 @@ dependencies: cached_network_image: ^3.3.1 flutter_svg: ^2.0.10+1 octo_image: ^2.0.0 + flutter_switch: ^0.3.2 # ##!SECTION --Dependencies #