@@ -2,33 +2,36 @@ import 'package:flutter/material.dart';
22import 'package:getwidget/getwidget.dart' ;
33
44class GFCheckbox extends StatefulWidget {
5- const GFCheckbox ({
6- Key key,
7- this .size = GFSize .MEDIUM ,
8- this .type = GFCheckboxType .basic,
9- this .checkColor = GFColors .WHITE ,
10- this .activebgColor = GFColors .PRIMARY ,
11- this .inactivebgColor = GFColors .WHITE ,
12- this .activeBorderColor = GFColors .WHITE ,
13- this .inactiveBorderColor = GFColors .DARK ,
14- this .onChanged,
15- this .value,
16- this .activeIcon = const Icon (
17- Icons .check,
18- size: 20 ,
19- color: GFColors .WHITE ,
20- ),
21- this .inactiveIcon = const Icon (Icons .close),
22- this .custombgColor = GFColors .SUCCESS ,
23- }) : super (key: key);
5+ const GFCheckbox (
6+ {Key key,
7+ this .size = GFSize .MEDIUM ,
8+ this .type = GFCheckboxType .basic,
9+ this .checkColor = GFColors .WHITE ,
10+ this .activebgColor = GFColors .PRIMARY ,
11+ this .inactivebgColor = GFColors .WHITE ,
12+ this .activeBorderColor = GFColors .WHITE ,
13+ this .inactiveBorderColor = GFColors .DARK ,
14+ this .onChanged,
15+ this .value,
16+ this .activeIcon = const Icon (
17+ Icons .check,
18+ size: 20 ,
19+ color: GFColors .WHITE ,
20+ ),
21+ this .inactiveIcon = const Icon (Icons .close),
22+ this .custombgColor = GFColors .SUCCESS ,
23+ this .autofocus = false ,
24+ this .focusNode})
25+ : assert (autofocus != null ),
26+ super (key: key);
2427
2528 /// type of [GFCheckboxType] which is of four type is basic, sqaure, circular and custom
2629 final GFCheckboxType type;
2730
2831 /// type of [double] which is GFSize ie, small, medium and large and can use any double value
2932 final double size;
3033
31- // type pf [Color] used to change the checkcolor when the checkbox is active
34+ /// type pf [Color] used to change the checkcolor when the checkbox is active
3235 final Color checkColor;
3336
3437 /// type of [Color] used to change the backgroundColor of the active checkbox
@@ -58,40 +61,42 @@ class GFCheckbox extends StatefulWidget {
5861 /// type of [Color] used to change the background color of the custom active checkbox only
5962 final Color custombgColor;
6063
64+ /// {@macro flutter.widgets.Focus.autofocus}
65+ final bool autofocus;
66+
67+ /// {@macro flutter.widgets.Focus.focusNode}
68+ final FocusNode focusNode;
69+
6170 @override
6271 _GFCheckboxState createState () => _GFCheckboxState ();
6372}
6473
6574class _GFCheckboxState extends State <GFCheckbox > {
6675 bool get enabled => widget.onChanged != null ;
67- bool isSelected = false ;
6876
6977 @override
7078 void initState () {
7179 super .initState ();
72- isSelected = widget.value ?? false ;
73- }
74-
75- void onStatusChange () {
76- setState (() {
77- isSelected = ! isSelected;
78- });
79- if (widget.onChanged != null ) {
80- widget.onChanged (isSelected);
81- }
8280 }
8381
8482 @override
8583 Widget build (BuildContext context) => FocusableActionDetector (
84+ focusNode: widget.focusNode,
85+ autofocus: widget.autofocus,
8686 enabled: enabled,
8787 child: InkWell (
88- onTap: onStatusChange,
88+ canRequestFocus: enabled,
89+ onTap: widget.onChanged != null
90+ ? () {
91+ widget.onChanged (! widget.value);
92+ }
93+ : null ,
8994 child: Container (
9095 height: widget.size,
9196 width: widget.size,
9297 decoration: BoxDecoration (
9398 color: enabled
94- ? isSelected
99+ ? widget.value
95100 ? widget.type == GFCheckboxType .custom
96101 ? Colors .white
97102 : widget.activebgColor
@@ -103,12 +108,12 @@ class _GFCheckboxState extends State<GFCheckbox> {
103108 ? BorderRadius .circular (50 )
104109 : BorderRadius .zero,
105110 border: Border .all (
106- color: isSelected
111+ color: widget.value
107112 ? widget.type == GFCheckboxType .custom
108113 ? Colors .black87
109114 : widget.activeBorderColor
110115 : widget.inactiveBorderColor)),
111- child: isSelected
116+ child: widget.value
112117 ? widget.type == GFCheckboxType .custom
113118 ? Stack (
114119 children: < Widget > [
0 commit comments