124 lines
3.9 KiB
Dart
124 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../data/user_repository.dart';
|
|
import 'package:monitoring_jamur/core/theme/app_theme.dart';
|
|
|
|
class RegisterPage extends StatefulWidget {
|
|
const RegisterPage({super.key});
|
|
|
|
@override
|
|
State<RegisterPage> createState() => _RegisterPageState();
|
|
}
|
|
|
|
class _RegisterPageState extends State<RegisterPage> {
|
|
final _usernameController = TextEditingController();
|
|
final _passwordController = TextEditingController();
|
|
final _userRepo = UserRepository();
|
|
bool _isLoading = false;
|
|
bool _obscurePassword = true;
|
|
|
|
void _register() async {
|
|
if (_usernameController.text.isEmpty || _passwordController.text.isEmpty) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Please fill all fields')),
|
|
);
|
|
return;
|
|
}
|
|
|
|
setState(() => _isLoading = true);
|
|
final success = await _userRepo.registerUser(
|
|
_usernameController.text,
|
|
_passwordController.text,
|
|
);
|
|
setState(() => _isLoading = false);
|
|
|
|
if (success) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Registration successful! Please login.')),
|
|
);
|
|
Navigator.pop(context);
|
|
} else {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('Registration failed. Try another username.')),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppTheme.backgroundBeige,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back, color: AppTheme.primaryGreen),
|
|
onPressed: () => Navigator.pop(context),
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 0),
|
|
child: Column(
|
|
children: [
|
|
const Icon(
|
|
Icons.app_registration,
|
|
size: 60,
|
|
color: AppTheme.primaryGreen,
|
|
),
|
|
const SizedBox(height: 16),
|
|
const Text(
|
|
'Join the Lab',
|
|
style: TextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppTheme.primaryGreen,
|
|
),
|
|
),
|
|
const Text(
|
|
'Start your mushroom monitoring journey',
|
|
style: TextStyle(color: AppTheme.textLight),
|
|
),
|
|
const SizedBox(height: 40),
|
|
TextField(
|
|
controller: _usernameController,
|
|
decoration: const InputDecoration(
|
|
hintText: 'Choose Username',
|
|
prefixIcon: Icon(Icons.person_outline),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
TextField(
|
|
controller: _passwordController,
|
|
obscureText: _obscurePassword,
|
|
decoration: InputDecoration(
|
|
hintText: 'Create Password',
|
|
prefixIcon: const Icon(Icons.lock_outline),
|
|
suffixIcon: IconButton(
|
|
icon: Icon(
|
|
_obscurePassword ? Icons.visibility_off : Icons.visibility,
|
|
color: AppTheme.primaryGreen.withOpacity(0.7),
|
|
),
|
|
onPressed: () {
|
|
setState(() {
|
|
_obscurePassword = !_obscurePassword;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 40),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
onPressed: _isLoading ? null : _register,
|
|
child: _isLoading
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: const Text('REGISTER ACCOUNT'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|