Skip to content

Commit 3e7396d

Browse files
committed
GFCheckbox working fine in all state
1 parent b953851 commit 3e7396d

File tree

3 files changed

+28
-97
lines changed

3 files changed

+28
-97
lines changed

example/lib/main_temp.dart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class _MyHomePageState extends State<MyHomePage>
162162
GFCheckboxListTile(
163163
color: GFColors.LIGHT,
164164
title: const Text('is checked'),
165-
size: GFSize.SMALL,
165+
size: GFSize.LARGE,
166166
activebgColor: GFColors.DANGER,
167167
onChanged: (val) {
168168
setState(() {
@@ -177,9 +177,11 @@ class _MyHomePageState extends State<MyHomePage>
177177
GFListTile(
178178
title: Text('title'),
179179
subTitle: Text('subtitle'),
180-
color: GFColors.LIGHT,
180+
color: check ? GFColors.LIGHT : GFColors.DARK,
181181
onTap: (){
182-
print('fghj');
182+
setState(() {
183+
check = !check;
184+
});
183185
},
184186
),
185187

@@ -199,15 +201,21 @@ class _MyHomePageState extends State<MyHomePage>
199201

200202
GFCheckbox(
201203
size: GFSize.SMALL,
202-
onChanged: (val) {
203-
print('on change val $val');
204+
onChanged: (val) {
205+
setState(() {
206+
check = val;
207+
});
204208
},
205-
value: true,
209+
value: check,
206210
type: GFCheckboxType.circle,
207211
checkColor: GFColors.DANGER,
208-
// activebgColor: Colors.green,
209-
// inactivebgColor: Colors.white,
210-
// activeBorderColor: Colors.red,
212+
activebgColor: Colors.green,
213+
inactivebgColor: Colors.white54,
214+
activeBorderColor: Colors.red,
215+
inactiveBorderColor: Colors.black12,
216+
inactiveIcon: Icon(Icons.check_box_outline_blank),
217+
activeIcon: Icon(Icons.check_box),
218+
autofocus: true,
211219
),
212220

213221
GFRadioButton(
@@ -232,7 +240,14 @@ class _MyHomePageState extends State<MyHomePage>
232240
// groupValue:
233241
),
234242

235-
243+
Checkbox(
244+
value: check,
245+
onChanged: (bool value) {
246+
setState(() {
247+
check = value;
248+
});
249+
},
250+
),
236251

237252
const Padding(
238253
padding: EdgeInsets.only(left: 15, top: 30),

lib/components/checkbox/gf_checkbox.dart

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:getwidget/getwidget.dart';
33

4-
import 'package:flutter/foundation.dart';
5-
import 'package:flutter/rendering.dart';
6-
import 'package:flutter/widgets.dart';
7-
8-
94
class GFCheckbox extends StatefulWidget {
105
const GFCheckbox({
116
Key key,
@@ -36,7 +31,7 @@ class GFCheckbox extends StatefulWidget {
3631
/// type of [double] which is GFSize ie, small, medium and large and can use any double value
3732
final double size;
3833

39-
// 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
4035
final Color checkColor;
4136

4237
/// type of [Color] used to change the backgroundColor of the active checkbox
@@ -78,54 +73,20 @@ class GFCheckbox extends StatefulWidget {
7873

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

8477
@override
8578
void initState() {
8679
super.initState();
87-
// isSelected = widget.value;
88-
// _actionMap = <Type, Action<Intent>>{
89-
// ActivateIntent: CallbackAction<ActivateIntent>(onInvoke: _actionHandler),
90-
// };
9180
}
9281

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-
// }
116-
117-
11882
@override
11983
Widget build(BuildContext context) => FocusableActionDetector(
120-
// actions: _actionMap,
12184
focusNode: widget.focusNode,
12285
autofocus: widget.autofocus,
12386
enabled: enabled,
12487
child: InkWell(
125-
// onTap: onStatusChange,
12688
canRequestFocus: enabled,
127-
onTap: widget.onChanged != null ?
128-
() {widget.onChanged(!widget.value);} : null,
89+
onTap: widget.onChanged != null ? () {widget.onChanged(!widget.value);} : null,
12990
child: Container(
13091
height: widget.size,
13192
width: widget.size,

lib/components/checkbox_list_tile/gf_checkbox_list_tile.dart

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class GFCheckboxListTile extends StatelessWidget {
6969
/// type of [double] which is GFSize ie, small, medium and large and can use any double value
7070
final double size;
7171

72-
// type pf [Color] used to change the checkcolor when the checkbox is active
72+
/// type pf [Color] used to change the checkcolor when the checkbox is active
7373
final Color checkColor;
7474

7575
/// type of [Color] used to change the backgroundColor of the active checkbox
@@ -145,48 +145,3 @@ class GFCheckboxListTile extends StatelessWidget {
145145
),
146146
);
147147
}
148-
149-
150-
//class GFCheckboxListTile extends StatefulWidget {
151-
//
152-
//
153-
// @override
154-
// _GFCheckboxListTileState createState() => _GFCheckboxListTileState();
155-
//}
156-
//
157-
//class _GFCheckboxListTileState extends State<GFCheckboxListTile> {
158-
//
159-
//
160-
//
161-
// @override
162-
// Widget build(BuildContext context) => GFListTile(
163-
// autofocus: widget.autofocus,
164-
// enabled: widget.onChanged != null,
165-
// onTap: widget.onChanged != null ? () { widget.onChanged(!widget.value); } : null,
166-
// selected: widget.selected,
167-
// avatar: widget.avatar,
168-
// titleText: widget.titleText,
169-
// subTitle: widget.subTitle,
170-
// subtitleText: widget.subtitleText,
171-
// description: widget.description,
172-
// color: widget.color,
173-
// padding: widget.padding,
174-
// margin: widget.margin,
175-
// title: widget.title,
176-
// icon: GFCheckbox(
177-
// autofocus: widget.autofocus,
178-
// onChanged:widget.onChanged,
179-
// value: widget.value,
180-
// size: widget.size,
181-
// activebgColor: widget.activebgColor,
182-
// inactiveIcon: widget.inactiveIcon,
183-
// activeBorderColor: widget.activeBorderColor,
184-
// inactivebgColor: widget.inactivebgColor,
185-
// activeIcon: widget.activeIcon,
186-
// inactiveBorderColor: widget.inactiveBorderColor,
187-
// custombgColor: widget.custombgColor,
188-
// checkColor: widget.checkColor,
189-
// type: widget.type,
190-
// ),
191-
// );
192-
//}

0 commit comments

Comments
 (0)