Skip to content

Instantly share code, notes, and snippets.

@kennedisimbolo
Created September 21, 2020 06:58
Show Gist options
  • Save kennedisimbolo/6d865aa1072b1331cafd395c4d760eb0 to your computer and use it in GitHub Desktop.
Save kennedisimbolo/6d865aa1072b1331cafd395c4d760eb0 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Program Luas Segitiga'),
),
body: Penjumlahan(),
),
);
}
}
class Penjumlahan extends StatefulWidget {
_PenjumlahanState createState() => _PenjumlahanState();
}
class _PenjumlahanState extends State<Penjumlahan> {
final txtalas = TextEditingController();
final txttinggi = TextEditingController();
String result = '';
getTextInputData() {
setState(() {
var alas = int.parse(txtalas.text);
var tinggi = int.parse(txttinggi.text);
var luas = 1/2 * alas * tinggi;
result = luas.toString();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 280,
padding: EdgeInsets.all(10.0),
child: TextField(
controller: txtalas,
autocorrect: true,
decoration: InputDecoration(hintText: 'Alas'),
)),
Container(
width: 280,
padding: EdgeInsets.all(10.0),
child: TextField(
controller: txttinggi,
autocorrect: true,
decoration: InputDecoration(hintText: 'Tinggi'),
)),
RaisedButton(
onPressed: getTextInputData,
color: Color(0xffFF1745),
textColor: Colors.white,
padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
child: Text('Proses'),
),
Padding(
padding: EdgeInsets.all(8.0),
child: Text("Luas Segitiga = $result",
style: TextStyle(fontSize: 20)))
],
),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment