Untitled

mail@pastecode.io avatar
unknown
dart
2 years ago
2.4 kB
2
Indexable
Never
import 'package:flutter/material.dart';

class UangPage extends StatefulWidget {
  const UangPage({Key? key}) : super(key: key);

  @override
  State<UangPage> createState() => _UangPageState();
}

class _UangPageState extends State<UangPage> {
  double dollar = 0;

  double hasil() {
    return 14366.75 * dollar;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("Menghitung Konversi Uang"),
        ),
        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(
                      "Menghitung konversi Dollar > Rupiah",
                      style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 10.0),
                  child: TextFormField(
                    // controller: gayaController,
                    autofocus: true,
                    onChanged: (val) {
                      setState(() {
                        dollar = double.parse(val);
                      });
                    },
                    keyboardType: TextInputType.number,
                    decoration: const InputDecoration(
                      hintText: "Masukkan nilai dollar",
                    ),
                  ),
                ),
                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,
                    ),
                  ),
                ),
              ],
            ),
          ),
        ));
  }
}