Skip to content

Commit 6df2b82

Browse files
committed
refactor(cell): add the checked property and fix some bugs
1 parent 342855a commit 6df2b82

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

lib/cells.dart

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/services.dart';
33
import 'action_sheet.dart';
4+
import 'weui_icon.dart';
45

56
class Cells extends StatelessWidget {
67
Cells({@required this.children, Key key}) : super(key: key);
@@ -164,14 +165,18 @@ class CellInput extends StatelessWidget {
164165
}
165166

166167
class Cell extends StatefulWidget {
167-
Cell({this.title = "", Key key, this.secondaryText = "", this.banner, this.access = false, this.onPressed, this.radio, this.checkBox}) : super(key: key);
168+
Cell({this.title = "", Key key, this.secondaryText = "", this.banner, this.access = false, this.onPressed, this.radio, this.checkBox, this.checked = false})
169+
: super(key: key);
168170
final String title;
169171
final String secondaryText;
170172
final Widget banner;
171173
final bool access;
172174
final VoidCallback onPressed;
173175
final bool radio;
174176
final bool checkBox;
177+
final bool checked;
178+
179+
///只在checkBox == true || radio == true时有效
175180
@override
176181
State<StatefulWidget> createState() => _Cell();
177182
}
@@ -194,22 +199,39 @@ class _Cell extends State<Cell> {
194199
if (widget.onPressed != null) widget.onPressed();
195200
}
196201

202+
_onTapCancel() {
203+
setState(() {
204+
bg = Color(0xFFFFFFFF);
205+
});
206+
}
207+
197208
@override
198209
Widget build(BuildContext context) {
199210
return GestureDetector(
200211
onTapDown: this._onTapDown,
201212
onTapUp: this._onTapUp,
213+
onTapCancel: this._onTapCancel,
202214
child: Container(
203215
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
204216
color: bg,
205217
child: Row(
206218
crossAxisAlignment: CrossAxisAlignment.center,
207219
children: <Widget>[
208220
Offstage(
209-
child: Icon(
210-
Icons.check_circle,
211-
color: Color(0xFF1AAD19),
212-
size: 20,
221+
child: Container(
222+
margin: const EdgeInsets.only(right: 5),
223+
child: WeuiIcon(
224+
type: WeuiIconType.success,
225+
color: widget.checked == true ? Color(0xFF1AAD19) : Color(0xFFFFFFFF),
226+
size: 20,
227+
),
228+
decoration: BoxDecoration(
229+
borderRadius: BorderRadius.all(Radius.circular(10)),
230+
border: Border.all(
231+
width: 1,
232+
color: Color(0xCCCCCCCC),
233+
),
234+
),
213235
),
214236
offstage: widget.checkBox != true,
215237
),
@@ -242,7 +264,7 @@ class _Cell extends State<Cell> {
242264
Offstage(
243265
child: Icon(
244266
Icons.check,
245-
color: Color(0xFF1AAD19),
267+
color: widget.checked == true ? Color(0xFF1AAD19) : Color(0xFFFFFFFF),
246268
size: 20,
247269
),
248270
offstage: widget.radio != true,

0 commit comments

Comments
 (0)