Skip to content

Commit b7c12c2

Browse files
committed
update bindings
1 parent d0f7502 commit b7c12c2

File tree

9 files changed

+62
-24
lines changed

9 files changed

+62
-24
lines changed

example/lib/main.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,26 @@ class _MyHomePageState extends State<MyHomePage> {
8282
separatorBuilder: (c, i) =>
8383
Separator(margin: EdgeInsets.only(left: 12)),
8484
itemBuilder: (c, i) {
85-
return TextCell(title: _items[i].coalesce("-").capitalize());
85+
switch (i) {
86+
case 0:
87+
return CheckboxCell(
88+
title: _items[i].coalesce("-").capitalize(),
89+
onChecked: (checked) {});
90+
case 1:
91+
return DateTimePickerCell(
92+
_items[i].coalesce("-").capitalize(), (dateTime) {});
93+
case 2:
94+
return PickerViewCell(
95+
title: _items[i].coalesce("-").capitalize(),
96+
items: "A B C D E F".split(' '));
97+
case 3:
98+
return SelectableViewCell(
99+
child: Text(_items[i].coalesce("-").capitalize()),
100+
selected: false);
101+
default:
102+
return TextCell(
103+
title: _items[i].coalesce("-").capitalize());
104+
}
86105
},
87106
),
88107
),

lib/widgets/checkbox_cell.dart

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ class CheckboxCell extends StatefulWidget {
1616
CheckboxCell({
1717
GlobalKey? key,
1818
this.checked = false,
19-
this.title,
19+
required this.title,
2020
this.onTap,
2121
this.detail,
2222
this.titleColor,
2323
this.detailColor,
2424
required this.onChecked,
25-
this.onStart,
25+
this.isAsync = false,
2626
}) : super(key: key);
2727

28+
final bool isAsync;
2829
bool checked;
29-
String? title;
30+
final String title;
3031
String? detail;
3132
Color? titleColor;
3233
Color? detailColor;
3334

3435
final ValueChanged<bool> onChecked;
3536
ValueChanged<ValueChanged<String>>? onTap;
36-
String? Function()? onStart;
3737

3838
@override
3939
State<StatefulWidget> createState() => CheckboxCellState();
@@ -47,25 +47,22 @@ class CheckboxCellState extends State<CheckboxCell> {
4747
_checkboxState.currentState!.setChecked(isChecked);
4848
}
4949

50-
String _detail = "";
51-
5250
void setDetail(String text) {
5351
setState(() {
54-
_detail = text;
52+
widget.detail = text;
5553
});
5654
}
5755

5856
@override
5957
void initState() {
6058
super.initState();
61-
_detail = widget.detail ?? "";
62-
if (widget.onStart != null) _detail = widget.onStart!() ?? "";
6359
}
6460

6561
@override
6662
Widget build(BuildContext context) {
6763
return ViewCell(
6864
showIcon: widget.onTap != null,
65+
isAsync: widget.isAsync,
6966
child: Container(
7067
child: Row(
7168
crossAxisAlignment: CrossAxisAlignment.center,
@@ -80,7 +77,7 @@ class CheckboxCellState extends State<CheckboxCell> {
8077
width: 10,
8178
),
8279
Text(
83-
widget.title == null ? "" : widget.title!,
80+
widget.title,
8481
style: TextStyle(color: widget.titleColor ?? Colors.black),
8582
),
8683
],
@@ -92,13 +89,13 @@ class CheckboxCellState extends State<CheckboxCell> {
9289
widget.onTap!((text) {
9390
if (!_checkboxState.currentState!.checked || widget.onTap == null)
9491
return;
95-
setState(() => _detail = text);
92+
setState(() => widget.detail = text);
9693
});
9794
}
9895
},
9996
detail: Flexible(
10097
child: Text(
101-
_detail,
98+
widget.detail ?? "",
10299
textAlign: TextAlign.right,
103100
style: TextStyle(
104101
color: widget.detailColor ?? CupertinoColors.systemGrey),

lib/widgets/datetime_cell.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ class DateTimeCell extends DateTimePickerCell {
2020
DateTimeCellMode mode = DateTimeCellMode.Date,
2121
DateTime? initialDateTime,
2222
String? dateTimeFormat,
23+
bool isAsync = false,
2324
}) : super(
2425
title,
2526
onSelected,
2627
dateTimeFormat: dateTimeFormat,
2728
initialDateTime: initialDateTime,
29+
isAsync: isAsync,
2830
mode: mode,
2931
);
3032
}
@@ -44,11 +46,14 @@ class DateTimePickerCell extends StatefulWidget {
4446
DateTimeSelected onSelected, {
4547
this.mode = DateTimeCellMode.Date,
4648
DateTime? initialDateTime,
49+
this.isAsync = false,
4750
this.dateTimeFormat,
4851
}) : this.title = title,
4952
this.onSelected = onSelected,
5053
this.initialDateTime = initialDateTime ?? DateTime.now();
5154

55+
final bool isAsync;
56+
5257
@override
5358
State<StatefulWidget> createState() => _DateTimeCellState();
5459
}
@@ -78,6 +83,7 @@ class _DateTimeCellState extends State<DateTimePickerCell> {
7883
color: Colors.black,
7984
),
8085
),
86+
isAsync: widget.isAsync,
8187
hasUneventRows: true,
8288
padding: EdgeInsets.only(left: 12, top: 8, right: 10, bottom: 8),
8389
enableSelection: false,

lib/widgets/picker_view_cell.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ class PickerViewCell extends StatefulWidget {
2424
this.onSelected,
2525
this.pickerSize,
2626
this.index,
27+
this.isAsync = false,
2728
}) : assert(items.isNotEmpty, "items mus have at least 1 value(s)");
2829

