The first Row widget is going to contain the button used to delete a single character and the button used to delete the entire expression.
All of the buttons in the app are going to call _CalculatorHomePageState methods, so we need to define them. So, directly below code, add the following empty method definitions, which we will fill up after we define the class to handle the calculations in Use the Calculation Inside the App:
| void add(String a) { |
| } |
| |
| void deleteAll() { |
| } |
| |
| void deleteOne() { |
| } |
| |
| void getResult() { |
| } |
Going back to app layout definition, the buttons will be FlatButtons, which you’ll add to the first Row widget you can see in the code by inserting, inside the square brackets of that Row’s children attribute, the following code:
| FlatButton( |
| child: Text( |
| 'C', |
| style: TextStyle(color: Colors.white), |
| ), |
| onPressed: (){deleteAll();}, |
| color: Colors.black54, |
| ), |
| FlatButton( |
| child: Text( |
| '<-', |
| style: TextStyle(color: Colors.white) |
| ), |
| onPressed: (){deleteOne();}, |
| color: Colors.black87, |
| ), |
Using this code will result in the button on the left (delete all) being gray and the one on the right (delete one character) being black.
That is because the number after the color name (which is used in this manner only with black and white) specifies how transparent they are; a low number means that they are very transparent and almost invisible and a high number is used to make something very opaque.