This commit is contained in:
Phuoc Nguyen
2025-10-10 17:36:10 +07:00
parent 04f7042b8d
commit bdaf0b96c5
82 changed files with 4753 additions and 329 deletions

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'core/theme/app_theme.dart';
import 'features/auth/presentation/presentation.dart';
import 'features/home/presentation/pages/home_page.dart';
import 'features/products/presentation/pages/products_page.dart';
import 'features/categories/presentation/pages/categories_page.dart';
@@ -8,7 +9,7 @@ import 'features/settings/presentation/pages/settings_page.dart';
import 'features/settings/presentation/providers/theme_provider.dart';
import 'shared/widgets/app_bottom_nav.dart';
/// Root application widget
/// Root application widget with authentication wrapper
class RetailApp extends ConsumerStatefulWidget {
const RetailApp({super.key});
@@ -17,14 +18,14 @@ class RetailApp extends ConsumerStatefulWidget {
}
class _RetailAppState extends ConsumerState<RetailApp> {
int _currentIndex = 0;
final List<Widget> _pages = const [
HomePage(),
ProductsPage(),
CategoriesPage(),
SettingsPage(),
];
@override
void initState() {
super.initState();
// Initialize auth state on app start
WidgetsBinding.instance.addPostFrameCallback((_) {
ref.read(authProvider.notifier).initialize();
});
}
@override
Widget build(BuildContext context) {
@@ -36,19 +37,46 @@ class _RetailAppState extends ConsumerState<RetailApp> {
theme: AppTheme.lightTheme(),
darkTheme: AppTheme.darkTheme(),
themeMode: themeMode,
home: Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _pages,
),
bottomNavigationBar: AppBottomNav(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
// Wrap the home with AuthWrapper to require login
home: const AuthWrapper(
child: MainScreen(),
),
);
}
}
/// Main screen with bottom navigation (only accessible after login)
class MainScreen extends ConsumerStatefulWidget {
const MainScreen({super.key});
@override
ConsumerState<MainScreen> createState() => _MainScreenState();
}
class _MainScreenState extends ConsumerState<MainScreen> {
int _currentIndex = 0;
final List<Widget> _pages = const [
HomePage(),
ProductsPage(),
CategoriesPage(),
SettingsPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _pages,
),
bottomNavigationBar: AppBottomNav(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
),
);
}