Skip to content

Commit b953851

Browse files
committed
GFCheckbox issue fixed
1 parent a57107a commit b953851

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

example/lib/main_temp.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ class _MyHomePageState extends State<MyHomePage>
157157
Container(
158158
height: 10,
159159
),
160-
161-
// CheckboxListTile(value: null, onChanged: null),
160+
162161

163162
GFCheckboxListTile(
164163
color: GFColors.LIGHT,
@@ -189,7 +188,6 @@ class _MyHomePageState extends State<MyHomePage>
189188
size: GFSize.SMALL,
190189
activebgColor: GFColors.DANGER,
191190
onChanged:
192-
// null,
193191
(val) {
194192
setState(() {
195193
check = val;
@@ -234,6 +232,8 @@ class _MyHomePageState extends State<MyHomePage>
234232
// groupValue:
235233
),
236234

235+
236+
237237
const Padding(
238238
padding: EdgeInsets.only(left: 15, top: 30),
239239
child: GFTypography(
@@ -270,7 +270,7 @@ class _MyHomePageState extends State<MyHomePage>
270270
onChanged: (val) {
271271
print('on change val $val');
272272
},
273-
value: true,
273+
value: false,
274274
inactiveIcon: null,
275275
),
276276
],

lib/components/checkbox/gf_checkbox.dart

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,65 +78,60 @@ class GFCheckbox extends StatefulWidget {
7878

7979
class _GFCheckboxState extends State<GFCheckbox> {
8080
bool get enabled => widget.onChanged != null;
81-
Map<Type, Action<Intent>> _actionMap;
82-
bool isSelected = false;
81+
// Map<Type, Action<Intent>> _actionMap;
82+
// bool isSelected = false;
8383

8484
@override
8585
void initState() {
8686
super.initState();
87-
isSelected = widget.value;
88-
_actionMap = <Type, Action<Intent>>{
89-
ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _actionHandler),
90-
};
87+
// isSelected = widget.value;
88+
// _actionMap = <Type, Action<Intent>>{
89+
// ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _actionHandler),
90+
// };
9191
}
9292

93-
void _actionHandler(ActivateIntent intent) {
94-
if (widget.onChanged != null) {
95-
switch (widget.value) {
96-
case false:
97-
widget.onChanged(true);
98-
break;
99-
default: // case null:
100-
widget.onChanged(false);
101-
break;
102-
}
103-
}
104-
final RenderObject renderObject = context.findRenderObject();
105-
renderObject.sendSemanticsEvent(const TapSemanticEvent());
106-
}
107-
108-
void onStatusChange() {
109-
setState(() {
110-
isSelected = !isSelected;
111-
});
112-
if (widget.onChanged != null) {
113-
widget.onChanged(isSelected);
114-
}
115-
}
93+
// void _actionHandler(ActivateIntent intent) {
94+
// if (widget.onChanged != null) {
95+
// switch (widget.value) {
96+
// case false:
97+
// widget.onChanged(true);
98+
// break;
99+
// default: // case null:
100+
// widget.onChanged(false);
101+
// break;
102+
// }
103+
// }
104+
// final RenderObject renderObject = context.findRenderObject();
105+
// renderObject.sendSemanticsEvent(const TapSemanticEvent());
106+
// }
107+
108+
// void onStatusChange() {
109+
// setState(() {
110+
// isSelected = !isSelected;
111+
// });
112+
// if (widget.onChanged != null) {
113+
// widget.onChanged(isSelected);
114+
// }
115+
// }
116116

117117

118118
@override
119119
Widget build(BuildContext context) => FocusableActionDetector(
120-
actions: _actionMap,
120+
// actions: _actionMap,
121121
focusNode: widget.focusNode,
122122
autofocus: widget.autofocus,
123123
enabled: enabled,
124124
child: InkWell(
125125
// onTap: onStatusChange,
126126
canRequestFocus: enabled,
127127
onTap: widget.onChanged != null ?
128-
() {
129-
setState(() {
130-
isSelected = !isSelected;
131-
});
132-
widget.onChanged(!widget.value);
133-
} : null,
128+
() {widget.onChanged(!widget.value);} : null,
134129
child: Container(
135130
height: widget.size,
136131
width: widget.size,
137132
decoration: BoxDecoration(
138133
color: enabled
139-
? isSelected
134+
? widget.value
140135
? widget.type == GFCheckboxType.custom
141136
? Colors.white
142137
: widget.activebgColor
@@ -148,12 +143,12 @@ class _GFCheckboxState extends State<GFCheckbox> {
148143
? BorderRadius.circular(50)
149144
: BorderRadius.zero,
150145
border: Border.all(
151-
color: isSelected
146+
color: widget.value
152147
? widget.type == GFCheckboxType.custom
153148
? Colors.black87
154149
: widget.activeBorderColor
155150
: widget.inactiveBorderColor)),
156-
child: isSelected
151+
child: widget.value
157152
? widget.type == GFCheckboxType.custom
158153
? Stack(
159154
children: <Widget>[

0 commit comments

Comments
 (0)