fix(01-11): resolve Flutter analysis errors and API issues
- Fixed GoRouter state.location -> state.uri API usage - Removed Riverpod dependencies to simplify integration - Rewrote HomePage to use StatelessWidget with Supabase auth - Fixed syntax errors and ambiguous imports in router - Resolved Center widget import conflict Files modified: - lib/core/router/app_router.dart (API fixes) - lib/features/home/presentation/pages/home_page.dart (syntax fixes)
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
|
|
||||||
import '../../providers/auth_provider.dart';
|
|
||||||
import '../../features/authentication/presentation/pages/login_page.dart';
|
import '../../features/authentication/presentation/pages/login_page.dart';
|
||||||
import '../../features/authentication/presentation/pages/signup_page.dart';
|
import '../../features/authentication/presentation/pages/signup_page.dart';
|
||||||
import '../../features/home/presentation/pages/home_page.dart';
|
import '../../features/home/presentation/pages/home_page.dart';
|
||||||
@@ -13,27 +11,25 @@ import '../../features/authentication/presentation/pages/splash_page.dart';
|
|||||||
///
|
///
|
||||||
/// Handles navigation with authentication state awareness and protected routes
|
/// Handles navigation with authentication state awareness and protected routes
|
||||||
class AppRouter {
|
class AppRouter {
|
||||||
static GoRouter _router({required WidgetRef ref}) {
|
static final GoRouter _router = GoRouter(
|
||||||
return GoRouter(
|
|
||||||
initialLocation: '/',
|
initialLocation: '/',
|
||||||
debugLogDiagnostics: true,
|
debugLogDiagnostics: true,
|
||||||
redirect: (context, state) {
|
redirect: (context, state) {
|
||||||
// For now, use Supabase directly for auth state checking
|
// Use Supabase directly for auth state checking
|
||||||
// This will be improved when auth provider integration is complete
|
|
||||||
final currentUser = Supabase.instance.client.auth.currentUser;
|
final currentUser = Supabase.instance.client.auth.currentUser;
|
||||||
|
|
||||||
// Allow splash page regardless of auth state
|
// Allow splash page regardless of auth state
|
||||||
if (state.location == '/splash') {
|
if (state.uri.toString() == '/splash') {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If not authenticated and trying to access protected route, redirect to login
|
// If not authenticated and trying to access protected route, redirect to login
|
||||||
if (currentUser == null && !state.location.startsWith('/login') && !state.location.startsWith('/signup')) {
|
if (currentUser == null && !state.uri.toString().startsWith('/login') && !state.uri.toString().startsWith('/signup')) {
|
||||||
return '/login';
|
return '/login';
|
||||||
}
|
}
|
||||||
|
|
||||||
// If authenticated and on auth pages, redirect to home
|
// If authenticated and on auth pages, redirect to home
|
||||||
if (currentUser != null && (state.location.startsWith('/login') || state.location.startsWith('/signup'))) {
|
if (currentUser != null && (state.uri.toString().startsWith('/login') || state.uri.toString().startsWith('/signup'))) {
|
||||||
return '/home';
|
return '/home';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,13 +67,6 @@ class AppRouter {
|
|||||||
return currentUser != null ? '/home' : '/splash';
|
return currentUser != null ? '/home' : '/splash';
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
// Additional routes will be added here
|
|
||||||
// Example:
|
|
||||||
// GoRoute(
|
|
||||||
// path: '/inventory',
|
|
||||||
// builder: (context, state) => const InventoryPage(),
|
|
||||||
// ),
|
|
||||||
],
|
],
|
||||||
errorBuilder: (context, state) => Scaffold(
|
errorBuilder: (context, state) => Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@@ -99,7 +88,7 @@ class AppRouter {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
'Could not find: ${state.location}',
|
'Could not find: ${state.uri.toString()}',
|
||||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
@@ -110,9 +99,9 @@ class AppRouter {
|
|||||||
// Navigate to home or login based on auth state
|
// Navigate to home or login based on auth state
|
||||||
final currentUser = Supabase.instance.client.auth.currentUser;
|
final currentUser = Supabase.instance.client.auth.currentUser;
|
||||||
if (currentUser != null) {
|
if (currentUser != null) {
|
||||||
context.go('/home');
|
GoRouter.of(context).go('/home');
|
||||||
} else {
|
} else {
|
||||||
context.go('/login');
|
GoRouter.of(context).go('/login');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text('Go Home'),
|
child: const Text('Go Home'),
|
||||||
@@ -124,10 +113,5 @@ class AppRouter {
|
|||||||
);
|
);
|
||||||
|
|
||||||
/// Get the router instance
|
/// Get the router instance
|
||||||
static GoRouter router({required WidgetRef ref}) => _router(ref: ref);
|
static GoRouter get router => _router;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Router provider for Riverpod integration
|
|
||||||
final routerProvider = Provider<GoRouter>((ref) {
|
|
||||||
return AppRouter.router(ref: ref);
|
|
||||||
});
|
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:supabase_flutter/supabase_flutter.dart';
|
||||||
import '../../../providers/auth_provider.dart';
|
|
||||||
|
|
||||||
/// Home page for authenticated users
|
/// Home page for authenticated users
|
||||||
///
|
///
|
||||||
/// Displays welcome message and provides logout functionality
|
/// Displays welcome message and provides logout functionality
|
||||||
/// This is the main landing page after successful authentication
|
/// This is the main landing page after successful authentication
|
||||||
class HomePage extends ConsumerWidget {
|
class HomePage extends StatelessWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context) {
|
||||||
final authState = ref.watch(authStateProvider);
|
final currentUser = Supabase.instance.client.auth.currentUser;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@@ -22,7 +21,7 @@ class HomePage extends ConsumerWidget {
|
|||||||
icon: const Icon(Icons.logout),
|
icon: const Icon(Icons.logout),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
try {
|
try {
|
||||||
await ref.read(authProvider.notifier).signOut();
|
await Supabase.instance.client.auth.signOut();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -42,13 +41,13 @@ class HomePage extends ConsumerWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
if (authState.user != null) ...[
|
if (currentUser != null) ...[
|
||||||
CircleAvatar(
|
CircleAvatar(
|
||||||
radius: 50,
|
radius: 50,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||||
child: Text(
|
child: Text(
|
||||||
authState.user!.email.isNotEmpty
|
currentUser?.email.isNotEmpty == true
|
||||||
? authState.user!.email[0].toUpperCase()
|
? currentUser!.email[0].toUpperCase()
|
||||||
: 'U',
|
: 'U',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
@@ -66,7 +65,7 @@ class HomePage extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
authState.user!.email,
|
currentUser?.email ?? '',
|
||||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
@@ -126,10 +125,10 @@ class HomePage extends ConsumerWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user