flutter_simple_calculator 2.0.0-nullsafety.0 flutter_simple_calculator: ^2.0.0-nullsafety.0 copied to clipboard
Flutter widget that provides simple calculator. You can easily integrate a calculator to your apps.
import 'package:flutter/material.dart';
import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('SimpleCalculator'),
),
body: Padding(
padding: const EdgeInsets.all(18.0),
child: SizedBox(
width: double.infinity,
child: CalcButton(),
),
),
),
);
}
}
class CalcButton extends StatefulWidget {
@override
_CalcButtonState createState() => _CalcButtonState();
}
class _CalcButtonState extends State<CalcButton> {
double _currentValue = 0;
@override
Widget build(BuildContext context) {
var calc = SimpleCalculator(
value: _currentValue,
hideExpression: false,
hideSurroundingBorder: true,
onChanged: (key, value, expression) {
setState(() {
_currentValue = value;
});
print("$key\t$value\t$expression");
},
onTappedDisplay: (value, details) {
print("$value\t${details.globalPosition}");
},
theme: const CalculatorThemeData(
borderColor: Colors.black,
borderWidth: 2,
displayColor: Colors.black,
displayStyle: const TextStyle(fontSize: 80, color: Colors.yellow),
expressionColor: Colors.indigo,
expressionStyle: const TextStyle(fontSize: 20, color: Colors.white),
operatorColor: Colors.pink,
operatorStyle: const TextStyle(fontSize: 30, color: Colors.white),
commandColor: Colors.orange,
commandStyle: const TextStyle(fontSize: 30, color: Colors.white),
numColor: Colors.grey,
numStyle: const TextStyle(fontSize: 50, color: Colors.white),
),
);
return OutlinedButton(
child: Text(_currentValue.toString()),
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
context: context,
builder: (BuildContext context) {
return SizedBox(
height: MediaQuery.of(context).size.height * 0.75,
child: calc);
});
},
);
}
}