#first commit

This commit is contained in:
cc
2026-01-11 19:42:22 +08:00
commit f70d6cace6
167 changed files with 6699 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import 'package:go_router/go_router.dart';
import 'package:maibu_satabot_v2/core/router/route_paths.dart';
import '../../features/auth/presentation/bloc/auth_cubit.dart';
import '../../features/auth/presentation/bloc/auth_state.dart';
import '../../features/auth/presentation/pages/login_page.dart';
import '../../features/home/presentation/pages/home_page.dart';
import '../../features/register/presentation/pages/register_page.dart';
import 'go_router_refresh_stream.dart';
GoRouter createRouter(AuthCubit authCubit) {
return GoRouter(
initialLocation: RoutePaths.login,
refreshListenable: GoRouterRefreshStream(authCubit.stream),
redirect: (context, state) {
final loggedIn = authCubit.state is AuthAuthenticated;
final loggingIn = state.matchedLocation == RoutePaths.login;
if (!loggedIn && !loggingIn) {
return RoutePaths.login;
}
if (loggedIn && loggingIn) {
return RoutePaths.home;
}
return null;
},
routes: [
GoRoute(path: RoutePaths.login, builder: (_, __) => LoginPage()),
GoRoute(path: RoutePaths.register, builder: (_, __) => RegisterPage()),
GoRoute(path: RoutePaths.home, builder: (context, state) => HomePage()),
],
);
}

View File

@@ -0,0 +1,19 @@
import 'dart:async';
import 'package:flutter/material.dart';
class GoRouterRefreshStream extends ChangeNotifier {
late final StreamSubscription _subscription;
GoRouterRefreshStream(Stream<dynamic> stream) {
_subscription = stream.listen((_) {
notifyListeners();
});
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
}

View File

@@ -0,0 +1,5 @@
class RoutePaths {
static const login = '/auth';
static const register = '/register';
static const home = '/home';
}