30+
final bool isAsync;
31+
2932
@override
3033
State<StatefulWidget> createState() => _PickerViewCellState();
3134
}
@@ -48,6 +51,7 @@ class _PickerViewCellState extends State<PickerViewCell> {
4851
color: Colors.black,
4952
),
5053
),
54+
isAsync: widget.isAsync,
5155
hasUneventRows: true,
5256
padding: EdgeInsets.only(left: 12, top: 8, right: 10, bottom: 8),
5357
enableSelection: false,

lib/widgets/selectable_view_cell.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SelectableViewCell extends StatelessWidget {
1919
});
2020

2121
final Widget child;
22-
bool selected;
22+
final bool selected;
2323
Color? iconColor;
2424
IconData? selectedIcon;
2525
void Function()? onTap;

lib/widgets/stack_view_cell.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ class StackViewCell extends StatelessWidget {
1919
this.showIcon = false,
2020
this.padding,
2121
this.onTap,
22+
this.isAsync = false,
2223
});
2324

25+
final bool isAsync;
26+
2427
@override
2528
Widget build(BuildContext context) {
2629
return ViewCell(
2730
onTap: onTap ?? () {},
2831
showIcon: showIcon,
2932
hasUneventRows: true,
33+
isAsync: isAsync,
3034
padding: padding ?? EdgeInsets.fromLTRB(12, 5, 5, 5),
3135
detail: showIcon ? Text("") : null,
3236
child: Column(

lib/widgets/switch_cell.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,28 @@ import 'package:housecode/widgets/view_cell.dart';
1010

1111
typedef SwitchValueChanged = void Function(bool isEnable);
1212

13+
// ignore: must_be_immutable
1314
class SwitchCell extends StatefulWidget {
14-
final bool initialValue;
15+
bool isChecked;
1516
final String title;
1617
final SwitchValueChanged onChanged;
1718

18-
SwitchCell(bool value, String title, SwitchValueChanged onChanged)
19-
: this.initialValue = value,
19+
SwitchCell(bool value, String title, SwitchValueChanged onChanged,
20+
{this.isAsync = false})
21+
: this.isChecked = value,
2022
this.onChanged = onChanged,
2123
this.title = title;
2224

25+
final bool isAsync;
26+
2327
@override
2428
State<StatefulWidget> createState() => _SwitchCellState();
2529
}
2630

2731
class _SwitchCellState extends State<SwitchCell> {
28-
late bool _value;
29-
3032
@override
3133
void initState() {
3234
super.initState();
33-
_value = widget.initialValue;
3435
}
3536

3637
@override
@@ -46,14 +47,15 @@ class _SwitchCellState extends State<SwitchCell> {
4647
),
4748
),
4849
),
50+
isAsync: widget.isAsync,
4951
enableSelection: false,
5052
detail: CupertinoSwitch(
51-
value: _value,
53+
value: widget.isChecked,
5254
onChanged: (value) {
5355
setState(() {
54-
_value = value;
56+
widget.isChecked = value;
5557
});
56-
widget.onChanged(_value);
58+
widget.onChanged(widget.isChecked);
5759
},
5860
),
5961
);

lib/widgets/text_cell.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ class TextCell extends StatefulWidget {
2424
this.boldTitle = false,
2525
this.fontSize,
2626
this.expanded = true,
27+
this.isAsync = false,
2728
});
2829

30+
final bool isAsync;
2931
bool boldTitle;
3032
final String title;
3133
String detail;
@@ -66,6 +68,7 @@ class _TextCellState extends State<TextCell> {
6668
),
6769
),
6870
),
71+
isAsync: widget.isAsync,
6972
onTap: widget.onTap == null
7073
? null
7174
: () {

lib/widgets/view_cell.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
import 'package:flutter/cupertino.dart';
88
import 'package:flutter/material.dart';
9+
import 'package:housecode/widgets/circular_indicator.dart';
910

1011
/// view cell for Listview itemBuilder
1112
// ignore: must_be_immutable
1213
class ViewCell extends StatelessWidget {
1314
ViewCell({
1415
required this.child,
16+
this.isAsync = false,
1517
this.hasUneventRows = false,
1618
this.padding,
1719
this.detail,
@@ -32,6 +34,7 @@ class ViewCell extends StatelessWidget {
3234
bool? showIcon;
3335
bool enableSelection;
3436
final bool expanded;
37+
final bool isAsync;
3538

3639
void Function()? onTap;
3740

@@ -66,7 +69,7 @@ class ViewCell extends StatelessWidget {
6669
mainAxisSize: MainAxisSize.max,
6770
crossAxisAlignment: CrossAxisAlignment.center,
6871
children: [
69-
detail ?? Container(),
72+
isAsync ? CircularIndicator() : detail ?? Container(),
7073
Container(
7174
width: onTap != null && (showIcon ?? false) == true
7275
? 5

0 commit comments

Comments
 (0)