flutter_simple_calculator 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 71

flutter_simple_calculator #

Flutter widget that provides simple calculator. You can easily integrate a calculator to your apps.

pub package

Default style #

With custom styles #

SimpleCalculator(
  theme: const CalculatorThemeData(
    displayColor: Colors.black,
    displayStyle: const TextStyle(fontSize: 80, color: Colors.yellow),
    /*...*/
  ),
)

Localize #

SimpleCalculator(
  numberFormat: NumberFormat.decimalPattern("fa_IR")
    ..maximumFractionDigits = 6,
)

Getting Started #

To use this plugin, add flutter_simple_calculator as a dependency in your pubspec.yaml file.

dependencies:
 flutter_simple_calculator: 

Import the library in your file.

import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';

See the example directory for a complete sample app using GridButton. Or use the GridButton like below.

SimpleCalculator(
  value: 123.45,
  hideExpression: true,
  onChanged: (key, value, expression) {
    /*...*/
  },
  theme: const CalculatorThemeData(
    displayColor: Colors.black,
    displayStyle: const TextStyle(fontSize: 80, color: Colors.yellow),
  ),
)

[1.0.2]

  • Changed default colors for dark theme.
  • Updated library version.

[1.0.1]

  • Added SimpleCalculator.hideSurroundingBorder.
  • Added CalculatorThemeData.borderWidth.
  • Fixed a state related issue.

[1.0.0]

  • First Release.

example/lib/main.dart

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");
      },
      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 OutlineButton(
      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);
            });
      },
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_simple_calculator: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
71
Learn more about scoring.

We analyzed this package on Nov 15, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/src/main.dart.

Run flutter format to format lib/src/main.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
auto_size_text ^2.1.0 2.1.0
expressions ^0.1.2 0.1.2
flutter 0.0.0
flutter_grid_button ^1.1.6 1.1.6
intl ^0.16.0 0.16.0
Transitive dependencies
collection 1.14.11 1.14.12
matcher 0.12.6
meta 1.1.7 1.1.8
path 1.6.4
petitparser 2.4.0
quiver 2.1.2+1
sky_engine 0.0.99
stack_trace 1.9.3
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test