Skip to content

Instantly share code, notes, and snippets.

@triyono777
Created April 18, 2022 04:35
Show Gist options
  • Save triyono777/923838302e5c4da954569079479793db to your computer and use it in GitHub Desktop.
Save triyono777/923838302e5c4da954569079479793db to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:projek_kel_1/home_screen.dart';
import 'package:projek_kel_1/list_screen.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key);
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
TextEditingController userNameController = TextEditingController();
TextEditingController passwordController = TextEditingController();
bool hidePass = true;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Column(
children: [
Text('Login',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30)),
Expanded(
child: Image.asset(
'assets/images/undraw_Specs_re_546x.png',
height: 1000,
)),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 10),
child: TextFormField(
controller: userNameController,
decoration: InputDecoration(
label: Text('Username'),
hintText: 'Masukkan username',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 10),
child: TextFormField(
controller: passwordController,
obscureText: hidePass,
decoration: InputDecoration(
label: Text('Password'),
hintText: 'Masukkan password',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
suffixIcon: IconButton(
onPressed: () {
print('hide pass = $hidePass');
setState(() {
hidePass = !hidePass;
});
},
icon:
Icon(hidePass ? Icons.visibility : Icons.visibility_off),
),
),
),
),
SizedBox(
width: 250,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
),
onPressed: () {
if (userNameController.text == 'budi' &&
passwordController.text == "123") {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('berhasil login'),
),
);
var box = Hive.box('userBox');
box.put('isLogin',true);
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (_) => HomeScreen()),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('username atau password salah'),
),
);
}
},
child: Text('Login'),
),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment