Advertisement
BlackBoY_

login_page.dart

Jun 19th, 2022
1,325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 2.78 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:praktikum_pertemuan_10/home_page.dart';
  3.  
  4. class LoginPage extends StatefulWidget {
  5.   @override
  6.   State<LoginPage> createState() => _LoginPageState();
  7. }
  8.  
  9. class _LoginPageState extends State<LoginPage> {
  10.   String _email = "temp";
  11.   String _password = "temp";
  12.   String _errorMessage = "Email atau Password Salah";
  13.  
  14.   @override
  15.   Widget build(BuildContext context) {
  16.     return Scaffold(
  17.       appBar: AppBar(
  18.         title: Text("Login Page"),
  19.       ),
  20.       body: SingleChildScrollView(
  21.         child: Column(children: [
  22.           Center(
  23.             child: Container(
  24.               padding: EdgeInsets.only(top: 40),
  25.               height: 190,
  26.               width: 230,
  27.               child: Image.asset('assets/img/powerrenjes.png'),
  28.             ),
  29.           ),
  30.           Padding(
  31.             padding: const EdgeInsets.all(8.0),
  32.             child: TextField(
  33.               decoration: InputDecoration(
  34.                 border: OutlineInputBorder(),
  35.                 labelText: 'Email',
  36.                 hintText: 'Masukkan Alamat Email',
  37.               ),
  38.               onChanged: (text) {
  39.                 _email = text;
  40.               },
  41.             ),
  42.           ),
  43.           Padding(
  44.             padding: const EdgeInsets.all(8.0),
  45.             child: TextField(
  46.               obscureText: true,
  47.               decoration: InputDecoration(
  48.                 border: OutlineInputBorder(),
  49.                 labelText: 'Password',
  50.                 hintText: 'Masukkan Passsword',
  51.               ),
  52.               onChanged: (text) {
  53.                 _password = text;
  54.               },
  55.             ),
  56.           ),
  57.           Padding(
  58.             padding: const EdgeInsets.all(10),
  59.             child: Text(
  60.               _errorMessage,
  61.               style: TextStyle(color: Colors.red),
  62.             ),
  63.           ),
  64.           Container(
  65.             height: 50,
  66.             width: 250,
  67.             decoration: BoxDecoration(
  68.                 color: Colors.blue, borderRadius: BorderRadius.circular(20)),
  69.             child: TextButton(
  70.               onPressed: () {
  71.                 setState(() {
  72.                   if (_email == "anjay" && _password == "anjay") {
  73.                     _errorMessage = "";
  74.                     Navigator.pushReplacement(context,
  75.                         MaterialPageRoute(builder: (context) => HomePage()));
  76.                   } else {
  77.                     _errorMessage =
  78.                         "Email dan Password yang anda masukkan salah!!!";
  79.                   }
  80.                 });
  81.               },
  82.               child: Text(
  83.                 "Login",
  84.                 style: TextStyle(color: Colors.white, fontSize: 20),
  85.               ),
  86.             ),
  87.           )
  88.         ]),
  89.       ),
  90.     );
  91.   }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement