Skip to content

Commit 48de9e4

Browse files
authored
Merge pull request #33 from deepikahr/GFCheckboxTile_GFRadioTile
Changes done in GFCheckbox, GFCheckboxTile, and GFListTile
2 parents 24ea19f + 051e500 commit 48de9e4

File tree

8 files changed

+1112
-324
lines changed

8 files changed

+1112
-324
lines changed

example/lib/main_temp.dart

Lines changed: 785 additions & 0 deletions
Large diffs are not rendered by default.

lib/components/checkbox/gf_checkbox.dart

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

44
class 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

6574
class _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>[

lib/components/checkboxListTile/gf_checkbox_list_tile.dart

Lines changed: 0 additions & 236 deletions
This file was deleted.

0 commit comments

Comments
 (0)