Skip to content

Commit

Permalink
implement secondary keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
derdilla committed Apr 25, 2024
1 parent 8fb597c commit 58525cc
Showing 1 changed file with 108 additions and 55 deletions.
163 changes: 108 additions & 55 deletions apps/calculator/lib/src/widgets/numpad.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,116 @@ class Numpad extends StatelessWidget {
child: child,
);

@override
Widget build(BuildContext context) => Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row( // +, -, *, /
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('+'),
_sameCharacterButton('-'),
_sameCharacterButton('*'),
_sameCharacterButton('/'),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('7'),
_sameCharacterButton('8'),
_sameCharacterButton('9'),
_sameCharacterButton('.'),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('4'),
_sameCharacterButton('5'),
_sameCharacterButton('6'),
_sameCharacterButton('x'),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('1'),
_sameCharacterButton('2'),
_sameCharacterButton('3'),
_buttonWrapper(FilledButton(
/// Keyboard with value input, basic operators and submit button.
Widget _buildPrimaryKeyboard(BuildContext context) => Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row( // +, -, *, /
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('+'),
_sameCharacterButton('-'),
_sameCharacterButton('*'),
_sameCharacterButton('/'),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('7'),
_sameCharacterButton('8'),
_sameCharacterButton('9'),
_sameCharacterButton('.'),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('4'),
_sameCharacterButton('5'),
_sameCharacterButton('6'),
_sameCharacterButton('x'),
],
),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_sameCharacterButton('1'),
_sameCharacterButton('2'),
_sameCharacterButton('3'),
_buttonWrapper(Tooltip(
message: 'compute result',
child: FilledButton(
onPressed: onSubmit,
child: const Text('➜')
)),
],
),
const SizedBox(height: 16,),
],
),
),
)),
],
),
],
);

Widget _buildSecondaryKeyboard(BuildContext context) => Column(
children: [
Row(
children: [
_characterButton('√', () => onEntered('sqrt(')),
_characterButton('π', () => onEntered('pi')),
_characterButton('e', () => onEntered('e')),
],
),
Row(
children: [
_characterButton('sin', () => onEntered('sin(')),
_characterButton('cos', () => onEntered('cos(')),
_characterButton('tan', () => onEntered('tan(')),
],
),
Row(
children: [
_characterButton('sin⁻¹', () => onEntered('asin(')),
_characterButton('cos⁻¹', () => onEntered('acos(')),
_characterButton('tan⁻¹', () => onEntered('atan(')),
],
),
Row(
children: [
_sameCharacterButton('('),
_sameCharacterButton(')'),
_sameCharacterButton('='),
],
),
],
);

@override
Widget build(BuildContext context) {
final primaryKB = _buildPrimaryKeyboard(context);
final secondaryKB = _buildSecondaryKeyboard(context);
return Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
primaryKB,
const VerticalDivider(),
secondaryKB,
],
),
);
// TODO: swiping when not enough space
}

}

0 comments on commit 58525cc

Please sign in to comment.