Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:fluttertoast/fluttertoast.dart';
- void main() {
- runApp(MainApp());
- }
- class MainApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- debugShowCheckedModeBanner: false,
- home: HalamanPertama(),
- );
- }
- }
- class HalamanPertama extends StatelessWidget {
- TextEditingController username = TextEditingController();
- TextEditingController password = TextEditingController();
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Halaman Satu'),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- 'Silakan login untuk mengakses halaman ini!',
- style: TextStyle(
- fontSize: 15,
- fontWeight: FontWeight.bold,
- color: Colors.blue,
- ),
- ),
- SizedBox(height: 30),
- Padding(
- padding: const EdgeInsets.fromLTRB(25, 0, 25, 10),
- child: TextField(
- controller: username,
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.person),
- labelText: 'Username',
- hintText: 'Masukkan username Anda',
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(25, 0, 25, 20),
- child: TextField(
- controller: password,
- obscureText: true,
- decoration: InputDecoration(
- prefixIcon: Icon(Icons.password),
- labelText: 'Password',
- hintText: 'Masukkan password Anda',
- border: OutlineInputBorder(),
- ),
- ),
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- ElevatedButton(
- onPressed: () {
- String uname = username.text;
- String pass = password.text;
- //logika percabangan
- if (uname == 'admin' && pass == '12345') {
- //logika login sukses
- Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => HalamanKedua(data: uname)),
- );
- Fluttertoast.showToast(
- msg: 'Login Sukses',
- toastLength: Toast.LENGTH_LONG,
- );
- } else {
- //logika login gagal
- Fluttertoast.showToast(
- msg: 'Login Gagal!! Silakan periksa kembali username dan password Anda',
- toastLength: Toast.LENGTH_LONG,
- );
- }
- },
- child: Text('LOGIN'),
- ),
- SizedBox(width: 20),
- ElevatedButton(
- onPressed: () {
- //logic ketika tombol di tekan
- username.clear();
- password.clear();
- },
- child: Text('RESET'),
- ),
- ],
- ),
- ],
- ),
- ),
- );
- }
- }
- class HalamanKedua extends StatelessWidget {
- final String data;
- //menerima data dari halaman pertama
- HalamanKedua({required this.data});
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('Halaman Dua'),
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- 'Selamat Datang ' + data,
- style: TextStyle(
- fontSize: 20,
- fontWeight: FontWeight.bold,
- color: Colors.orange,
- ),
- ),
- SizedBox(height: 35),
- ElevatedButton(
- onPressed: () {
- //logic ketika tombol di tekan
- Navigator.pop(context);
- },
- child: Text('Kembali'),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement