2019-07-09 11:52:25 +01:00
import ' package:flutter/material.dart ' ;
import ' package:local_spend/common/widgets/custom_checkbox.dart ' ;
class LabeledCheckboxWithIcon extends StatelessWidget {
const LabeledCheckboxWithIcon ( {
this . label ,
this . textStyle ,
this . icon ,
2019-07-09 12:44:05 +01:00
this . iconSize ,
2019-07-09 11:52:25 +01:00
this . iconColor ,
this . padding ,
this . value ,
this . onChanged ,
} ) ;
final String label ;
final TextStyle textStyle ;
final IconData icon ;
2019-07-09 12:44:05 +01:00
final double iconSize ;
2019-07-09 11:52:25 +01:00
final Color iconColor ;
final EdgeInsets padding ;
final bool value ;
final Function onChanged ;
@ override
Widget build ( BuildContext context ) {
return InkWell (
onTap: ( ) {
onChanged ( ! value ) ;
} ,
child: Padding (
padding: padding ,
child: Row (
2019-07-09 12:44:05 +01:00
// crossAxisAlignment: CrossAxisAlignment.center, //doesn't do anything
2019-07-09 11:52:25 +01:00
children: < Widget > [
2019-07-09 12:44:05 +01:00
Container (
padding: EdgeInsets . all ( 0 ) ,
width: iconSize ,
2019-08-21 14:53:52 +01:00
child: Icon (
2019-07-09 11:52:25 +01:00
icon ,
2019-08-21 14:53:52 +01:00
// size: iconSize,
2019-07-09 11:52:25 +01:00
color: iconColor ,
) ,
) ,
2019-08-21 14:53:52 +01:00
Expanded (
child: Text (
label ,
style: textStyle ,
textAlign: TextAlign . center ,
) ) ,
2019-07-09 11:52:25 +01:00
CustomCheckbox (
//custom checkbox removes padding so the form looks nice
value: value ,
useTapTarget: false ,
onChanged: ( bool newValue ) {
onChanged ( newValue ) ;
} ,
) ,
] ,
) ,
) ,
) ;
}
}
class LabeledCheckbox extends StatelessWidget {
const LabeledCheckbox ( {
this . label ,
this . textStyle ,
this . padding ,
this . value ,
this . onChanged ,
} ) ;
final String label ;
final TextStyle textStyle ;
final EdgeInsets padding ;
final bool value ;
final Function onChanged ;
@ override
Widget build ( BuildContext context ) {
return InkWell (
onTap: ( ) {
onChanged ( ! value ) ;
} ,
child: Padding (
padding: padding ,
child: Row (
children: < Widget > [
Expanded ( child: Text ( label , style: textStyle ) ) ,
2019-07-09 12:44:05 +01:00
CustomCheckbox (
//custom checkbox removes padding so the form looks nice
2019-07-09 11:52:25 +01:00
value: value ,
2019-07-09 12:44:05 +01:00
useTapTarget: false ,
2019-07-09 11:52:25 +01:00
onChanged: ( bool newValue ) {
onChanged ( newValue ) ;
} ,
) ,
] ,
) ,
) ,
) ;
}
}
/ *
//USAGE:
bool _isSelected = false ;
@ override
Widget build ( BuildContext context ) {
return Scaffold (
body: Center (
child: LabeledCheckbox (
label: ' Label Text Here ' ,
padding: const EdgeInsets . fromLTRB ( 0 , 0 , 0 , 0 ) ,
value: _isSelected ,
onChanged: ( bool newValue ) {
setState ( ( ) {
_isSelected = newValue ;
} ) ;
} ,
) ,
) ,
) ;
}
2019-08-21 14:53:52 +01:00
* /