Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views4 pages

Practical 2 MP

This document provides a Flutter program for a simple calculator mobile app that performs addition, subtraction, multiplication, and division. It includes a user interface with text fields for input and buttons for each operation, updating the result dynamically. The app is structured using a StatefulWidget to manage state changes effectively.

Uploaded by

virusplays76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Practical 2 MP

This document provides a Flutter program for a simple calculator mobile app that performs addition, subtraction, multiplication, and division. It includes a user interface with text fields for input and buttons for each operation, updating the result dynamically. The app is structured using a StatefulWidget to manage state changes effectively.

Uploaded by

virusplays76
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practical 2

Q.1) Designing the mobile app to implement different widgets

Program:-
import 'package:flutter/material.dart';

void main(){
runApp(MaterialApp(
debugShowCheckedModeBanner: false,
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


TextEditingController controller1 = TextEditingController();
TextEditingController controller2 = TextEditingController();
int? num1 = 0,
num2 = 0,
result = 0;

add(){
setState(() {
num1 = int.parse(controller1.text);
num2 = int.parse(controller2.text);
result = num1! + num2!;
});
}

sub(){
setState(() {
num1 = int.parse(controller1.text);
num2 = int.parse(controller2.text);
result = num1! - num2!;
});
}

mul(){
setState(() {
num1 = int.parse(controller1.text);
num2 = int.parse(controller2.text);
result = num1! * num2!;
});
}

div(){
setState(() {
num1 = int.parse(controller1.text);
num2 = int.parse(controller2.text);
result = num1! ~/ num2!;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Simple Calculator'),
backgroundColor: Colors.blue.shade900,
),
body: Column(
children: [
SizedBox(
height: 15,
),
Text('Result is: $result', style: TextStyle(fontSize: 20,
color: Colors.blue.shade700
),),
SizedBox(
height: 15,
),
TextField(
controller: controller1,
decoration: InputDecoration(
labelText: "Enter number",border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20)
)
),
),
SizedBox(
height: 15,
),
TextField(
controller: controller2,
decoration: InputDecoration(
labelText: "Enter number",border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20)
)
),
),
SizedBox(
height: 15,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(onPressed: (){
add();
controller1.clear();
controller2.clear();
},child: Text('ADD')),
ElevatedButton(onPressed: (){
sub();
},child: Text('SUB'))
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(onPressed: () {
mul();
},child: Text('MUL')),
ElevatedButton(onPressed: () {
div();
},child: Text('DIV')),
],
)

],
),
);
}
}

OutPut:-

You might also like