Skip to content

Instantly share code, notes, and snippets.

Created January 3, 2018 02:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1a251fca7692daa71de5bf14b2bfe4ea to your computer and use it in GitHub Desktop.
Save anonymous/1a251fca7692daa71de5bf14b2bfe4ea to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
title: 'GST Calculator',
home: new GstCalculator()
));
}
class GstCalculator extends StatelessWidget {
double billAmount = 0.0;
double gstPercentage = 0.0;
@override
Widget build(BuildContext context) {
// Create first input field
TextField billAmountField = new TextField(
decoration: new InputDecoration(
labelText: "Bill amount(\$)"),
keyboardType: TextInputType.number,
onChanged: (String value) {
try {
billAmount = double.parse(value.toString());
} catch (exception) {
billAmount = 0.0;
}
}
);
RaisedButton calculateButton = new RaisedButton(
child: new Text("Calculate"),
onPressed: () {
// Calculate tip and total
double calculatedGst = billAmount * gstPercentage / 100.0;
double total = billAmount + calculatedGst;
// Generate dialog
AlertDialog dialog = new AlertDialog(
content: new Text("GST Rs: $calculatedGst \n"
"Total Rs.: $total")
);
// Show dialog
showDialog(context: context, child: dialog);
}
);
// Create another input field
TextField gstPercentageField = new TextField(
decoration: new InputDecoration(
labelText: "GST %",hintText: "15"),
keyboardType: TextInputType.number,
onChanged: (String value) {
try {
gstPercentage = double.parse(value.toString());
} catch (exception) {
gstPercentage = 0.0;
}
}
);
Container container = new Container(
padding: const EdgeInsets.all(16.0),
child: new Column(
children: [ billAmountField,
gstPercentageField,
calculateButton ]
)
);
AppBar appBar = new AppBar(title: new Text("GST Calculator"));
Scaffold scaffold = new Scaffold(appBar: appBar,body: container);
return scaffold;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment