Switches updated

This commit is contained in:
Mohammad Salameh
2024-02-27 10:13:58 +03:00
parent abe7072f2d
commit 4c27cce519
14 changed files with 89 additions and 74 deletions

View File

@ -22,20 +22,24 @@ class _CustomSwitchState extends State<CustomSwitch>
bool value = false;
void onChange(bool customValue){
value = customValue ;
void onChange(bool customValue) {
value = customValue;
}
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 100));
vsync: this, duration: const Duration(milliseconds: 300));
_circleAnimation = AlignmentTween(
begin: value ? Alignment.centerRight : Alignment.centerLeft,
end: value ? Alignment.centerLeft : Alignment.centerRight)
.animate(CurvedAnimation(
parent: _animationController!, curve: Curves.linear));
begin: value ? Alignment.centerRight : Alignment.centerLeft,
end: value ? Alignment.centerLeft : Alignment.centerRight,
).animate(
CurvedAnimation(
parent: _animationController!,
curve: Curves.linear,
),
);
}
@override
@ -49,9 +53,7 @@ class _CustomSwitchState extends State<CustomSwitch>
_animationController!.isCompleted
? _animationController!.reverse()
: _animationController!.forward();
value == false
? onChange(true)
: onChange(false);
value ? onChange(false) : onChange(true);
});
},
child: Container(
@ -60,20 +62,33 @@ class _CustomSwitchState extends State<CustomSwitch>
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: _circleAnimation!.value == Alignment.centerLeft
? Colors.grey
? Color(0xFFD9D9D9)
: ColorsManager.primaryColor,
),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Center(
child: Container(
alignment: value
? Alignment.centerRight
: Alignment.centerLeft,
child: Container(
width: 20.0,
height: 20.0,
decoration: const BoxDecoration(
shape: BoxShape.circle, color: Colors.white),
width: 40.0,
height: 23.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.white,
),
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
alignment:
value ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: _circleAnimation!.value == Alignment.centerLeft
? Color(0xFFD9D9D9)
: ColorsManager.primaryColor,
),
),
),
),
),
),