smart_math 1.0.2 copy "smart_math: ^1.0.2" to clipboard
smart_math: ^1.0.2 copied to clipboard

Smart Math is an advanced Dart mathematics library providing calculator engine, expression parser, scientific functions, finance calculators, unit conversions, fractions, complex numbers, statistics, [...]

example/main.dart

import 'package:flutter/material.dart';
import 'package:smart_math/smart_math.dart';

void main() {
  runApp(const SmartMathDemo());
}

class SmartMathDemo extends StatelessWidget {
  const SmartMathDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        useMaterial3: true,
      ),
      home: const DemoHome(),
    );
  }
}

class DemoHome extends StatelessWidget {
  const DemoHome({super.key});

  @override
  Widget build(BuildContext context) {
    final parser = ExpressionParser();

    // Calculator
    final addition = SmartCalculator.add(10, 20);

    final division = SmartCalculator.divide(100, 5);

    // Expression Parser

    final expression = parser.evaluate("10+(5*2)");

    // Arithmetic

    final factorial = Arithmetic.factorial(5);

    // Scientific

    final power = ScientificCalculator.power(
      2,
      5,
    );

    // Fraction

    final fraction = Fraction(1, 2) + Fraction(1, 3);

    // BigInt

    final bigFactorial = BigIntMath.factorial(20);

    // Complex

    final complex = ComplexNumber(2, 3) * ComplexNumber(1, 2);

    // Finance

    final emi = EMI.calculate(
      principal: 100000,
      annualRate: 8,
      years: 5,
    );

    final sip = SIP.calculate(
      monthlyInvestment: 500,
      annualReturn: 12,
      years: 10,
    );

    final interest = Interest.simple(
      principal: 10000,
      rate: 10,
      years: 2,
    );

    // Health

    final bmi = BMI.calculate(
      weightKg: 70,
      heightMeter: 1.75,
    );

    final age = Age.calculate(
      birthDate: DateTime(2000, 1, 1),
    );

    // Conversion

    final km = LengthConverter.meterToKm(
      5000,
    );

    final pound = WeightConverter.kgToPound(
      10,
    );

    final fahrenheit = TemperatureConverter.celsiusToFahrenheit(
      25,
    );

    // Statistics

    final mean = Statistics.mean(
      [10, 20, 30, 40],
    );

    // Matrix

    final matrix = Matrix(
      [
        [1, 2],
        [3, 4]
      ],
    );

    return Scaffold(
      appBar: AppBar(
        title: const Text(
          "Smart Math Demo",
        ),
      ),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          resultCard(
            "Calculator",
            """
Addition: $addition

Division: $division
""",
          ),
          resultCard(
            "Expression Parser",
            """
10+(5*2)

Result:
$expression
""",
          ),
          resultCard(
            "Arithmetic",
            """
Factorial 5:

$factorial
""",
          ),
          resultCard(
            "Scientific",
            """
2 Power 5:

$power
""",
          ),
          resultCard(
            "Fraction",
            """
1/2 + 1/3

$fraction
""",
          ),
          resultCard(
            "BigInt",
            """
20!

$bigFactorial
""",
          ),
          resultCard(
            "Complex Number",
            """
(2+3i)*(1+2i)

$complex

Magnitude:
${complex.magnitude()}
""",
          ),
          resultCard(
            "Finance",
            """
EMI:
$emi

SIP:
$sip

Simple Interest:
$interest
""",
          ),
          resultCard(
            "Health",
            """
BMI:
$bmi

Category:
${BMI.category(bmi)}

Age:
$age years
""",
          ),
          resultCard(
            "Conversion",
            """
5000 Meter =
$km KM


10 KG =
$pound Pound


25°C =
$fahrenheit°F
""",
          ),
          resultCard(
            "Statistics",
            """
Mean:

$mean
""",
          ),
          resultCard(
            "Matrix",
            """
Matrix:

$matrix


Determinant:

${matrix.determinant()}
""",
          ),
        ],
      ),
    );
  }

  Widget resultCard(
    String title,
    String value,
  ) {
    return Card(
      margin: const EdgeInsets.only(
        bottom: 12,
      ),
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: const TextStyle(
                fontSize: 20,
                fontWeight: FontWeight.bold,
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            Text(
              value,
              style: const TextStyle(
                fontSize: 16,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
145
points
9
downloads

Documentation

API reference

Publisher

verified publisherappifyhaven.website

Weekly Downloads

Smart Math is an advanced Dart mathematics library providing calculator engine, expression parser, scientific functions, finance calculators, unit conversions, fractions, complex numbers, statistics, and more.

Repository (GitHub)
View/report issues

Topics

#calculator #mathematics #parser #conversion #finance

License

MIT (license)

Dependencies

flutter, meta

More

Packages that depend on smart_math