feat: add home and profile screens
This commit is contained in:
29
lib/app.dart
29
lib/app.dart
@@ -3,16 +3,43 @@ import 'package:go_router/go_router.dart';
|
||||
import 'package:phone_login/auth/auth_state.dart';
|
||||
import 'package:phone_login/auth/phone_input_screen.dart';
|
||||
import 'package:phone_login/auth/sms_verification_screen.dart';
|
||||
import 'package:phone_login/home/home_screen.dart';
|
||||
import 'package:phone_login/profile/profile_screen.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
final _router = GoRouter(
|
||||
routes: [
|
||||
GoRoute(path: '/', builder: (context, state) => const PhoneInputScreen()),
|
||||
GoRoute(path: '/', builder: (context, state) => const HomeScreen()),
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
builder: (context, state) => const PhoneInputScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/sms_verify',
|
||||
builder: (context, state) => const SmsVerificationScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/profile',
|
||||
builder: (context, state) => const ProfileScreen(),
|
||||
),
|
||||
],
|
||||
redirect: (BuildContext context, GoRouterState state) {
|
||||
final authState = Provider.of<AuthState>(context, listen: false);
|
||||
final bool loggedIn = authState.isLoggedIn;
|
||||
final bool loggingIn =
|
||||
state.matchedLocation == '/login' ||
|
||||
state.matchedLocation == '/sms_verify';
|
||||
|
||||
if (!loggedIn && !loggingIn) {
|
||||
return '/login';
|
||||
}
|
||||
|
||||
if (loggedIn && loggingIn) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
class App extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user