Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/2 Co-authored-by: Mark M2 Macbook <marco@catelli.it> Co-committed-by: Mark M2 Macbook <marco@catelli.it>
187 lines
5.8 KiB
Dart
187 lines
5.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flux/core/blocs/session/session_bloc.dart';
|
|
import 'package:flux/core/theme/theme.dart';
|
|
import 'package:flux/features/master_data/master_data_hub_content.dart';
|
|
import 'package:flux/features/services/blocs/services_cubit.dart';
|
|
import 'package:flux/features/services/ui/services_screen.dart';
|
|
import 'dashboard_content.dart'; // Importiamo il contenuto della dashboard
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
int _selectedIndex = 0;
|
|
bool _extendRailway = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Caricamento "silenzioso" all'avvio dell'app
|
|
// Usiamo WidgetsBinding per assicurarci che il contesto sia pronto
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.read<ServicesCubit>().loadServices();
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<SessionBloc, SessionState>(
|
|
builder: (context, state) {
|
|
return LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
// Se lo schermo è più largo di 900px usiamo il layout Desktop
|
|
final bool isLargeScreen = constraints.maxWidth > 900;
|
|
|
|
return Scaffold(
|
|
body: Row(
|
|
children: [
|
|
// --- SIDEBAR (Desktop) ---
|
|
if (isLargeScreen)
|
|
_buildNavigationRail(constraints.maxWidth > 1200),
|
|
|
|
// --- CONTENUTO DINAMICO ---
|
|
Expanded(
|
|
child: _buildPageContent(_selectedIndex, isLargeScreen),
|
|
),
|
|
],
|
|
),
|
|
// --- BOTTOM BAR (Solo Mobile) ---
|
|
bottomNavigationBar: isLargeScreen
|
|
? null
|
|
: _buildBottomNavigationBar(_selectedIndex),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
// --- BOTTOM NAVIGATION BAR (Mobile) ---
|
|
Widget _buildBottomNavigationBar(int selectedIndex) {
|
|
return BottomNavigationBar(
|
|
currentIndex: selectedIndex,
|
|
onTap: (index) => setState(() => _selectedIndex = index),
|
|
selectedItemColor: context.accent,
|
|
unselectedItemColor: context.secondaryText,
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.dashboard),
|
|
label: 'Dashboard',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.receipt_long),
|
|
label: 'Servizi',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.folder_shared),
|
|
label: 'Anagrafiche',
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// --- NAVIGATION RAIL (Desktop) ---
|
|
Widget _buildNavigationRail(bool veryLargeScreen) {
|
|
return MouseRegion(
|
|
onEnter: (_) => setState(() => _extendRailway = true),
|
|
onExit: (_) => setState(() => _extendRailway = false),
|
|
child: NavigationRail(
|
|
// Manteniamo 'extended' dinamico in base alla larghezza per un look Pro
|
|
extended: veryLargeScreen ? true : _extendRailway,
|
|
selectedIndex: _selectedIndex,
|
|
onDestinationSelected: (index) =>
|
|
setState(() => _selectedIndex = index),
|
|
backgroundColor: context.background,
|
|
indicatorColor: context.accent.withValues(alpha: 0.2),
|
|
|
|
// Header con il logo FLUX o l'icona bolt
|
|
leading: _buildRailHeader(veryLargeScreen),
|
|
|
|
selectedIconTheme: IconThemeData(color: context.accent, size: 28),
|
|
unselectedIconTheme: IconThemeData(
|
|
color: context.secondaryText,
|
|
size: 24,
|
|
),
|
|
|
|
selectedLabelTextStyle: TextStyle(
|
|
color: context.accent,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
unselectedLabelTextStyle: TextStyle(color: context.secondaryText),
|
|
|
|
destinations: const [
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.dashboard_outlined),
|
|
selectedIcon: Icon(Icons.dashboard),
|
|
label: Text('Dashboard'),
|
|
),
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.receipt_long_outlined),
|
|
selectedIcon: Icon(Icons.receipt_long),
|
|
label: Text('Servizi'),
|
|
),
|
|
NavigationRailDestination(
|
|
icon: Icon(Icons.folder_shared_outlined),
|
|
selectedIcon: Icon(Icons.folder_shared),
|
|
label: Text(
|
|
'Anagrafiche',
|
|
), // Questo caricherà il MasterDataHubContent
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildRailHeader(bool veryLargeScreen) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 24),
|
|
child: GestureDetector(
|
|
onTap: veryLargeScreen
|
|
? null
|
|
: () => setState(() => _extendRailway = !_extendRailway),
|
|
child: _extendRailway
|
|
? Text(
|
|
'FLUX',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 24,
|
|
color: context.accent,
|
|
),
|
|
)
|
|
: Icon(Icons.bolt, color: context.accent, size: 32),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Switch tra le sottopagine
|
|
Widget _buildPageContent(int index, bool isLargeScreen) {
|
|
return IndexedStack(
|
|
index: index,
|
|
children: [
|
|
DashboardContent(
|
|
isLargeScreen: isLargeScreen,
|
|
onTabRequested: (idx) => setState(() => _selectedIndex = 2),
|
|
),
|
|
|
|
ServicesScreen(),
|
|
|
|
// L'unico punto di ingresso per tutte le anagrafiche
|
|
MasterDataHubContent(
|
|
// Qui gestiamo la navigazione "interna" all'hub
|
|
onOpenPage: (widget) {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => widget),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|