Untitled
unknown
dart
4 years ago
3.0 kB
8
Indexable
import 'package:flutter/material.dart';
class JarakPage extends StatefulWidget {
const JarakPage({Key? key}) : super(key: key);
@override
State<JarakPage> createState() => _JarakPageState();
}
class _JarakPageState extends State<JarakPage> {
double? kecepatan;
double? waktu;
double hasil() {
double tmpHasil = 0;
if (kecepatan != null && waktu != null) {
tmpHasil = kecepatan! * waktu!;
}
return tmpHasil;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Menghitung Jarak"),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Center(
child: Text(
"s = v x t",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextFormField(
// controller: gayaController,
autofocus: true,
onChanged: (val) {
setState(() {
kecepatan = double.parse(val);
});
},
keyboardType: TextInputType.number,
decoration: const InputDecoration(
hintText: "Masukkan nilai kecepatan",
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextFormField(
// controller: percepatanController,
autofocus: true,
onChanged: (val) {
setState(() {
waktu = double.parse(val);
});
},
keyboardType: TextInputType.number,
decoration: const InputDecoration(
hintText: "Masukkan nilai kecepatan",
),
),
),
const Text(
"Hasil: ",
style: TextStyle(
fontSize: 18,
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Text(
hasil().toString(),
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
),
);
}
}
Editor is loading...