ZawXtut

flutter_SanDev_calculator005

Oct 26th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.59 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter/material.dart';
  4.  
  5. void main() => runApp(MyApp());
  6.  
  7. class MyApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       debugShowCheckedModeBanner: false,
  12.       title: 'Material App',
  13.       home: Scaffold(
  14.         appBar: AppBar(
  15.           title: Text('Material App Bar'),
  16.         ),
  17.         body: Center(
  18.           child: Container(
  19.             child: _Mbody(),
  20.           ),
  21.         ),
  22.       ),
  23.     );
  24.   }
  25. }
  26.  
  27. class _Mbody extends StatefulWidget {
  28.   _Mbody({Key key}) : super(key: key);
  29.  
  30.   @override
  31.   __MbodyState createState() => __MbodyState();
  32. }
  33.  
  34. class __MbodyState extends State<_Mbody> {
  35.   final txtFieA = TextEditingController();
  36.   final txtFieB = TextEditingController();
  37.   var _result = 0;
  38.   void _add() {
  39.     _result = int.parse(txtFieA.text) + int.parse(txtFieB.text);
  40.     //  setState(() {});
  41.   }
  42.  
  43.   void _sub() {
  44.     _result = int.parse(txtFieA.text) - int.parse(txtFieB.text);
  45.     //setState(() {});
  46.   }
  47.  
  48.   void _div() {
  49.     //_result = (int.parse(txtFieB.text) ~/ int.parse(txtFieA.text));
  50.     double num1 = double.parse(txtFieA.text);
  51.     double num2 = double.parse(txtFieB.text);
  52.     _result = (num1 / num2) as int;
  53.     // setState(() {});
  54.   }
  55.  
  56.   void _mul() {
  57.     _result = int.parse(txtFieA.text) * int.parse(txtFieB.text);
  58.     //setState(() {});
  59.   }
  60.  
  61.   void _enter() {
  62.     setState(() {});
  63.   }
  64.  
  65.   @override
  66.   Widget build(BuildContext context) {
  67.     return Column(
  68.       children: [
  69.         Container(
  70.           margin: EdgeInsets.only(top: 20),
  71.           padding: EdgeInsets.fromLTRB(50, 20, 50, 20),
  72.           decoration: BoxDecoration(
  73.               color: Colors.lightBlueAccent,
  74.               borderRadius: BorderRadius.circular(20)),
  75.           child: Text(
  76.             _result.toString(),
  77.             style: TextStyle(fontSize: 30),
  78.           ),
  79.         ),
  80.         Container(
  81.           margin: EdgeInsets.only(top: 20),
  82.           decoration: BoxDecoration(
  83.               borderRadius: BorderRadius.circular(15), color: Colors.cyan),
  84.           padding: EdgeInsets.all(5),
  85.           child: TextField(
  86.             controller: txtFieA,
  87.             keyboardType: TextInputType.number,
  88.             decoration: InputDecoration(
  89.                 hintText: "Number1", border: OutlineInputBorder()),
  90.           ),
  91.         ),
  92.         Container(
  93.           margin: EdgeInsets.only(top: 20),
  94.           decoration: BoxDecoration(
  95.               borderRadius: BorderRadius.circular(15), color: Colors.cyan),
  96.           padding: EdgeInsets.all(5),
  97.           child: TextField(
  98.             controller: txtFieB,
  99.             keyboardType: TextInputType.number,
  100.             decoration: InputDecoration(
  101.                 hintText: "Number2", border: OutlineInputBorder()),
  102.           ),
  103.         ),
  104.         Container(
  105.           margin: EdgeInsets.only(top: 20),
  106.           child: Row(
  107.             mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  108.             children: [
  109.               RaisedButton(
  110.                 color: Colors.blueGrey,
  111.                 onPressed: () {
  112.                   _add();
  113.                 },
  114.                 child: Text('+'),
  115.               ),
  116.               RaisedButton(
  117.                 color: Colors.blueGrey,
  118.                 onPressed: () {
  119.                   _sub();
  120.                 },
  121.                 child: Text('-'),
  122.               ),
  123.             ],
  124.           ),
  125.         ),
  126.         Container(
  127.           margin: EdgeInsets.only(top: 20),
  128.           child: Row(
  129.             mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  130.             children: [
  131.               RaisedButton(
  132.                 color: Colors.blueGrey,
  133.                 onPressed: () {
  134.                   _mul();
  135.                 },
  136.                 child: Text('x'),
  137.               ),
  138.               RaisedButton(
  139.                 color: Colors.blueGrey,
  140.                 onPressed: () {
  141.                   _div();
  142.                 },
  143.                 child: Text('÷'),
  144.               ),
  145.             ],
  146.           ),
  147.         ),
  148.         Row(children: [
  149.           Expanded(
  150.             child: Container(
  151.               margin: EdgeInsets.fromLTRB(70, 20, 70, 0),
  152.               child: RaisedButton(
  153.                 padding: EdgeInsets.all(20),
  154.                 color: Colors.blueGrey,
  155.                 onPressed: () {
  156.                   _enter();
  157.                 },
  158.                 child: Text(
  159.                   "=",
  160.                   style: TextStyle(fontSize: 25),
  161.                 ),
  162.               ),
  163.             ),
  164.           ),
  165.         ]),
  166.       ],
  167.     );
  168.   }
  169. }
  170.  
Add Comment
Please, Sign In to add comment