-4

Title: Flutter Calculator Layout Issue - Buttons Not Displaying Correctly

Description:

I'm building a calculator app in Flutter and facing layout problems with the button grid. The calculator interface consists of a display area and a keyboard grid, but the buttons are not rendering properly.

asked Nov 22 at 7:26
New contributor
Oxsine is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 2
    There's nothing in your question that we can answer. It's not clear whether the code in the answer you've posted is intended to be part if this question, or represents some sort of answer. Commented Nov 22 at 8:08

1 Answer 1

-1
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Calc()));
class Calc extends StatefulWidget {
 @override
 _CalcState createState() => _CalcState();
}
class _CalcState extends State<Calc> {
 String d = '0', o = '';
 double n1 = 0, n2 = 0;
 void p(String v) {
 setState(() {
 if (v == 'C') {
 d = '0'; o = ''; n1 = 0; n2 = 0;
 } else if (v == '=') {
 n2 = double.parse(d);
 if (o == '+') d = (n1 + n2).toString();
 if (o == '-') d = (n1 - n2).toString();
 if (o == ×ばつ') d = (n1 * n2).toString();
 if (o == '÷') d = (n1 / n2).toString();
 o = '';
 } else if (['+', '-', ×ばつ', '÷'].contains(v)) {
 n1 = double.parse(d);
 o = v;
 d = '0';
 } else {
 d = d == '0' ? v : d + v;
 }
 });
 }
 Widget b(String t) => Expanded(
 child: Padding(
 padding: EdgeInsets.all(4),
 child: ElevatedButton(
 onPressed: () => p(t),
 child: Text(t, style: TextStyle(fontSize: 24)),
 style: ElevatedButton.styleFrom(padding: EdgeInsets.all(20)),
 ),
 ),
 );
 @override
 Widget build(BuildContext context) => Scaffold(
 appBar: AppBar(title: Text('Калькулятор')),
 body: Column(
 children: [
 Expanded(
 child: Container(
 alignment: Alignment.bottomRight,
 padding: EdgeInsets.all(24),
 child: Text(d, style: TextStyle(fontSize: 48)),
 ),
 ),
 Row(children: ['7', '8', '9', '÷'].map(b).toList()),
 Row(children: ['4', '5', '6', ×ばつ'].map(b).toList()),
 Row(children: ['1', '2', '3', '-'].map(b).toList()),
 Row(children: ['C', '0', '=', '+'].map(b).toList()),
 ],
 ),
 );
}
answered Nov 22 at 7:28
New contributor
Oxsine is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Sign up to request clarification or add additional context in comments.

1 Comment

is this your question part that causing the issue?if so you can add this into the question & if not you can add trouble snippet into the question section

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.