From f33e2202718ced6cbe20ee25cb36a26fb13a5f17 Mon Sep 17 00:00:00 2001 From: Dwikyyy Date: Thu, 30 Jul 2026 12:52:52 +0700 Subject: [PATCH] Upload files to "Source Code Mobile" --- Source Code Mobile/register_page.dart | 158 ++++++++++++++++++++++++++ Source Code Mobile/splash_page.dart | 78 +++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 Source Code Mobile/register_page.dart create mode 100644 Source Code Mobile/splash_page.dart diff --git a/Source Code Mobile/register_page.dart b/Source Code Mobile/register_page.dart new file mode 100644 index 0000000..aa337e8 --- /dev/null +++ b/Source Code Mobile/register_page.dart @@ -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 createState() => _RegisterPageState(); +} + +class _RegisterPageState extends State { + final _formKey = GlobalKey(); + + final _nameController = TextEditingController(); + + final _emailController = TextEditingController(); + + final _passwordController = TextEditingController(); + + final _confirmController = TextEditingController(); + + Future register() async { + if (!_formKey.currentState!.validate()) { + return; + } + + final auth = context.read(); + + 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(); + + 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'), + ), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/Source Code Mobile/splash_page.dart b/Source Code Mobile/splash_page.dart new file mode 100644 index 0000000..13d4145 --- /dev/null +++ b/Source Code Mobile/splash_page.dart @@ -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 createState() => _SplashPageState(); +} + +class _SplashPageState extends State { + @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), + ], + ), + ), + ); + } +}