[SYNC] Done with the checkbox toggle.
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
//---------------
|
//---------------
|
||||||
//s2 CORE
|
//s2 CORE
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/scheduler.dart';
|
|
||||||
|
|
||||||
//s2 3RD-PARTY
|
//s2 3RD-PARTY
|
||||||
//
|
//
|
||||||
@@ -21,6 +20,7 @@ import 'package:flutter/scheduler.dart';
|
|||||||
class AstromicCheckboxToggle extends StatefulWidget {
|
class AstromicCheckboxToggle extends StatefulWidget {
|
||||||
//SECTION - Widget Arguments
|
//SECTION - Widget Arguments
|
||||||
//s1 -- Functionality
|
//s1 -- Functionality
|
||||||
|
/// If provided, you have to change the variable yourself in the onStateChanged!
|
||||||
final bool? stateVariable;
|
final bool? stateVariable;
|
||||||
final bool? initialState;
|
final bool? initialState;
|
||||||
final void Function(bool)? onStateChanged;
|
final void Function(bool)? onStateChanged;
|
||||||
@@ -38,7 +38,7 @@ class AstromicCheckboxToggle extends StatefulWidget {
|
|||||||
//!SECTION
|
//!SECTION
|
||||||
//
|
//
|
||||||
const AstromicCheckboxToggle(
|
const AstromicCheckboxToggle(
|
||||||
{Key? key,
|
{super.key,
|
||||||
//s1 -- Functionality
|
//s1 -- Functionality
|
||||||
this.stateVariable,
|
this.stateVariable,
|
||||||
this.initialState,
|
this.initialState,
|
||||||
@@ -53,9 +53,7 @@ class AstromicCheckboxToggle extends StatefulWidget {
|
|||||||
//s1 -- Content
|
//s1 -- Content
|
||||||
required this.itemBuilder,
|
required this.itemBuilder,
|
||||||
this.labelBuilder})
|
this.labelBuilder})
|
||||||
: super(
|
: assert(stateVariable == null || initialState == null, "Can't define both the state variable and the initial state");
|
||||||
key: key,
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AstromicCheckboxToggle> createState() => _AstromicCheckboxToggleState();
|
State<AstromicCheckboxToggle> createState() => _AstromicCheckboxToggleState();
|
||||||
@@ -84,7 +82,6 @@ class _AstromicCheckboxToggleState extends State<AstromicCheckboxToggle> {
|
|||||||
//s1 --Controllers & Listeners
|
//s1 --Controllers & Listeners
|
||||||
//
|
//
|
||||||
//s1 --State
|
//s1 --State
|
||||||
|
|
||||||
isChecked = widget.initialState ?? widget.stateVariable ?? false;
|
isChecked = widget.initialState ?? widget.stateVariable ?? false;
|
||||||
//s1 --State
|
//s1 --State
|
||||||
//
|
//
|
||||||
@@ -102,6 +99,15 @@ class _AstromicCheckboxToggleState extends State<AstromicCheckboxToggle> {
|
|||||||
//s1 --State
|
//s1 --State
|
||||||
//!SECTION
|
//!SECTION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(AstromicCheckboxToggle oldWidget) {
|
||||||
|
if (widget.stateVariable != null && widget.stateVariable != oldWidget.stateVariable) {
|
||||||
|
isChecked = widget.stateVariable!;
|
||||||
|
}
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
}
|
||||||
|
|
||||||
//SECTION - Stateless functions
|
//SECTION - Stateless functions
|
||||||
//!SECTION
|
//!SECTION
|
||||||
|
|
||||||
@@ -118,11 +124,6 @@ class _AstromicCheckboxToggleState extends State<AstromicCheckboxToggle> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
//SECTION - Build Setup
|
//SECTION - Build Setup
|
||||||
//s1 -Values
|
//s1 -Values
|
||||||
if (widget.stateVariable != null) {
|
|
||||||
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
|
|
||||||
isChecked = widget.stateVariable!;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//double w = MediaQuery.of(context).size.width;
|
//double w = MediaQuery.of(context).size.width;
|
||||||
//double h = MediaQuery.of(context).size.height;
|
//double h = MediaQuery.of(context).size.height;
|
||||||
//s1 -Values
|
//s1 -Values
|
||||||
@@ -141,12 +142,12 @@ class _AstromicCheckboxToggleState extends State<AstromicCheckboxToggle> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
width: widget.itemSize,
|
width: widget.itemSize,
|
||||||
height: widget.itemSize,
|
height: widget.itemSize,
|
||||||
child: widget.itemBuilder(isChecked, widget.isEnabled!, () => _onTap()),
|
child: widget.itemBuilder(isChecked, widget.isEnabled!, widget.isEnabled! ? () => _onTap() : null),
|
||||||
),
|
),
|
||||||
//S1 -- Label Spacing
|
//S1 -- Label Spacing
|
||||||
if (widget.labelBuilder != null) SizedBox(width: widget.labelSpacing),
|
if (widget.labelBuilder != null) SizedBox(width: widget.labelSpacing),
|
||||||
//S1 -- Label
|
//S1 -- Label
|
||||||
if (widget.labelBuilder != null) widget.labelBuilder!(isChecked, widget.isEnabled!, () => _onTap()),
|
if (widget.labelBuilder != null) widget.labelBuilder!(isChecked, widget.isEnabled!, widget.isEnabled! ? () => _onTap() : null),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user