flutter_simple_calculator 2.2.4 flutter_simple_calculator: ^2.2.4 copied to clipboard
Flutter widget that provides simple calculator. You can easily integrate a calculator to your apps.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('SimpleCalculator'),
),
body: const Padding(
padding: EdgeInsets.all(18.0),
child: SizedBox(
width: double.infinity,
child: CalcButton(),
),
),
),
);
}
}
class CalcButton extends StatefulWidget {
const CalcButton({Key? key}) : super(key: key);
@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,
autofocus: true,
onChanged: (key, value, expression) {
setState(() {
_currentValue = value ?? 0;
});
if (kDebugMode) {
print('$key\t$value\t$expression');
}
},
onTappedDisplay: (value, details) {
if (kDebugMode) {
print('$value\t${details.globalPosition}');
}
},
theme: const CalculatorThemeData(
borderColor: Colors.black,
borderWidth: 2,
displayColor: Colors.black,
displayStyle: TextStyle(fontSize: 80, color: Colors.yellow),
expressionColor: Colors.indigo,
expressionStyle: TextStyle(fontSize: 20, color: Colors.white),
operatorColor: Colors.pink,
operatorStyle: TextStyle(fontSize: 30, color: Colors.white),
commandColor: Colors.orange,
commandStyle: TextStyle(fontSize: 30, color: Colors.white),
numColor: Colors.grey,
numStyle: 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);
});
},
);
}
}