Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Muh Fiqry Pratama

221220639
Tugas 2
Code
// ignore_for_file: prefer_const_constructors, sort_child_properties_last,
deprecated_member_use, unused_import

import 'package:flutter/material.dart';
import 'dart:math';
import 'package:flutter/services.dart';

void main() {
runApp(const MyWidget());
}

class MyWidget extends StatelessWidget {


const MyWidget({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.blue),
home: MyKalkulator(),
);
}
}

class MyKalkulator extends StatefulWidget {


const MyKalkulator({super.key});

@override
State<MyKalkulator> createState() => _MyKalkulatorState();
}

class _MyKalkulatorState extends State<MyKalkulator> {


TextEditingController bilA = TextEditingController();
TextEditingController bilB = TextEditingController();
TextEditingController bilC = TextEditingController();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Kalkulator"),
actions: [
IconButton(
icon: Icon(Icons.exit_to_app),
onPressed: () {
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
},
),
],
),
body: Column(
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Column(
children: <Widget>[
Image.network(
"https://cmsv2-
assets.apptegy.net/uploads/12837/file/1394965/86a7f4dc-5aba-4456-967d-
1bfbc3d4aa01.jpeg",
width: 300,
height: 300,
),
TextField(
controller: bilA,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Bilangan A',
),
),
SizedBox(height: 20),
TextField(
controller: bilB,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Bilangan B',
),
),
SizedBox(height: 20),
TextField(
controller: bilC,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Hasil',
),
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double B = double.parse(bilB.text);
double c = A + B;
bilC.text = c.toString();
},
child: Text("+"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double B = double.parse(bilB.text);
double c = A - B;
bilC.text = c.toString();
},
child: Text("-"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double B = double.parse(bilB.text);
double c = A / B;
bilC.text = c.toString();
},
child: Text("/"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
],
),
Padding(padding: EdgeInsetsDirectional.all(10)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double B = double.parse(bilB.text);
double c = A * B;
bilC.text = c.toString();
},
child: Text("*"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double B = double.parse(bilB.text);
num c = pow(A, B);
bilC.text = c.toString();
},
child: Text("^"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double B = double.parse(bilB.text);
double c = A % B;
bilC.text = c.toString();
},
child: Text("%"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
],
),
Padding(padding: EdgeInsetsDirectional.all(10)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double c = sqrt(A);
bilC.text = c.toString();
},
child: Text("√"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
num c = tan(A);
bilC.text = c.toString();
},
child: Text("Tan"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double c = sin(A);
bilC.text = c.toString();
},
child: Text("Sin"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
],
),
SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
double c = cos(A);
bilC.text = c.toString();
},
child: Text("Cos"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
double A = double.parse(bilA.text);
num c = log(A);
bilC.text = c.toString();
},
child: Text("Log"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
SizedBox(width: 16),
SizedBox(
width: 100,
height: 50,
child: ElevatedButton(
onPressed: () {
bilA.clear();
bilB.clear();
bilC.clear();
},
child: Text("Clear"),
style: ElevatedButton.styleFrom(
primary: Color.fromARGB(255, 1, 159, 244),
side: BorderSide(color: Colors.yellow, width: 5),
textStyle: TextStyle(
color: Colors.white,
fontSize: 25,
fontStyle: FontStyle.normal),
shadowColor: Colors.lightBlue,
),
),
),
],
),
],
),
),
],
),
);
}
}

Hasil
Flowchart

You might also like