Flutter TaxCalculate 🧮
A Dart package for calculating taxes on prices, supporting both inclusive and exclusive tax calculations. This package is a Dart port of the taxCalculate Go package.
Features ✨
- ✅ Calculate multiple taxes simultaneously
- 🔄 Handle both tax-inclusive and tax-exclusive prices
- 📊 Detailed tax breakdown report
- 🛠️ Simple and intuitive API
- 💰 GHS currency formatting
Installation
Add this to your package's pubspec.yaml file:
dependencies:
flutter_taxcalculate: ^1.0.0
Usage
Basic Usage
import 'package:flutter_taxcalculate/flutter_taxcalculate.dart';
void main() {
// Define your taxes
final taxes = [
Tax(name: 'VAT', rate: 0.15), // 15% VAT
Tax(name: 'NHIL', rate: 0.025), // 2.5% NHIL
];
// Calculate tax-exclusive price
final result = TaxCalculator.calculateTotal(1000.0, taxes);
// Calculate tax-inclusive price
final inclusiveResult = TaxCalculator.calculateTotal(
1000.0,
taxes,
isInclusive: true,
);
}
API Reference
Tax Class
class Tax {
final String name; // Name of the tax
final double rate; // Tax rate (e.g., 0.15 for 15%)
}
TaxCalculator Class
class TaxCalculator {
// Calculate total with taxes
static Map<String, dynamic> calculateTotal(
double price,
List<Tax> taxes, {
bool isInclusive = false,
});
// Format amount as GHS currency
static String formatCurrency(double amount);
}
The calculateTotal method returns a map with:
totalExclusivePrice: The original pricetotal: The final price with all taxestaxAmounts: A map of tax names to their calculated amounts
Example
Check out the example for a complete usage example.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Additional information
Libraries
- flutter_taxcalculate
- A Dart package for calculating taxes on prices, supporting both inclusive and exclusive tax calculations.