updating checkbox to handle long press and using UniqueKey() to avoid weird side effects

pull/186/head
Kevin Despoulains 4 years ago
parent b853ae3129
commit 535e973799
  1. 17
      lib/widgets/text_block.dart

@ -163,6 +163,7 @@ class EditableTextBlock extends StatelessWidget {
if (attrs[Attribute.list.key] == Attribute.checked) { if (attrs[Attribute.list.key] == Attribute.checked) {
return _Checkbox( return _Checkbox(
key: UniqueKey(),
style: defaultStyles!.leading!.style, style: defaultStyles!.leading!.style,
width: 32, width: 32,
isChecked: true, isChecked: true,
@ -173,9 +174,9 @@ class EditableTextBlock extends StatelessWidget {
if (attrs[Attribute.list.key] == Attribute.unchecked) { if (attrs[Attribute.list.key] == Attribute.unchecked) {
return _Checkbox( return _Checkbox(
key: UniqueKey(),
style: defaultStyles!.leading!.style, style: defaultStyles!.leading!.style,
width: 32, width: 32,
isChecked: false,
offset: block.offset + line.offset, offset: block.offset + line.offset,
onTap: onCheckboxTap, onTap: onCheckboxTap,
); );
@ -704,14 +705,13 @@ class _Checkbox extends StatelessWidget {
Key? key, Key? key,
this.style, this.style,
this.width, this.width,
this.isChecked, this.isChecked = false,
this.offset, this.offset,
this.onTap, this.onTap,
}) : super(key: key); }) : super(key: key);
final TextStyle? style; final TextStyle? style;
final double? width; final double? width;
final bool? isChecked; final bool isChecked;
final int? offset; final int? offset;
final Function(int, bool)? onTap; final Function(int, bool)? onTap;
@ -727,9 +727,12 @@ class _Checkbox extends StatelessWidget {
alignment: AlignmentDirectional.topEnd, alignment: AlignmentDirectional.topEnd,
width: width, width: width,
padding: const EdgeInsetsDirectional.only(end: 13), padding: const EdgeInsetsDirectional.only(end: 13),
child: Checkbox( child: GestureDetector(
value: isChecked, onLongPress: () => _onCheckboxClicked(!isChecked),
onChanged: _onCheckboxClicked, child: Checkbox(
value: isChecked,
onChanged: _onCheckboxClicked,
),
), ),
); );
} }

Loading…
Cancel
Save