feat(apps): add router auth protection

This commit is contained in:
qzl
2026-02-25 15:25:31 +08:00
parent 8c1dfa9987
commit d3bdb3ab4f
4 changed files with 180 additions and 87 deletions
+24 -9
View File
@@ -1,21 +1,36 @@
import 'package:flutter/material.dart';
import 'core/theme/app_theme.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'core/di/injection.dart';
import 'core/router/app_router.dart';
import 'core/theme/app_theme.dart';
import 'features/auth/presentation/bloc/auth_bloc.dart';
import 'features/auth/presentation/bloc/auth_event.dart';
void main() {
runApp(const LinksyApp());
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await configureDependencies();
final authBloc = sl<AuthBloc>();
authBloc.add(AuthStarted());
runApp(LinksyApp(authBloc: authBloc));
}
class LinksyApp extends StatelessWidget {
const LinksyApp({super.key});
final AuthBloc authBloc;
const LinksyApp({super.key, required this.authBloc});
@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: 'Linksy',
debugShowCheckedModeBanner: false,
theme: AppTheme.light,
routerConfig: appRouter,
return BlocProvider<AuthBloc>.value(
value: authBloc,
child: MaterialApp.router(
title: 'Linksy',
debugShowCheckedModeBanner: false,
theme: AppTheme.light,
routerConfig: createAppRouter(authBloc),
),
);
}
}