Guest User

Untitled

a guest
Feb 17th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.74 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'alertz_box.dart';
  3.  
  4.  
  5. class SiApp extends StatefulWidget {
  6. @override
  7. State<StatefulWidget> createState() => _SiForm();
  8. }
  9.  
  10. class _SiForm extends State<SiApp> {
  11. var _currencies = ['Select Currency', 'Rupees', 'Dollar', 'Pound'];
  12. var _currentItemSelected = 'Select Currency';
  13. TextEditingController principalController = TextEditingController();
  14. TextEditingController roiController = TextEditingController();
  15. TextEditingController termController = TextEditingController();
  16.  
  17. var displayResult = '';
  18. var _formKey = GlobalKey<FormState>();
  19.  
  20. //final _minipadding = 5.0;
  21. @override
  22. Widget build(BuildContext context) {
  23. TextStyle textStyle = Theme.of(context).textTheme.title;
  24.  
  25. return MaterialApp(
  26. debugShowCheckedModeBanner: false,
  27. theme: ThemeData(
  28. primaryColor: Colors.purple, accentColor: Colors.purpleAccent),
  29. home: Scaffold(
  30. appBar: AppBar(
  31. centerTitle: true,
  32. title: Text(
  33. "Simple Interest Calculator",
  34. style: TextStyle(
  35. fontFamily: 'PoiretOne',
  36. fontSize: 25.0,
  37. fontWeight: FontWeight.bold),
  38. ),
  39. // backgroundColor: Colors.teal,
  40. ),
  41. body: Form(
  42. key: _formKey,
  43. child: Padding(
  44. padding: const EdgeInsets.all(8.0),
  45. child: ListView(
  46. children: <Widget>[
  47. getImage(),
  48.  
  49. SizedBox(
  50. height: 10.0,
  51. ),
  52. // Column(
  53. // children: <Widget>[
  54. TextFormField(
  55. keyboardType: TextInputType.number,
  56. validator: (String value) {
  57. if (value.isEmpty) {
  58. return 'Please Enter Principal Amount';
  59. }
  60. },
  61. // style: textStyle,
  62. controller: principalController,
  63. decoration: InputDecoration(
  64. labelText: "Principal",
  65. // labelStyle: textStyle,
  66. hintText: "Enter principal e.g:- 12000",
  67. // errorText:'Please ',
  68. border: OutlineInputBorder(
  69. borderRadius: BorderRadius.circular(10.0)),
  70. ),
  71. ),
  72. SizedBox(
  73. height: 10.0,
  74. ),
  75. TextFormField(
  76. keyboardType: TextInputType.number,
  77. validator: (String value) {
  78. if (value.isEmpty) {
  79. return 'Please Enter Interest';
  80. }},
  81. controller: roiController,
  82. decoration: InputDecoration(
  83. labelText: "Rate of interest",
  84. hintText: "Enter rate of interest",
  85. border: OutlineInputBorder(
  86. borderRadius: BorderRadius.circular(10.0)),
  87. ),
  88. ),
  89. SizedBox(height: 10.0),
  90.  
  91. Row(
  92. children: <Widget>[
  93. Expanded(
  94. child: TextFormField(
  95. keyboardType: TextInputType.number,
  96. validator: (String value) {
  97. if (value.isEmpty) {
  98. return 'Please Enter Term';
  99. }},
  100. controller: termController,
  101. decoration: InputDecoration(
  102. labelText: "Term",
  103. hintText: "Time in years",
  104. border: OutlineInputBorder(
  105. borderRadius: BorderRadius.circular(10.0)),
  106. ),
  107. )),
  108. SizedBox(width: 20.0),
  109. Container(
  110. height: 60.0,
  111. decoration: ShapeDecoration(
  112. shape: RoundedRectangleBorder(
  113. side: BorderSide(color: Colors.black54),
  114. borderRadius: BorderRadius.circular(10.0)),
  115. ),
  116. child: DropdownButtonHideUnderline(
  117. child: ButtonTheme(
  118. alignedDropdown: true,
  119. child: DropdownButton<String>(
  120. items: _currencies.map((String dropDownStringItem) {
  121. return DropdownMenuItem<String>(
  122. value: dropDownStringItem,
  123. child: Text(dropDownStringItem));
  124. }).toList(),
  125. onChanged: (String newValueSelected) {
  126. _OndropDownItemSelected(newValueSelected);
  127. },
  128. value: _currentItemSelected,
  129. // hint: Text('Select Currency'),
  130. ),
  131. ),
  132. ),
  133. ),
  134. ],
  135. ),
  136. SizedBox(
  137. height: 10.0,
  138. ),
  139.  
  140. Row(
  141. children: <Widget>[
  142. Expanded(
  143. child: FlatButton(
  144. child: Text(
  145. "Reset",
  146. style: TextStyle(
  147. fontSize: 25.0,
  148. fontFamily: 'PoiretOne',
  149. fontWeight: FontWeight.bold,
  150. color: Colors.teal,
  151. ),
  152. ),
  153. // shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0),),
  154. onPressed: () {
  155. setState(() {
  156. reset();
  157. });
  158. })),
  159. SizedBox(
  160. width: 20.0,
  161. ),
  162. Expanded(
  163. child: RaisedGradientButton(
  164. child: Text(
  165. 'Calculate',
  166. style: TextStyle(
  167. fontSize: 20.0,
  168. color: Colors.white,
  169. fontFamily: 'PoiretOne',
  170. fontWeight: FontWeight.bold),
  171. ),
  172. gradient: LinearGradient(colors: <Color>[
  173. Colors.purple,
  174. Colors.yellowAccent,
  175. ]),
  176. onPressed: () {
  177. setState(() {
  178. if (_formKey.currentState.validate()) {
  179. this.displayResult = _calculateTotalReturns();
  180. // build(BuildContext context) {
  181. // showDialog();
  182. // }
  183. }
  184. });
  185. },
  186. ),
  187. ),
  188. ],
  189. ),
  190. // SizedBox(height: 20.0),
  191. // Text(displayResult),
  192. showDialog(),
  193. ],
  194. ),
  195. ),
  196. ),
  197. ),
  198. );
  199. }
  200.  
  201. void _OndropDownItemSelected(String newValueSelected) {
  202. setState(() {
  203. this._currentItemSelected = newValueSelected;
  204. });
  205. }
  206.  
  207. void reset() {
  208. principalController.text = '';
  209. roiController.text = '';
  210. termController.text = '';
  211.  
  212. displayResult = '';
  213. _currentItemSelected = 'Select Currency';
  214. }
  215.  
  216. String _calculateTotalReturns() {
  217. double principal = double.parse(principalController.text);
  218. double roi = double.parse(roiController.text);
  219. double term = double.parse(termController.text);
  220.  
  221. double totalInterest = principal + (principal * roi * term) / 100;
  222. String result =
  223. 'After $term years, your investment will be worth $totalInterest $_currentItemSelected';
  224. return result;
  225. }
  226.  
  227. Widget showDialog(){
  228. return AlertDialog(
  229. title: Text('Result'),
  230. content: Text(displayResult, style: TextStyle(
  231. fontFamily: 'PoiretOne',
  232. fontWeight: FontWeight.bold,
  233. color: Colors.black),),
  234. actions: <Widget>[
  235. // usually buttons at the bottom of the dialog
  236. new FlatButton(
  237. child: new Text("Close"),
  238. onPressed: () {
  239. Navigator.of(context).pop();
  240. },
  241. ),
  242. ],
  243. );
  244. }
  245.  
  246. }
  247.  
  248. Widget getImage() {
  249. return Container(
  250. height: 200.0,
  251. width: 400.0,
  252. decoration: BoxDecoration(
  253. image: DecorationImage(
  254. image: AssetImage("images/money.png"), fit: BoxFit.fitWidth),
  255. ),
  256. );
  257. }
  258.  
  259.  
  260.  
  261. class RaisedGradientButton extends StatelessWidget {
  262. final Widget child;
  263. final Gradient gradient;
  264. final double width;
  265. final double height;
  266. final Function onPressed;
  267.  
  268. const RaisedGradientButton({
  269. Key key,
  270. @required this.child,
  271. this.gradient,
  272. this.width = double.infinity,
  273. this.height = 50.0,
  274. this.onPressed,
  275. }) : super(key: key);
  276.  
  277. @override
  278. Widget build(BuildContext context) {
  279. return Container(
  280. width: width,
  281. height: 50.0,
  282. decoration: BoxDecoration(
  283. gradient: gradient,
  284. borderRadius: BorderRadius.circular(30.0),
  285. boxShadow: [
  286. BoxShadow(
  287. color: Colors.grey[500],
  288. offset: Offset(0.0, 1.5),
  289. blurRadius: 1.5,
  290. ),
  291. ]),
  292. child: Material(
  293. color: Colors.transparent,
  294. child: InkWell(
  295. onTap: onPressed,
  296. child: Center(
  297. child: child,
  298. )),
  299. ),
  300. );
  301. }
  302. }
Add Comment
Please, Sign In to add comment