Skip to content

Commit d4ebd32

Browse files
committed
GFCheckbox , GFCheckboxListTile, GFListTile changes done
1 parent 98deed0 commit d4ebd32

File tree

1 file changed

+75
-65
lines changed

1 file changed

+75
-65
lines changed

lib/components/radio/gf_radio.dart

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ class GFRadioButton<T> extends StatefulWidget {
2626
this.custombgColor = GFColors.SUCCESS,
2727
this.groupValue,
2828
this.autofocus = false,
29-
this.focusNode
29+
this.focusNode,
30+
this.toggleable = false
3031
}) : assert(autofocus != null),
32+
assert(toggleable != null),
3133
super(key: key);
3234

3335
/// type of [GFRadioButtonType] which is of four type is basic, sqaure, circular and custom
@@ -87,79 +89,87 @@ class GFRadioButton<T> extends StatefulWidget {
8789
/// [groupValue].
8890
final T groupValue;
8991

92+
final bool toggleable;
93+
9094
@override
91-
_GFRadioButtonState createState() => _GFRadioButtonState();
95+
_GFRadioButtonState<T> createState() => _GFRadioButtonState<T>();
9296
}
9397

94-
class _GFRadioButtonState extends State<GFRadioButton> {
98+
class _GFRadioButtonState<T> extends State<GFRadioButton<T>> with TickerProviderStateMixin {
9599
bool get enabled => widget.onChanged != null;
100+
bool isSelected = false;
96101

97102
@override
98103
void initState() {
99104
super.initState();
105+
isSelected = widget.value == widget.groupValue ?? false;
106+
}
107+
108+
void onStatusChange() {
109+
setState(() {
110+
isSelected = !isSelected;
111+
});
112+
if (widget.onChanged != null) {
113+
widget.onChanged(isSelected);
114+
}
100115
}
101116

102117
@override
103-
Widget build(BuildContext context) => FocusableActionDetector(
104-
focusNode: widget.focusNode,
105-
autofocus: widget.autofocus,
106-
enabled: enabled,
107-
child: InkWell(
108-
canRequestFocus: enabled,
109-
onTap: widget.onChanged != null ? () {widget.onChanged(!widget.value);} : null,
110-
child: Container(
111-
height: widget.size,
112-
width: widget.size,
113-
decoration: BoxDecoration(
114-
color: enabled ? widget.activebgColor : widget.inactivebgColor,
115-
borderRadius: widget.type == GFRadioButtonType.basic
116-
? BorderRadius.circular(50)
117-
: widget.type == GFRadioButtonType.square
118-
? BorderRadius.circular(0)
119-
: BorderRadius.circular(10),
120-
border: Border.all(
121-
color: enabled
122-
? widget.activeBorderColor
123-
: widget.inactiveBorderColor)),
124-
child: enabled
125-
? widget.type == GFRadioButtonType.basic ||
126-
widget.type == GFRadioButtonType.square
127-
? Stack(
128-
children: <Widget>[
129-
Container(
130-
alignment: Alignment.center,
131-
),
132-
Container(
133-
margin: const EdgeInsets.all(5),
134-
alignment: Alignment.center,
135-
width: widget.size * 0.7,
136-
height: widget.size * 0.7,
137-
decoration: BoxDecoration(
138-
shape: BoxShape.circle, color: widget.radioColor),
139-
)
140-
],
141-
)
142-
: widget.type == GFRadioButtonType.blunt
143-
? Stack(
144-
children: <Widget>[
145-
Container(
146-
alignment: Alignment.center,
147-
),
148-
Container(
149-
margin: const EdgeInsets.all(5),
150-
alignment: Alignment.center,
151-
width: widget.size * 0.8,
152-
height: widget.size * 0.8,
153-
decoration: BoxDecoration(
154-
borderRadius: const BorderRadius.all(
155-
Radius.circular(50)),
156-
color: widget.custombgColor),
157-
)
158-
],
159-
)
160-
: widget.type == GFRadioButtonType.custom
161-
? widget.activeIcon
162-
: widget.inactiveIcon
163-
: widget.inactiveIcon)),
164-
);
118+
Widget build(BuildContext context) => InkWell(
119+
enableFeedback: enabled,
120+
onTap: onStatusChange,
121+
child: Container(
122+
height: widget.size,
123+
width: widget.size,
124+
decoration: BoxDecoration(
125+
color: isSelected ? widget.activebgColor : widget.inactivebgColor,
126+
borderRadius: widget.type == GFRadioButtonType.basic
127+
? BorderRadius.circular(50)
128+
: widget.type == GFRadioButtonType.square
129+
? BorderRadius.circular(0)
130+
: BorderRadius.circular(10),
131+
border: Border.all(
132+
color: isSelected
133+
? widget.activeBorderColor
134+
: widget.inactiveBorderColor)),
135+
child: isSelected
136+
? widget.type == GFRadioButtonType.basic ||
137+
widget.type == GFRadioButtonType.square
138+
? Stack(
139+
children: <Widget>[
140+
Container(
141+
alignment: Alignment.center,
142+
),
143+
Container(
144+
margin: const EdgeInsets.all(5),
145+
alignment: Alignment.center,
146+
width: widget.size * 0.7,
147+
height: widget.size * 0.7,
148+
decoration: BoxDecoration(
149+
shape: BoxShape.circle, color: widget.radioColor),
150+
)
151+
],
152+
)
153+
: widget.type == GFRadioButtonType.blunt
154+
? Stack(
155+
children: <Widget>[
156+
Container(
157+
alignment: Alignment.center,
158+
),
159+
Container(
160+
margin: const EdgeInsets.all(5),
161+
alignment: Alignment.center,
162+
width: widget.size * 0.8,
163+
height: widget.size * 0.8,
164+
decoration: BoxDecoration(
165+
borderRadius: const BorderRadius.all(
166+
Radius.circular(50)),
167+
color: widget.custombgColor),
168+
)
169+
],
170+
)
171+
: widget.type == GFRadioButtonType.custom
172+
? widget.activeIcon
173+
: widget.inactiveIcon
174+
: widget.inactiveIcon));
165175
}

0 commit comments

Comments
 (0)