in_app_calculator 0.0.3
in_app_calculator: ^0.0.3 copied to clipboard
A customizable, easy-to-integrate in-app calculator widget for Flutter apps with light and dark mode support, result storage, and responsive design.
import 'package:flutter/material.dart';
import 'package:in_app_calculator/in_app_calculator.dart';
class MyApp_ extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp_> {
bool _isCalculatorVisible = false;
String _calculatedResult = "0"; // Store the result here
void _toggleCalculator() {
setState(() {
_isCalculatorVisible = !_isCalculatorVisible; // Toggle visibility
});
}
void _updateResult(String result) {
setState(() {
_calculatedResult = result; // Update result with the calculated value
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Toggle Calculator'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// Button to show/hide calculator
ElevatedButton(
onPressed: _toggleCalculator,
child: Text(
_isCalculatorVisible ? 'Hide Calculator' : 'Show Calculator',
),
),
SizedBox(height: 20),
// Display the calculated result
Text(
'Result: $_calculatedResult',
style: TextStyle(fontSize: 24),
),
SizedBox(height: 20),
// Show the CalculatorWidget only if _isCalculatorVisible is true
if (_isCalculatorVisible)
InAppCalculator(
isDarkMode: true,
onResultCalculated: _updateResult, // Pass the callback
),
],
),
),
),
);
}
}