import 'dart:async'; import 'package:flutter/material.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; import 'login_screen.dart'; import 'register_screen.dart'; class AuthScreen extends StatefulWidget { const AuthScreen({super.key}); @override State createState() => _AuthScreenState(); } class _AuthScreenState extends State with SingleTickerProviderStateMixin { final SupabaseClient supabase = Supabase.instance.client; late TabController _tabController; @override void initState() { super.initState(); _tabController = TabController(length: 2, vsync: this); _setupAuthListener(); } @override void dispose() { _tabController.dispose(); super.dispose(); } void _setupAuthListener() { supabase.auth.onAuthStateChange.listen((data) { final event = data.event; if (event == AuthChangeEvent.signedIn) { Navigator.of(context).pushReplacement( MaterialPageRoute( builder: (context) => const Scaffold( body: Center( child: Text('Signed in'), ), ), ), ); } }); } Future _googleSignIn() async { /// TODO: update the Web client ID with your own. /// /// Web Client ID that you registered with Google Cloud. const webClientId = '311478513323-n2qut52hb4ms7g6g6r5ukni4mr49p6ff.apps.googleusercontent.com'; /// TODO: update the iOS client ID with your own. /// /// iOS Client ID that you registered with Google Cloud. const iosClientId = '311478513323-8j9q5oe77hnmcmn7i6qsq5r7t0krrlb1.apps.googleusercontent.com'; // Google sign in on Android will work without providing the Android // Client ID registered on Google Cloud. final GoogleSignIn signIn = GoogleSignIn( clientId: iosClientId, serverClientId: webClientId, ); final googleUser = await signIn.signIn(); final googleAuth = await googleUser!.authentication; final accessToken = googleAuth.accessToken; final idToken = googleAuth.idToken; if(accessToken == null){ throw Exception('No access token found'); } if(idToken == null){ throw Exception('No id token found'); } return supabase.auth.signInWithIdToken( provider: OAuthProvider.google, idToken: idToken, accessToken: accessToken, ); } Future login(String email, String password) async { } Future register(String email, String password, String name) async { } Future logout() async { } Future oAuthLogin() async { await _googleSignIn(); } bool isLogged= false; @override Widget build(BuildContext context) { final screenHeight = MediaQuery.of(context).size.height; // If user is logged in, show logout screen if (isLogged) { return Scaffold( backgroundColor: Colors.grey[50], body: SafeArea( child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( width: 80, height: 80, decoration: BoxDecoration( color: Theme.of(context).primaryColor, borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Theme.of(context).primaryColor.withValues(alpha: 0.3), blurRadius: 20, offset: const Offset(0, 10), ), ], ), child: const Icon( Icons.task_alt, color: Colors.white, size: 40, ), ), const SizedBox(height: 24), Text( 'Welcome back!', style: GoogleFonts.poppins( fontSize: 28, fontWeight: FontWeight.bold, color: Colors.grey[800], ), ), const SizedBox(height: 8), Text( "username", style: GoogleFonts.poppins( fontSize: 20, fontWeight: FontWeight.w600, color: Theme.of(context).primaryColor, ), ), const SizedBox(height: 4), Text( "email or id", style: GoogleFonts.poppins( fontSize: 16, color: Colors.grey[600], ), ), const SizedBox(height: 40), ElevatedButton( onPressed: logout, style: ElevatedButton.styleFrom( backgroundColor: Colors.red, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), elevation: 2, ), child: Text( 'Logout', style: GoogleFonts.poppins( fontSize: 16, fontWeight: FontWeight.w600, ), ), ), ], ), ), ), ); } return Scaffold( backgroundColor: Colors.grey[50], body: SafeArea( child: SingleChildScrollView( child: Column( children: [ // Header Section Container( width: double.infinity, padding: const EdgeInsets.all(32.0), child: Column( children: [ const SizedBox(height: 40), // App Logo/Icon Container( width: 80, height: 80, decoration: BoxDecoration( color: Theme.of(context).primaryColor, borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Theme.of(context).primaryColor.withValues(alpha: 0.3), blurRadius: 20, offset: const Offset(0, 10), ), ], ), child: const Icon( Icons.task_alt, color: Colors.white, size: 40, ), ), const SizedBox(height: 24), Text( 'TaskTracker', style: GoogleFonts.poppins( fontSize: 32, fontWeight: FontWeight.bold, color: Colors.grey[800], ), ), const SizedBox(height: 8), Text( 'Manage your tasks efficiently', style: GoogleFonts.poppins( fontSize: 16, color: Colors.grey[600], ), ), ], ), ), // Tab Bar Container( margin: const EdgeInsets.symmetric(horizontal: 24), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.grey.withValues(alpha: 0.1), blurRadius: 10, offset: const Offset(0, 5), ), ], ), child: TabBar( controller: _tabController, indicator: BoxDecoration( borderRadius: BorderRadius.circular(20), color: Theme.of(context).primaryColor, ), indicatorSize: TabBarIndicatorSize.tab, // Make indicator fill the tab labelColor: Colors.white, unselectedLabelColor: Colors.grey[600], labelStyle: GoogleFonts.poppins( fontWeight: FontWeight.w600, fontSize: 16, ), unselectedLabelStyle: GoogleFonts.poppins( fontWeight: FontWeight.w500, fontSize: 16, ), tabs: const [ Tab(text: 'Login'), Tab(text: 'Register'), ], ), ), const SizedBox(height: 24), // Tab Views SizedBox( height: screenHeight * 0.8, child: TabBarView( controller: _tabController, children: [ LoginScreen( onLogin: login, onOAuthLogin: () => oAuthLogin(), ), RegisterScreen( onRegister: register, onOAuthRegister: () => oAuthLogin(), ), ], ), ), ], ), ), ), ); } }