|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:getflutter/getflutter.dart'; |
| 3 | + |
| 4 | + |
| 5 | +class GFCheckboxListTile extends StatefulWidget { |
| 6 | + |
| 7 | + const GFCheckboxListTile({ |
| 8 | + Key key, |
| 9 | + this.titleText, |
| 10 | + this.subtitleText, |
| 11 | + this.color, |
| 12 | + this.avatar, |
| 13 | + this.title, |
| 14 | + this.subTitle, |
| 15 | + this.description, |
| 16 | + this.padding = const EdgeInsets.all(8), |
| 17 | + this.margin = const EdgeInsets.all(16), |
| 18 | + this.size = GFSize.MEDIUM, |
| 19 | + this.type = GFCheckboxType.basic, |
| 20 | + this.checkColor = GFColors.WHITE, |
| 21 | + this.activebgColor = GFColors.PRIMARY, |
| 22 | + this.inactivebgColor = GFColors.WHITE, |
| 23 | + this.activeBorderColor = GFColors.WHITE, |
| 24 | + this.inactiveBorderColor = GFColors.DARK, |
| 25 | + this.onChanged, |
| 26 | + this.value, |
| 27 | + this.activeIcon = const Icon( |
| 28 | + Icons.check, |
| 29 | + size: 20, |
| 30 | + color: GFColors.WHITE, |
| 31 | + ), |
| 32 | + this.inactiveIcon = const Icon(Icons.close), |
| 33 | + this.custombgColor = GFColors.SUCCESS, |
| 34 | + }) : super(key: key); |
| 35 | + |
| 36 | + ///type of [String] used to pass text, alternative to title property and gets higher priority than title |
| 37 | + final String titleText; |
| 38 | + |
| 39 | + ///type of [String] used to pass text, alternative to subtitle property and gets higher priority than subtitle |
| 40 | + final String subtitleText; |
| 41 | + |
| 42 | + /// The GFListTile's background color. Can be given [Color] or [GFColors] |
| 43 | + final Color color; |
| 44 | + |
| 45 | + /// type of [Widget] or [GFAvatar] used to create rounded user profile |
| 46 | + final Widget avatar; |
| 47 | + |
| 48 | + /// The title to display inside the [GFListTile]. see [Text] |
| 49 | + final Widget title; |
| 50 | + |
| 51 | + /// The subTitle to display inside the [GFListTile]. see [Text] |
| 52 | + final Widget subTitle; |
| 53 | + |
| 54 | + /// The description to display inside the [GFListTile]. see [Text] |
| 55 | + final Widget description; |
| 56 | + |
| 57 | + |
| 58 | + /// defines the margin of GFListTile |
| 59 | + final EdgeInsets margin; |
| 60 | + |
| 61 | + /// defines the padding of GFListTile |
| 62 | + final EdgeInsets padding; |
| 63 | + |
| 64 | + /// type of [GFCheckboxType] which is of four type is basic, sqaure, circular and custom |
| 65 | + final GFCheckboxType type; |
| 66 | + |
| 67 | + /// type of [double] which is GFSize ie, small, medium and large and can use any double value |
| 68 | + final double size; |
| 69 | + |
| 70 | + // type pf [Color] used to change the checkcolor when the checkbox is active |
| 71 | + final Color checkColor; |
| 72 | + |
| 73 | + /// type of [Color] used to change the backgroundColor of the active checkbox |
| 74 | + final Color activebgColor; |
| 75 | + |
| 76 | + /// type of [Color] used to change the backgroundColor of the inactive checkbox |
| 77 | + final Color inactivebgColor; |
| 78 | + |
| 79 | + /// type of [Color] used to change the border color of the active checkbox |
| 80 | + final Color activeBorderColor; |
| 81 | + |
| 82 | + /// type of [Color] used to change the border color of the inactive checkbox |
| 83 | + final Color inactiveBorderColor; |
| 84 | + |
| 85 | + /// Called when the user checks or unchecks the checkbox. |
| 86 | + final ValueChanged<bool> onChanged; |
| 87 | + |
| 88 | + ///Used to set the current state of the checkbox |
| 89 | + final bool value; |
| 90 | + |
| 91 | + ///type of Widget used to change the checkbox's active icon |
| 92 | + final Widget activeIcon; |
| 93 | + |
| 94 | + ///type of [Widget] used to change the checkbox's inactive icon |
| 95 | + final Widget inactiveIcon; |
| 96 | + |
| 97 | + /// type of [Color] used to change the background color of the custom active checkbox only |
| 98 | + final Color custombgColor; |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + @override |
| 103 | + _GFCheckboxListTileState createState() => _GFCheckboxListTileState(); |
| 104 | +} |
| 105 | + |
| 106 | +class _GFCheckboxListTileState extends State<GFCheckboxListTile> { |
| 107 | + |
| 108 | + |
| 109 | + bool isSelected = false; |
| 110 | + @override |
| 111 | + void initState(){ |
| 112 | + isSelected = widget.value??false; |
| 113 | + } |
| 114 | + |
| 115 | + void onStatusChange() { |
| 116 | + setState(() { |
| 117 | + isSelected = !isSelected; |
| 118 | + }); |
| 119 | + if (widget.onChanged != null) { |
| 120 | + widget.onChanged(isSelected); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | +// void onStatusChange() { |
| 126 | +// if (widget.onChanged != null) { |
| 127 | +// setState(() { |
| 128 | +// isSelected = !isSelected; |
| 129 | +// }); |
| 130 | +// switch (widget.value) { |
| 131 | +// case false: |
| 132 | +// widget.onChanged(true); |
| 133 | +// break; |
| 134 | +// case true: |
| 135 | +//// widget.onChanged(widget.tristate ? null : true); |
| 136 | +//// break; |
| 137 | +// default: // case null: |
| 138 | +// widget.onChanged(isSelected); |
| 139 | +// break; |
| 140 | +// } |
| 141 | +// } |
| 142 | +//// } |
| 143 | + @override |
| 144 | + Widget build(BuildContext context) => |
| 145 | + InkWell( |
| 146 | +// onTap: widget.onChanged != null ? () { widget.onChanged(isSelected); } : null, |
| 147 | + onTap: onStatusChange, |
| 148 | + |
| 149 | +// onTap: (){ |
| 150 | +// setState((){ |
| 151 | +// isSelected = !isSelected; |
| 152 | +// }); |
| 153 | +// }, |
| 154 | + child: GestureDetector( |
| 155 | + |
| 156 | + child: GFListTile( |
| 157 | + avatar: widget.avatar, |
| 158 | + titleText: widget.titleText, |
| 159 | + subTitle: widget.subTitle, |
| 160 | + subtitleText: widget.subtitleText, |
| 161 | + description: widget.description, |
| 162 | + color: widget.color, |
| 163 | + padding: widget.padding, |
| 164 | + margin: widget.margin, |
| 165 | + title: widget.title, |
| 166 | + |
| 167 | + icon: GFCheckbox( |
| 168 | + size: widget.size, |
| 169 | + activebgColor: widget.activebgColor, |
| 170 | +// onChanged:widget.onChanged, |
| 171 | +// value: widget.value, |
| 172 | + inactiveIcon: widget.inactiveIcon, |
| 173 | + activeBorderColor: widget.activeBorderColor, |
| 174 | + inactivebgColor: widget.inactivebgColor, |
| 175 | + activeIcon: widget.activeIcon, |
| 176 | + inactiveBorderColor: widget.inactiveBorderColor, |
| 177 | + custombgColor: widget.custombgColor, |
| 178 | + checkColor: widget.checkColor, |
| 179 | + type: widget.type, |
| 180 | + ), |
| 181 | + ), |
| 182 | + ) |
| 183 | + ); |
| 184 | +// InkWell( |
| 185 | +// onTap: onStatusChange, |
| 186 | +// child: Container( |
| 187 | +// constraints: const BoxConstraints(minHeight: 50), |
| 188 | +// padding: widget.padding, |
| 189 | +// margin: widget.margin, |
| 190 | +// decoration: BoxDecoration( |
| 191 | +// color: widget.color, |
| 192 | +// borderRadius: const BorderRadius.all(Radius.circular(5)), |
| 193 | +// ), |
| 194 | +// child: Row( |
| 195 | +// mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 196 | +// children: <Widget>[ |
| 197 | +// widget.avatar ?? Container(), |
| 198 | +// Expanded( |
| 199 | +// child: Padding( |
| 200 | +// padding: const EdgeInsets.symmetric(horizontal: 10), |
| 201 | +// child: Column( |
| 202 | +// crossAxisAlignment: CrossAxisAlignment.start, |
| 203 | +// children: <Widget>[ |
| 204 | +// widget.titleText != null |
| 205 | +// ? Text( |
| 206 | +// widget.titleText, |
| 207 | +// style: const TextStyle( |
| 208 | +// fontSize: 17, |
| 209 | +// fontWeight: FontWeight.w500, |
| 210 | +// color: GFColors.DARK), |
| 211 | +// ) |
| 212 | +// : widget.title ?? Container(), |
| 213 | +// widget.subtitleText != null |
| 214 | +// ? Text( |
| 215 | +// widget.subtitleText, |
| 216 | +// style: TextStyle( |
| 217 | +// fontSize: 14.5, |
| 218 | +// color: Colors.black54, |
| 219 | +// ), |
| 220 | +// ) |
| 221 | +// : widget.subTitle ?? Container(), |
| 222 | +// widget.description ?? Container() |
| 223 | +// ], |
| 224 | +// ), |
| 225 | +// ), |
| 226 | +// ), |
| 227 | +//// widget.icon ?? Container(), |
| 228 | +// |
| 229 | +// GFCheckbox( |
| 230 | +// size: widget.size, |
| 231 | +// activebgColor: widget.activebgColor, |
| 232 | +// onChanged: widget.onChanged, |
| 233 | +// value: widget.value, |
| 234 | +// inactiveIcon: widget.inactiveIcon, |
| 235 | +// activeBorderColor: widget.activeBorderColor, |
| 236 | +// inactivebgColor: widget.inactivebgColor, |
| 237 | +// activeIcon: widget.activeIcon, |
| 238 | +// inactiveBorderColor: widget.inactiveBorderColor, |
| 239 | +// custombgColor: widget.custombgColor, |
| 240 | +// checkColor: widget.checkColor, |
| 241 | +// type: widget.type, |
| 242 | +// ), |
| 243 | +// ], |
| 244 | +// ), |
| 245 | +// ), |
| 246 | +// ); |
| 247 | +} |
| 248 | + |
0 commit comments