Created
January 3, 2018 02:26
-
-
Save anonymous/1a251fca7692daa71de5bf14b2bfe4ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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