163 lines
5.7 KiB
Dart
163 lines
5.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'home_page.dart';
|
|
import 'admin_dashboard.dart';
|
|
|
|
class LoginPage extends StatefulWidget {
|
|
const LoginPage({super.key});
|
|
|
|
@override
|
|
State<LoginPage> createState() => _LoginPageState();
|
|
}
|
|
|
|
class _LoginPageState extends State<LoginPage> {
|
|
final _usernameController = TextEditingController();
|
|
final _passwordController = TextEditingController();
|
|
String _role = 'user';
|
|
|
|
void _login() {
|
|
final username = _usernameController.text.trim();
|
|
final password = _passwordController.text.trim();
|
|
|
|
if (_role == 'admin' && username == 'admin' && password == 'admin123') {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (_) => const AdminDashboard()),
|
|
);
|
|
} else if (_role == 'user' && username.isNotEmpty && password.isNotEmpty) {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => HomePage(username: username, isGuest: false),
|
|
),
|
|
);
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Username atau password salah!')),
|
|
);
|
|
}
|
|
}
|
|
|
|
void _guestMode() {
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => const HomePage(username: 'Tamu', isGuest: true),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(24),
|
|
child: Container(
|
|
constraints: const BoxConstraints(maxWidth: 400),
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFF1F2937),
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFF374151)),
|
|
),
|
|
padding: const EdgeInsets.all(32),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.movie, size: 64, color: Color(0xFFFBBF24)),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'CineSim',
|
|
style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold),
|
|
),
|
|
const SizedBox(height: 8),
|
|
const Text(
|
|
'Simulasi Pemesanan Tiket Bioskop',
|
|
style: TextStyle(color: Colors.grey),
|
|
),
|
|
const SizedBox(height: 32),
|
|
DropdownButtonFormField<String>(
|
|
value: _role,
|
|
decoration: InputDecoration(
|
|
labelText: 'Role',
|
|
filled: true,
|
|
fillColor: const Color(0xFF374151),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
items: const [
|
|
DropdownMenuItem(value: 'user', child: Text('User')),
|
|
DropdownMenuItem(value: 'admin', child: Text('Admin')),
|
|
],
|
|
onChanged: (value) => setState(() => _role = value!),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _usernameController,
|
|
decoration: InputDecoration(
|
|
labelText: 'Username',
|
|
hintText: _role == 'admin' ? 'admin' : 'Masukkan username',
|
|
filled: true,
|
|
fillColor: const Color(0xFF374151),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _passwordController,
|
|
obscureText: true,
|
|
decoration: InputDecoration(
|
|
labelText: 'Password',
|
|
hintText:
|
|
_role == 'admin' ? 'admin123' : 'Masukkan password',
|
|
filled: true,
|
|
fillColor: const Color(0xFF374151),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 24),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
onPressed: _login,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: const Color(0xFFFBBF24),
|
|
foregroundColor: Colors.black,
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
child: const Text(
|
|
'Login',
|
|
style: TextStyle(fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton(
|
|
onPressed: _guestMode,
|
|
style: OutlinedButton.styleFrom(
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
side: const BorderSide(color: Color(0xFF374151)),
|
|
),
|
|
child: const Text('Lanjutkan sebagai Tamu'),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Admin: admin / admin123',
|
|
style: TextStyle(fontSize: 12, color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|