@ -61,6 +61,7 @@ class EditableTextBlock extends StatelessWidget {
this . embedBuilder ,
this . cursorCont ,
this . indentLevelCounts ,
this . onCheckboxTap ,
) ;
final Block block ;
@ -76,6 +77,7 @@ class EditableTextBlock extends StatelessWidget {
final EmbedBuilder embedBuilder ;
final CursorCont cursorCont ;
final Map < int , int > indentLevelCounts ;
final Function ( int , bool ) onCheckboxTap ;
@ override
Widget build ( BuildContext context ) {
@ -161,12 +163,23 @@ class EditableTextBlock extends StatelessWidget {
if ( attrs [ Attribute . list . key ] = = Attribute . checked ) {
return _Checkbox (
style: defaultStyles ! . leading ! . style , width: 32 , isChecked: true ) ;
key: UniqueKey ( ) ,
style: defaultStyles ! . leading ! . style ,
width: 32 ,
isChecked: true ,
offset: block . offset + line . offset ,
onTap: onCheckboxTap ,
) ;
}
if ( attrs [ Attribute . list . key ] = = Attribute . unchecked ) {
return _Checkbox (
style: defaultStyles ! . leading ! . style , width: 32 , isChecked: false ) ;
key: UniqueKey ( ) ,
style: defaultStyles ! . leading ! . style ,
width: 32 ,
offset: block . offset + line . offset ,
onTap: onCheckboxTap ,
) ;
}
if ( attrs . containsKey ( Attribute . codeBlock . key ) ) {
@ -685,46 +698,39 @@ class _BulletPoint extends StatelessWidget {
}
}
class _Checkbox extends StatefulWidget {
const _Checkbox ( { Key ? key , this . style , this . width , this . isChecked } )
: super ( key: key ) ;
class _Checkbox extends StatelessWidget {
const _Checkbox ( {
Key ? key ,
this . style ,
this . width ,
this . isChecked = false ,
this . offset ,
this . onTap ,
} ) : super ( key: key ) ;
final TextStyle ? style ;
final double ? width ;
final bool ? isChecked ;
final bool isChecked ;
final int ? offset ;
final Function ( int , bool ) ? onTap ;
@ override
__CheckboxState createState ( ) = > __CheckboxState ( ) ;
}
class __CheckboxState extends State < _Checkbox > {
bool ? isChecked ;
void _onCheckboxClicked ( bool ? newValue ) = > setState ( ( ) {
isChecked = newValue ;
if ( isChecked ! ) {
/ / check list
} else {
/ / uncheck list
}
} ) ;
@ override
void initState ( ) {
super . initState ( ) ;
isChecked = widget . isChecked ;
void _onCheckboxClicked ( bool ? newValue ) {
if ( onTap ! = null & & newValue ! = null & & offset ! = null ) {
onTap ! ( offset ! , newValue ) ;
}
}
@ override
Widget build ( BuildContext context ) {
return Container (
alignment: AlignmentDirectional . topEnd ,
width: widget . wid th ,
width: width ,
padding: const EdgeInsetsDirectional . only ( end: 13 ) ,
child: Checkbox (
value: widget . isChecked ,
onChanged: _onCheckboxClicked ,
child: GestureDetector (
onLongPress: ( ) = > _onCheckboxClicked ( ! isChecked ) ,
child: Checkbox (
value: isChecked ,
onChanged: _onCheckboxClicked ,
) ,
) ,
) ;
}