Very simple calculator App done in 90 lines of code, inspired by Elmish.Calculator done in Xamarin Forms.
flutter_calculator's Introduction
flutter_calculator's People
flutter_calculator's Issues
New logo design for the project
Hello! I want to contribute on your project with making logo design. What do you think about it?
Best Regards,
Arslan Şahin
Graphics Designer
Shorter but still readable
import 'dart:math';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
MyAppState createState() {return new MyAppState();}
}
typedef OperatorFunc = double Function(double accu, double operand);
class MyAppState extends State<MyApp> {
double accu = 0.0;
double operand = 0.0;
OperatorFunc queuedOperation;
String resultString = "0.0";
void numberPressed(int value) {
operand = operand * 10 + value;
setState(() => resultString = operand.toString());
}
void calc(OperatorFunc operation) {
if (operation == null) // C was pressed
{ accu = 0.0; } else
{ accu = queuedOperation != null ? queuedOperation(accu, operand) : operand; }
queuedOperation = operation;
operand = 0.0;
var result = accu.toString();
setState(() => resultString = result.toString().substring(0, min(10,result.length) ));
}
List<Widget> buildNumberButtons( int count,int from, int flex) {
return new Iterable.generate(count, (index) {
return new Expanded(flex: flex, child: new Padding(padding: const EdgeInsets.all(1.0), child: FlatButton(onPressed: () => numberPressed(from + index), color: Colors.white, child: Text("${from + index}", style: TextStyle(fontSize: 40.0),)),),); }).toList();
}
Widget buildOperatorButton(String label, OperatorFunc func, int flex, {Color color = Colors.amber}){
return Expanded(flex: flex,
child: Padding(
padding: const EdgeInsets.all(1.0),
child: FlatButton(onPressed: () => calc(func), color: color,
child: Text(label, style: TextStyle(fontSize: 40.0),)),
),); }
Widget buildRow(int numberKeyCount, int startNumber, int numberFlex, String operationLabel, OperatorFunc operation, int operrationFlex){
return new Expanded(child:
Row(crossAxisAlignment: CrossAxisAlignment.stretch,
children: new List.from(buildNumberButtons(numberKeyCount,startNumber ,numberFlex,))
..add(buildOperatorButton(operationLabel, operation, operrationFlex))));
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new SafeArea(
child: new Material(color: Colors.black,
child: Column( crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Expanded(child: Row(crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.end, children: [Text(resultString,textAlign: TextAlign.right, style: TextStyle(fontSize: 50.0, color: Colors.white),)])),
buildRow(3,7,1,"/", (accu, dividor)=> accu / dividor , 1), buildRow(3,4,1,"x", (accu, dividor)=> accu * dividor , 1), buildRow(3,1,1,"-", (accu, dividor)=> accu - dividor , 1), buildRow(1, 0,3,"+", (accu, dividor)=> accu + dividor , 1),
Expanded(child:Row(crossAxisAlignment: CrossAxisAlignment.stretch,children: [buildOperatorButton("C", null, 1, color: Colors.grey),buildOperatorButton("=", (accu, dividor)=> accu, 3)],)) ],),),)); } }
how to input decimal
how to input decimal?
Operation not working
Operation /, x, -, +, c, = not working.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.