초기 커밋
This commit is contained in:
221
lib/shared/widgets/app_scaffold.dart
Normal file
221
lib/shared/widgets/app_scaffold.dart
Normal file
@@ -0,0 +1,221 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../app/app_providers.dart';
|
||||
import '../../core/router/route_names.dart';
|
||||
import '../../core/utils/extensions.dart';
|
||||
import '../providers/auth_provider.dart';
|
||||
|
||||
class AppScaffold extends ConsumerWidget {
|
||||
const AppScaffold({
|
||||
required this.child,
|
||||
required this.currentPath,
|
||||
this.isAdmin = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final Widget child;
|
||||
final String currentPath;
|
||||
final bool isAdmin;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final isMobile = context.isMobile;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(isAdmin ? '관리자' : 'Flutter Frame'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.brightness_6),
|
||||
onPressed: () {
|
||||
ref.read(themeModeNotifierProvider.notifier).toggleTheme();
|
||||
},
|
||||
tooltip: '테마 전환',
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: () async {
|
||||
await ref.read(authStateProvider.notifier).logout();
|
||||
if (context.mounted) {
|
||||
context.goNamed(RouteNames.login);
|
||||
}
|
||||
},
|
||||
tooltip: '로그아웃',
|
||||
),
|
||||
],
|
||||
),
|
||||
drawer: isMobile ? _buildDrawer(context) : null,
|
||||
body: Row(
|
||||
children: [
|
||||
if (!isMobile) _buildSidebar(context),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSidebar(BuildContext context) {
|
||||
return NavigationRail(
|
||||
selectedIndex: _getSelectedIndex(),
|
||||
onDestinationSelected: (index) => _onDestinationSelected(context, index),
|
||||
labelType: NavigationRailLabelType.all,
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Icon(
|
||||
isAdmin ? Icons.admin_panel_settings : Icons.apps,
|
||||
size: 32,
|
||||
color: context.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
destinations: _getDestinations(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDrawer(BuildContext context) {
|
||||
return NavigationDrawer(
|
||||
selectedIndex: _getSelectedIndex(),
|
||||
onDestinationSelected: (index) {
|
||||
Navigator.pop(context);
|
||||
_onDestinationSelected(context, index);
|
||||
},
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(28, 16, 16, 10),
|
||||
child: Text(
|
||||
isAdmin ? '관리자 메뉴' : '메뉴',
|
||||
style: context.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
..._getDrawerDestinations(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
int _getSelectedIndex() {
|
||||
if (isAdmin) {
|
||||
if (currentPath.contains('/admin/home')) return 0;
|
||||
if (currentPath.contains('/admin/users')) return 1;
|
||||
if (currentPath.contains('/admin/dashboard')) return 2;
|
||||
if (currentPath.contains('/admin/settings')) return 3;
|
||||
} else {
|
||||
if (currentPath.contains('/user/home')) return 0;
|
||||
if (currentPath.contains('/user/profile')) return 1;
|
||||
if (currentPath.contains('/user/dashboard')) return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _onDestinationSelected(BuildContext context, int index) {
|
||||
if (isAdmin) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
context.goNamed(RouteNames.adminHome);
|
||||
case 1:
|
||||
context.goNamed(RouteNames.adminUsers);
|
||||
case 2:
|
||||
context.goNamed(RouteNames.adminDashboard);
|
||||
case 3:
|
||||
context.goNamed(RouteNames.adminSettings);
|
||||
}
|
||||
} else {
|
||||
switch (index) {
|
||||
case 0:
|
||||
context.goNamed(RouteNames.userHome);
|
||||
case 1:
|
||||
context.goNamed(RouteNames.userProfile);
|
||||
case 2:
|
||||
context.goNamed(RouteNames.userDashboard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<NavigationRailDestination> _getDestinations() {
|
||||
if (isAdmin) {
|
||||
return const [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
selectedIcon: Icon(Icons.home),
|
||||
label: Text('홈'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.people_outlined),
|
||||
selectedIcon: Icon(Icons.people),
|
||||
label: Text('사용자 관리'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
selectedIcon: Icon(Icons.dashboard),
|
||||
label: Text('대시보드'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
selectedIcon: Icon(Icons.settings),
|
||||
label: Text('설정'),
|
||||
),
|
||||
];
|
||||
}
|
||||
return const [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
selectedIcon: Icon(Icons.home),
|
||||
label: Text('홈'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.person_outlined),
|
||||
selectedIcon: Icon(Icons.person),
|
||||
label: Text('프로필'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
selectedIcon: Icon(Icons.dashboard),
|
||||
label: Text('대시보드'),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
List<NavigationDrawerDestination> _getDrawerDestinations() {
|
||||
if (isAdmin) {
|
||||
return const [
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
selectedIcon: Icon(Icons.home),
|
||||
label: Text('홈'),
|
||||
),
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.people_outlined),
|
||||
selectedIcon: Icon(Icons.people),
|
||||
label: Text('사용자 관리'),
|
||||
),
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
selectedIcon: Icon(Icons.dashboard),
|
||||
label: Text('대시보드'),
|
||||
),
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
selectedIcon: Icon(Icons.settings),
|
||||
label: Text('설정'),
|
||||
),
|
||||
];
|
||||
}
|
||||
return const [
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
selectedIcon: Icon(Icons.home),
|
||||
label: Text('홈'),
|
||||
),
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.person_outlined),
|
||||
selectedIcon: Icon(Icons.person),
|
||||
label: Text('프로필'),
|
||||
),
|
||||
NavigationDrawerDestination(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
selectedIcon: Icon(Icons.dashboard),
|
||||
label: Text('대시보드'),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user