File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,28 +56,35 @@ class _FlutterSwitchState extends State<FlutterSwitch>
5656 CurvedAnimation (parent: _animationController, curve: Curves .linear),
5757 );
5858 }
59-
59+
6060 @override
6161 void dispose () {
6262 _animationController.dispose ();
6363 super .dispose ();
6464 }
6565
66+ @override
67+ void didUpdateWidget (FlutterSwitch oldWidget) {
68+ super .didUpdateWidget (oldWidget);
69+ if (widget.value)
70+ _animationController.forward ();
71+ else
72+ _animationController.reverse ();
73+ }
74+
6675 @override
6776 Widget build (BuildContext context) {
6877 return AnimatedBuilder (
6978 animation: _animationController,
7079 builder: (context, child) {
7180 return GestureDetector (
7281 onTap: () {
73- if (_animationController.isCompleted) {
82+ if (widget.value)
7483 _animationController.reverse ();
75- } else {
84+ else
7685 _animationController.forward ();
77- }
78- widget.value == false
79- ? widget.onToggle (true )
80- : widget.onToggle (false );
86+
87+ widget.onToggle (! widget.value);
8188 },
8289 child: Container (
8390 width: widget.width,
You can’t perform that action at this time.
0 commit comments