ref
This commit is contained in:
44
lib/features/home/ui/dashboard_action_card.dart
Normal file
44
lib/features/home/ui/dashboard_action_card.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
|
||||
class DashboardActionCard extends StatelessWidget {
|
||||
final String label;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const DashboardActionCard({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
// CAMBIA QUI: da Border.all a BorderSide
|
||||
side: BorderSide(
|
||||
color: context.accent.withValues(alpha: 0.1),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, color: color, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
74
lib/features/home/ui/dashboard_adaptive_grid.dart
Normal file
74
lib/features/home/ui/dashboard_adaptive_grid.dart
Normal file
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/features/home/ui/dashboard_action_card.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class DashboardAdaptiveGrid extends StatelessWidget {
|
||||
final bool isLargeScreen;
|
||||
final Function(int)? onTabRequested;
|
||||
const DashboardAdaptiveGrid({
|
||||
super.key,
|
||||
this.isLargeScreen = false,
|
||||
this.onTabRequested,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Logica Colonne: Mobile 2, Tablet 3, Desktop 4+
|
||||
int crossAxisCount = 2;
|
||||
if (constraints.maxWidth > 1000) {
|
||||
crossAxisCount = 5;
|
||||
} else if (constraints.maxWidth > 700) {
|
||||
crossAxisCount = 3;
|
||||
}
|
||||
|
||||
return GridView.count(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: crossAxisCount,
|
||||
mainAxisSpacing: 16,
|
||||
crossAxisSpacing: 16,
|
||||
childAspectRatio: isLargeScreen ? 1.3 : 1.5,
|
||||
children: [
|
||||
DashboardActionCard(
|
||||
label: 'Nuova Op',
|
||||
icon: Icons.add_task,
|
||||
color: context.accent,
|
||||
onTap: () {},
|
||||
),
|
||||
DashboardActionCard(
|
||||
label: 'Clienti',
|
||||
icon: Icons.people,
|
||||
color: Colors.orange,
|
||||
onTap: () => onTabRequested?.call(1),
|
||||
),
|
||||
DashboardActionCard(
|
||||
label: 'Prodotti',
|
||||
icon: Icons
|
||||
.phone_android_outlined, // Icona "comoda" e professionale
|
||||
color: context
|
||||
.accent, // O un colore a tua scelta, magari Indigo o Blue
|
||||
onTap: () => context.push(
|
||||
'/products',
|
||||
), // Apre la schermata sopra la Dashboard
|
||||
),
|
||||
DashboardActionCard(
|
||||
label: 'Campagne',
|
||||
icon: Icons.campaign,
|
||||
color: Colors.purple,
|
||||
onTap: () {},
|
||||
),
|
||||
DashboardActionCard(
|
||||
label: 'Report',
|
||||
icon: Icons.analytics,
|
||||
color: Colors.teal,
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
125
lib/features/home/ui/dashboard_content.dart
Normal file
125
lib/features/home/ui/dashboard_content.dart
Normal file
@@ -0,0 +1,125 @@
|
||||
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/home/ui/dashboard_adaptive_grid.dart';
|
||||
|
||||
class DashboardContent extends StatelessWidget {
|
||||
final bool isLargeScreen;
|
||||
final Function(int)? onTabRequested;
|
||||
|
||||
const DashboardContent({
|
||||
super.key,
|
||||
this.isLargeScreen = false,
|
||||
this.onTabRequested,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SessionBloc, SessionState>(
|
||||
builder: (context, state) {
|
||||
final store = state.selectedStore;
|
||||
final company = state.company;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: context.background,
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
SliverAppBar(
|
||||
expandedHeight: 100.0,
|
||||
floating: false,
|
||||
pinned: true,
|
||||
elevation: 0,
|
||||
backgroundColor: context.background,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
titlePadding: const EdgeInsets.only(left: 24, bottom: 16),
|
||||
title: Text(
|
||||
store?.nome ?? 'Dashboard',
|
||||
style: TextStyle(
|
||||
color: context.primaryText,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Center(
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 1200),
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildWelcome(context, company?.ragioneSociale),
|
||||
const SizedBox(height: 32),
|
||||
const _SectionTitle(title: 'AZIONI RAPIDE'),
|
||||
const SizedBox(height: 16),
|
||||
DashboardAdaptiveGrid(
|
||||
isLargeScreen: isLargeScreen,
|
||||
onTabRequested: onTabRequested,
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
const _SectionTitle(title: 'INFO PUNTO VENDITA'),
|
||||
const SizedBox(height: 16),
|
||||
_buildStoreCard(context, store),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildWelcome(BuildContext context, String? name) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Benvenuto in',
|
||||
style: TextStyle(color: context.secondaryText, fontSize: 16),
|
||||
),
|
||||
Text(
|
||||
name ?? 'Azienda',
|
||||
style: const TextStyle(fontSize: 28, fontWeight: FontWeight.w900),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStoreCard(BuildContext context, dynamic store) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: context.accent.withValues(alpha: 0.05),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: context.accent.withValues(alpha: 0.1)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.location_on, color: context.accent),
|
||||
const SizedBox(width: 16),
|
||||
Text('${store?.indirizzo}, ${store?.comune} (${store?.provincia})'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionTitle extends StatelessWidget {
|
||||
final String title;
|
||||
const _SectionTitle({required this.title});
|
||||
@override
|
||||
Widget build(BuildContext context) => Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: context.accent,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 12,
|
||||
letterSpacing: 1.2,
|
||||
),
|
||||
);
|
||||
}
|
||||
174
lib/features/home/ui/home_screen.dart
Normal file
174
lib/features/home/ui/home_screen.dart
Normal file
@@ -0,0 +1,174 @@
|
||||
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/anagrafiche/master_data_hub_content.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
|
||||
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: 'Operazioni',
|
||||
),
|
||||
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('Operazioni'),
|
||||
),
|
||||
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) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return DashboardContent(
|
||||
isLargeScreen: isLargeScreen,
|
||||
onTabRequested: (idx) => setState(() => _selectedIndex = 2),
|
||||
);
|
||||
case 1:
|
||||
return const Center(child: Text('Operazioni'));
|
||||
case 2:
|
||||
// L'unico punto di ingresso per tutte le anagrafiche
|
||||
return MasterDataHubContent(
|
||||
// Qui gestiamo la navigazione "interna" all'hub
|
||||
onOpenPage: (widget) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => widget),
|
||||
);
|
||||
},
|
||||
);
|
||||
default:
|
||||
return DashboardContent(isLargeScreen: isLargeScreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user