To keep the project maintainable and scalable, the application is divided into three layers:
Responsible for:
- User interactions
- Display updates
- Event handling
Responsible for:
- Calculator state management
- Tracking operands and operators
- Processing user input
Responsible for:
- Mathematical operations
- Precision handling
- Error handling
- Secure calculations without using
eval()
Goal: Build the calculator engine.
- Create
CalculatorEngine - Store current operand
- Store previous operand
- Store selected operator
- Handle input flow before pressing "="
Goal: Improve the user experience.
- Replace standard buttons with custom
Containerwidgets - Create a minimalist layout
- Improve spacing and alignment
- Add consistent styling
Goal: Make calculations reliable.
- Implement
calculate() - Handle division by zero
- Handle invalid input
- Improve floating-point precision
Goal: Track previous calculations.
- Add history panel
- Create scrollable
ListView - Save operations locally
- Load history on startup
calculator_app/
├── main.py # Flet entry point
├── engine.py # Calculator logic
├── styles.py # Colors, fonts, themes
└── history.json # Optional persistent storage
Instead of evaluating raw strings, operators are mapped directly to Python functions.
import operator
ops = {
"+": operator.add,
"-": operator.sub,
"*": operator.mul,
"/": operator.truediv,
}
# Example
# result = ops[operator_symbol](float(num1), float(num2))- Safer than
eval() - Easier to debug
- Easier to extend
- Better control over errors
- Material Design 3 inspired
- Dark theme
- High contrast colors
- Minimalist layout
INPUTTING_FIRST_NUMBER
↓
WAITING_FOR_OPERATOR
↓
INPUTTING_SECOND_NUMBER
↓
CALCULATE_RESULT
Use regex validation to ensure user input is valid before passing values to the calculation engine.
| Feature | Status |
|---|---|
| Project Structure | ⬜ Planned |
| Calculator Engine | ⬜ Planned |
| UI Components | ⬜ Planned |
| Parsing & Validation | ⬜ Planned |
| History Logging | ⬜ Planned |
| Testing | ⬜ Planned |