ModalCalc function
void
ModalCalc()
Implementation
void ModalCalc(context, String label, String currentValue, Function callback, bool currency){
String inputValue = currentValue == '0' || currentValue == '0.0' || currentValue == '.0' ? '' : currentValue;
List valuesRow1 = ['1', '2', '3' ];
List valuesRow2 = ['4', '5', '6' ];
List valuesRow3 = ['7', '8', '9' ];
List valuesRow4 = ['.', '0', 'back' ];
List values = [ valuesRow1, valuesRow2, valuesRow3, valuesRow4 ];
void delete(Function setStateModal){
if (inputValue.isNotEmpty) {
setStateModal(()=> inputValue = inputValue.substring(0, inputValue.length - 1) );
}
}
void confirm(){
Navigator.pop(context);
callback(inputValue);
}
Widget child = StatefulBuilder(
builder: (BuildContext context, StateSetter setStateModal ) {
ColorScheme colorScheme = Theme.of(context).colorScheme;
final customColors = CustomColors();
final customIcons = CustomIcons();
return Container(
color: colorScheme.background,
margin: const EdgeInsets.fromLTRB(8, 8, 8, 24),
height: MediaQuery.of(context).size.height - (isPortrait(context) ? 0 : 264), //360.0
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
CustomAppBarModal(
buttonType: ButtonType.icon,
title: label,
centerTitle: true,
options: {
'cancel': ()=>Navigator.of(context).pop(),
'confirm': ()=>confirm()
}
),
const SizedBox(height: 48),
Text('${currency ? '\$ ' : ''}$inputValue', style: TextStyle(fontSize: 32) ),
const SizedBox(height: 24),
Column(
children: List.generate(values.length, (index) {
List rowValues = values[index];
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(rowValues.length, (index) {
String value = rowValues[index];
return CustomElevatedButton(
flex: 1,
borderRadius: BorderRadius.circular(0),
margin: const EdgeInsets.all(1),
backgroundColor: colorScheme.background,
padding: const EdgeInsets.fromLTRB(16, 16, 16, 16),
child: value == 'back'
? Icon(customIcons.backspace, color: customColors.error)
: Text( value, style: TextStyle(fontSize: 24), textAlign: TextAlign.center, ),
onPressed: ()=>
value == 'back' ? delete(setStateModal)
: setStateModal(() => inputValue += value )
);
}),
);
})
)
],
),
);
}
);
customAutoDialog(context, child);
}