gst_calculator 0.0.3
gst_calculator: ^0.0.3 copied to clipboard
Indian GST calculator for Dart and Flutter. Add or remove GST, split CGST/SGST/IGST, with optional paise-accurate rounding.
import 'package:gst_calculator/gst_calculator.dart';
void main() {
// GST-exclusive price: add 18% GST to ₹1,000 for a sale within one state.
final added = GstCalculator.addGST(amount: 1000, gstRate: 18);
print('Base: ${added.baseAmount}'); // 1000.0
print('CGST: ${added.cgst}'); // 90.0
print('SGST: ${added.sgst}'); // 90.0
print('Total: ${added.total}'); // 1180.0
// GST-inclusive price: split ₹1,180 for a sale to another state.
final removed = GstCalculator.removeGST(
amount: 1180,
gstRate: 18,
isInterState: true,
);
print('Base: ${removed.baseAmount}'); // 1000.0
print('IGST: ${removed.igst}'); // 180.0
// Invoice-ready values rounded to paise.
final invoice = GstCalculator.addGST(
amount: 99.99,
gstRate: 5,
fractionDigits: 2,
);
print(invoice); // cgst: 2.5, sgst: 2.5, total: 104.99
// Invalid input throws an ArgumentError.
try {
GstCalculator.addGST(amount: 100, gstRate: -5);
} on ArgumentError catch (e) {
print('Error: ${e.message}');
}
}