Upload files to "Source Code Mobile"

This commit is contained in:
Dwikyyy 2026-07-30 12:52:52 +07:00
parent 7fc2e49904
commit f33e220271
2 changed files with 236 additions and 0 deletions

View File

@ -0,0 +1,158 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
import 'dashboard_page.dart';
class RegisterPage extends StatefulWidget {
const RegisterPage({super.key});
@override
State<RegisterPage> createState() => _RegisterPageState();
}
class _RegisterPageState extends State<RegisterPage> {
final _formKey = GlobalKey<FormState>();
final _nameController = TextEditingController();
final _emailController = TextEditingController();
final _passwordController = TextEditingController();
final _confirmController = TextEditingController();
Future<void> register() async {
if (!_formKey.currentState!.validate()) {
return;
}
final auth = context.read<AuthProvider>();
final result = await auth.register(
name: _nameController.text.trim(),
email: _emailController.text.trim(),
password: _passwordController.text,
);
if (!mounted) return;
if (result == null) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (_) => const DashboardPage()),
(route) => false,
);
} else {
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(result)));
}
}
@override
void dispose() {
_nameController.dispose();
_emailController.dispose();
_passwordController.dispose();
_confirmController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final auth = context.watch<AuthProvider>();
return Scaffold(
appBar: AppBar(title: const Text('Register')),
body: SafeArea(
child: SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
controller: _nameController,
decoration: const InputDecoration(
labelText: 'Nama',
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Nama wajib diisi';
}
return null;
},
),
const SizedBox(height: 20),
TextFormField(
controller: _emailController,
decoration: const InputDecoration(
labelText: 'Email',
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Email wajib diisi';
}
return null;
},
),
const SizedBox(height: 20),
TextFormField(
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
validator: (value) {
if (value == null || value.length < 6) {
return 'Password minimal 6 karakter';
}
return null;
},
),
const SizedBox(height: 20),
TextFormField(
controller: _confirmController,
obscureText: true,
decoration: const InputDecoration(
labelText: 'Konfirmasi Password',
border: OutlineInputBorder(),
),
validator: (value) {
if (value != _passwordController.text) {
return 'Password tidak sama';
}
return null;
},
),
const SizedBox(height: 30),
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: auth.isLoading ? null : register,
child: auth.isLoading
? const CircularProgressIndicator()
: const Text('Register'),
),
),
],
),
),
),
),
);
}
}

View File

@ -0,0 +1,78 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import '../screens/login_page.dart';
import '../screens/dashboard_page.dart';
class SplashPage extends StatefulWidget {
const SplashPage({super.key});
@override
State<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
_checkLogin();
}
void _checkLogin() {
Timer(const Duration(seconds: 2), () {
final user = FirebaseAuth.instance.currentUser;
if (user != null) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const DashboardPage()),
);
} else {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (_) => const LoginPage()),
);
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.green,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.air, size: 100, color: Colors.white),
const SizedBox(height: 20),
const Text(
'Smart Air Quality',
style: TextStyle(
color: Colors.white,
fontSize: 26,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
const Text(
'Monitoring Kualitas Udara',
style: TextStyle(color: Colors.white70, fontSize: 14),
),
const SizedBox(height: 50),
const CircularProgressIndicator(color: Colors.white),
],
),
),
);
}
}