import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:news/views/developer_page.dart';
import 'package:news/views/home_screen.dart';
import 'views/auth/signup_screen.dart';
import 'views/auth/login_screen.dart';
import 'views/splash_screen.dart';
import 'views/profile/profile_screen.dart';
import 'views/profile/edit_profile_screen.dart';
import '../repositories/auth_repository.dart';
import '../providers/auth_provider.dart';
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Article Reading App',
theme: ThemeData(primarySwatch: Colors.blue),
home: AuthGate(), // Entry point to check authentication state
routes: {
'/login': (context) => LoginScreen(),
'/signup': (context) => SignupScreen(),
'/profile': (context) => ProfileScreen(),
'/edit-profile': (context) => EditProfileScreen(),
'/home': (context) => HomeScreen(),
'/who-built-this-app': (context) => DeveloperPage(),
},
);
}
}
class AuthGate extends ConsumerStatefulWidget {
@override
_AuthGateState createState() => _AuthGateState();
}
class _AuthGateState extends ConsumerState<AuthGate> {
bool _isSplashVisible = true;
@override
void initState() {
super.initState();
// Show splash screen for 2 seconds and then load the auth state
Future.delayed(Duration(seconds: 2), () async {
await ref.read(authNotifierProvider.notifier).checkAuthStatus(); // Check auth status
setState(() {
_isSplashVisible = false;
});
});
}
@override
Widget build(BuildContext context) {
final authState = ref.watch(authNotifierProvider);
// Show splash screen while loading the authentication state
if (_isSplashVisible) {
return SplashScreen();
}```