Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'alertz_box.dart';
- class SiApp extends StatefulWidget {
- @override
- State<StatefulWidget> createState() => _SiForm();
- }
- class _SiForm extends State<SiApp> {
- var _currencies = ['Select Currency', 'Rupees', 'Dollar', 'Pound'];
- var _currentItemSelected = 'Select Currency';
- TextEditingController principalController = TextEditingController();
- TextEditingController roiController = TextEditingController();
- TextEditingController termController = TextEditingController();
- var displayResult = '';
- var _formKey = GlobalKey<FormState>();
- //final _minipadding = 5.0;
- @override
- Widget build(BuildContext context) {
- TextStyle textStyle = Theme.of(context).textTheme.title;
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- theme: ThemeData(
- primaryColor: Colors.purple, accentColor: Colors.purpleAccent),
- home: Scaffold(
- appBar: AppBar(
- centerTitle: true,
- title: Text(
- "Simple Interest Calculator",
- style: TextStyle(
- fontFamily: 'PoiretOne',
- fontSize: 25.0,
- fontWeight: FontWeight.bold),
- ),
- // backgroundColor: Colors.teal,
- ),
- body: Form(
- key: _formKey,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: ListView(
- children: <Widget>[
- getImage(),
- SizedBox(
- height: 10.0,
- ),
- // Column(
- // children: <Widget>[
- TextFormField(
- keyboardType: TextInputType.number,
- validator: (String value) {
- if (value.isEmpty) {
- return 'Please Enter Principal Amount';
- }
- },
- // style: textStyle,
- controller: principalController,
- decoration: InputDecoration(
- labelText: "Principal",
- // labelStyle: textStyle,
- hintText: "Enter principal e.g:- 12000",
- // errorText:'Please ',
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0)),
- ),
- ),
- SizedBox(
- height: 10.0,
- ),
- TextFormField(
- keyboardType: TextInputType.number,
- validator: (String value) {
- if (value.isEmpty) {
- return 'Please Enter Interest';
- }},
- controller: roiController,
- decoration: InputDecoration(
- labelText: "Rate of interest",
- hintText: "Enter rate of interest",
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0)),
- ),
- ),
- SizedBox(height: 10.0),
- Row(
- children: <Widget>[
- Expanded(
- child: TextFormField(
- keyboardType: TextInputType.number,
- validator: (String value) {
- if (value.isEmpty) {
- return 'Please Enter Term';
- }},
- controller: termController,
- decoration: InputDecoration(
- labelText: "Term",
- hintText: "Time in years",
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(10.0)),
- ),
- )),
- SizedBox(width: 20.0),
- Container(
- height: 60.0,
- decoration: ShapeDecoration(
- shape: RoundedRectangleBorder(
- side: BorderSide(color: Colors.black54),
- borderRadius: BorderRadius.circular(10.0)),
- ),
- child: DropdownButtonHideUnderline(
- child: ButtonTheme(
- alignedDropdown: true,
- child: DropdownButton<String>(
- items: _currencies.map((String dropDownStringItem) {
- return DropdownMenuItem<String>(
- value: dropDownStringItem,
- child: Text(dropDownStringItem));
- }).toList(),
- onChanged: (String newValueSelected) {
- _OndropDownItemSelected(newValueSelected);
- },
- value: _currentItemSelected,
- // hint: Text('Select Currency'),
- ),
- ),
- ),
- ),
- ],
- ),
- SizedBox(
- height: 10.0,
- ),
- Row(
- children: <Widget>[
- Expanded(
- child: FlatButton(
- child: Text(
- "Reset",
- style: TextStyle(
- fontSize: 25.0,
- fontFamily: 'PoiretOne',
- fontWeight: FontWeight.bold,
- color: Colors.teal,
- ),
- ),
- // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0),),
- onPressed: () {
- setState(() {
- reset();
- });
- })),
- SizedBox(
- width: 20.0,
- ),
- Expanded(
- child: RaisedGradientButton(
- child: Text(
- 'Calculate',
- style: TextStyle(
- fontSize: 20.0,
- color: Colors.white,
- fontFamily: 'PoiretOne',
- fontWeight: FontWeight.bold),
- ),
- gradient: LinearGradient(colors: <Color>[
- Colors.purple,
- Colors.yellowAccent,
- ]),
- onPressed: () {
- setState(() {
- if (_formKey.currentState.validate()) {
- this.displayResult = _calculateTotalReturns();
- // build(BuildContext context) {
- // showDialog();
- // }
- }
- });
- },
- ),
- ),
- ],
- ),
- // SizedBox(height: 20.0),
- // Text(displayResult),
- showDialog(),
- ],
- ),
- ),
- ),
- ),
- );
- }
- void _OndropDownItemSelected(String newValueSelected) {
- setState(() {
- this._currentItemSelected = newValueSelected;
- });
- }
- void reset() {
- principalController.text = '';
- roiController.text = '';
- termController.text = '';
- displayResult = '';
- _currentItemSelected = 'Select Currency';
- }
- String _calculateTotalReturns() {
- double principal = double.parse(principalController.text);
- double roi = double.parse(roiController.text);
- double term = double.parse(termController.text);
- double totalInterest = principal + (principal * roi * term) / 100;
- String result =
- 'After $term years, your investment will be worth $totalInterest $_currentItemSelected';
- return result;
- }
- Widget showDialog(){
- return AlertDialog(
- title: Text('Result'),
- content: Text(displayResult, style: TextStyle(
- fontFamily: 'PoiretOne',
- fontWeight: FontWeight.bold,
- color: Colors.black),),
- actions: <Widget>[
- // usually buttons at the bottom of the dialog
- new FlatButton(
- child: new Text("Close"),
- onPressed: () {
- Navigator.of(context).pop();
- },
- ),
- ],
- );
- }
- }
- Widget getImage() {
- return Container(
- height: 200.0,
- width: 400.0,
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage("images/money.png"), fit: BoxFit.fitWidth),
- ),
- );
- }
- class RaisedGradientButton extends StatelessWidget {
- final Widget child;
- final Gradient gradient;
- final double width;
- final double height;
- final Function onPressed;
- const RaisedGradientButton({
- Key key,
- @required this.child,
- this.gradient,
- this.width = double.infinity,
- this.height = 50.0,
- this.onPressed,
- }) : super(key: key);
- @override
- Widget build(BuildContext context) {
- return Container(
- width: width,
- height: 50.0,
- decoration: BoxDecoration(
- gradient: gradient,
- borderRadius: BorderRadius.circular(30.0),
- boxShadow: [
- BoxShadow(
- color: Colors.grey[500],
- offset: Offset(0.0, 1.5),
- blurRadius: 1.5,
- ),
- ]),
- child: Material(
- color: Colors.transparent,
- child: InkWell(
- onTap: onPressed,
- child: Center(
- child: child,
- )),
- ),
- );
- }
- }
Add Comment
Please, Sign In to add comment