m
This commit is contained in:
@@ -2,8 +2,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||||
import 'package:flux/features/auth/ui/auth_screen.dart';
|
import 'package:flux/features/auth/ui/auth_screen.dart';
|
||||||
import 'package:flux/features/company/ui/create_company_screen.dart';
|
import 'package:flux/features/company/ui/create_company_screen.dart';
|
||||||
import 'package:flux/features/dashboard/ui/dashboard_screen.dart';
|
import 'package:flux/features/home/ui/dashboard_content.dart';
|
||||||
import 'package:flux/features/store/ui/create_store_screen.dart';
|
import 'package:flux/features/store/ui/create_store_screen.dart';
|
||||||
|
import 'package:flux/ui/home_screen.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
@@ -33,8 +34,9 @@ class AppRouter {
|
|||||||
|
|
||||||
if (isUnauthenticated && location != '/login') return '/login';
|
if (isUnauthenticated && location != '/login') return '/login';
|
||||||
|
|
||||||
if (isNoCompany && location != '/create-company')
|
if (isNoCompany && location != '/create-company') {
|
||||||
return '/create-company';
|
return '/create-company';
|
||||||
|
}
|
||||||
|
|
||||||
if (isNoStore && location != '/create-store') return '/create-store';
|
if (isNoStore && location != '/create-store') return '/create-store';
|
||||||
|
|
||||||
@@ -44,10 +46,7 @@ class AppRouter {
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(path: '/', builder: (context, state) => const HomeScreen()),
|
||||||
path: '/',
|
|
||||||
builder: (context, state) => const DashboardScreen(),
|
|
||||||
),
|
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/login',
|
path: '/login',
|
||||||
builder: (context, state) => const AuthScreen(),
|
builder: (context, state) => const AuthScreen(),
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||||
import 'package:flux/core/theme/theme.dart';
|
import 'package:flux/core/theme/theme.dart';
|
||||||
|
|
||||||
class DashboardScreen extends StatelessWidget {
|
class DashboardContent extends StatelessWidget {
|
||||||
const DashboardScreen({super.key});
|
final bool? isLargeScreen;
|
||||||
|
|
||||||
|
const DashboardContent({super.key, this.isLargeScreen});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -38,21 +40,29 @@ class DashboardScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
|
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Padding(
|
child: Center(
|
||||||
padding: const EdgeInsets.all(20.0),
|
child: Container(
|
||||||
child: Column(
|
constraints: const BoxConstraints(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
maxWidth: 1200,
|
||||||
children: [
|
), // Larghezza massima "confortevole"
|
||||||
_buildWelcomeHeader(context, company?.ragioneSociale),
|
padding: const EdgeInsets.all(24.0),
|
||||||
const SizedBox(height: 30),
|
child: Padding(
|
||||||
_SectionTitle(title: 'AZIONI RAPIDE'),
|
padding: const EdgeInsets.all(20.0),
|
||||||
const SizedBox(height: 16),
|
child: Column(
|
||||||
_buildGridActions(context),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
const SizedBox(height: 32),
|
children: [
|
||||||
_SectionTitle(title: 'STATO NEGOZIO'),
|
_buildWelcomeHeader(context, company?.ragioneSociale),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 30),
|
||||||
_buildInfoCard(context, store),
|
_SectionTitle(title: 'AZIONI RAPIDE'),
|
||||||
],
|
const SizedBox(height: 16),
|
||||||
|
_buildGridActions(context),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
_SectionTitle(title: 'STATO NEGOZIO'),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
_buildInfoCard(context, store),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -84,39 +94,71 @@ class DashboardScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildGridActions(BuildContext context) {
|
Widget _buildGridActions(BuildContext context) {
|
||||||
return GridView.count(
|
return LayoutBuilder(
|
||||||
shrinkWrap: true,
|
builder: (context, constraints) {
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
// Calcoliamo il numero di colonne in base alla larghezza
|
||||||
crossAxisCount: 2,
|
// Sotto i 600px (mobile): 2 colonne
|
||||||
mainAxisSpacing: 16,
|
// Tra 600 e 1000px (tablet): 3 o 4 colonne
|
||||||
crossAxisSpacing: 16,
|
// Sopra i 1000px (desktop): 6 colonne
|
||||||
childAspectRatio: 1.5,
|
int crossAxisCount = 2;
|
||||||
children: [
|
if (constraints.maxWidth > 1000) {
|
||||||
_ActionCard(
|
crossAxisCount = 6;
|
||||||
label: 'Nuova Op',
|
} else if (constraints.maxWidth > 600) {
|
||||||
icon: Icons.add_task_rounded,
|
crossAxisCount = 4;
|
||||||
color: context.accent,
|
}
|
||||||
onTap: () {},
|
|
||||||
),
|
return GridView.count(
|
||||||
_ActionCard(
|
shrinkWrap: true,
|
||||||
label: 'Clienti',
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
icon: Icons.people_alt_rounded,
|
crossAxisCount: crossAxisCount,
|
||||||
color: Colors.orange,
|
mainAxisSpacing: 16,
|
||||||
onTap: () {},
|
crossAxisSpacing: 16,
|
||||||
),
|
// Su desktop rendiamo i tasti un po' più squadrati (1.0)
|
||||||
_ActionCard(
|
// Su mobile manteniamo il rettangolo (1.5)
|
||||||
label: 'Campagne',
|
childAspectRatio: constraints.maxWidth > 600 ? 1.2 : 1.5,
|
||||||
icon: Icons.campaign_rounded,
|
children: [
|
||||||
color: Colors.purple,
|
_ActionCard(
|
||||||
onTap: () {},
|
label: 'Nuova Op',
|
||||||
),
|
icon: Icons.add_task_rounded,
|
||||||
_ActionCard(
|
color: context.accent,
|
||||||
label: 'Report',
|
onTap: () {},
|
||||||
icon: Icons.analytics_rounded,
|
),
|
||||||
color: Colors.teal,
|
_ActionCard(
|
||||||
onTap: () {},
|
label: 'Clienti',
|
||||||
),
|
icon: Icons.people_alt_rounded,
|
||||||
],
|
color: Colors.orange,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
_ActionCard(
|
||||||
|
label: 'Campagne',
|
||||||
|
icon: Icons.campaign_rounded,
|
||||||
|
color: Colors.purple,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
_ActionCard(
|
||||||
|
label: 'Report',
|
||||||
|
icon: Icons.analytics_rounded,
|
||||||
|
color: Colors.teal,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
// Se siamo su desktop, possiamo aggiungere altri slot senza affollare
|
||||||
|
if (constraints.maxWidth > 600) ...[
|
||||||
|
_ActionCard(
|
||||||
|
label: 'Impostazioni',
|
||||||
|
icon: Icons.settings,
|
||||||
|
color: Colors.grey,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
_ActionCard(
|
||||||
|
label: 'Supporto',
|
||||||
|
icon: Icons.help_outline,
|
||||||
|
color: Colors.blueGrey,
|
||||||
|
onTap: () {},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
128
lib/features/home/ui/home_screen.dart
Normal file
128
lib/features/home/ui/home_screen.dart
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
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_content.dart';
|
||||||
|
|
||||||
|
class HomeScreen extends StatefulWidget {
|
||||||
|
const HomeScreen({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomeScreen> createState() => _HomeScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeScreenState extends State<HomeScreen> {
|
||||||
|
int _selectedIndex = 0;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<SessionBloc, SessionState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
// Definiamo se siamo su uno schermo "Large" (es. sopra i 900px)
|
||||||
|
final bool isLargeScreen = constraints.maxWidth > 900;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
body: Row(
|
||||||
|
children: [
|
||||||
|
// --- SIDEBAR (Solo per schermi grandi) ---
|
||||||
|
if (isLargeScreen)
|
||||||
|
NavigationRail(
|
||||||
|
selectedIndex: _selectedIndex,
|
||||||
|
onDestinationSelected: (int index) {
|
||||||
|
setState(() => _selectedIndex = index);
|
||||||
|
},
|
||||||
|
extended:
|
||||||
|
constraints.maxWidth >
|
||||||
|
1200, // Si allarga se c'è molto spazio
|
||||||
|
labelType: constraints.maxWidth > 1200
|
||||||
|
? NavigationRailLabelType.none
|
||||||
|
: NavigationRailLabelType.all,
|
||||||
|
leading: _buildRailHeader(constraints.maxWidth > 1200),
|
||||||
|
destinations: const [
|
||||||
|
NavigationRailDestination(
|
||||||
|
icon: Icon(Icons.dashboard_outlined),
|
||||||
|
selectedIcon: Icon(Icons.dashboard),
|
||||||
|
label: Text('Dashboard'),
|
||||||
|
),
|
||||||
|
NavigationRailDestination(
|
||||||
|
icon: Icon(Icons.people_outlined),
|
||||||
|
selectedIcon: Icon(Icons.people),
|
||||||
|
label: Text('Clienti'),
|
||||||
|
),
|
||||||
|
NavigationRailDestination(
|
||||||
|
icon: Icon(Icons.receipt_long_outlined),
|
||||||
|
selectedIcon: Icon(Icons.receipt_long),
|
||||||
|
label: Text('Operazioni'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
|
||||||
|
// --- CONTENUTO PRINCIPALE ---
|
||||||
|
Expanded(
|
||||||
|
child: _buildMainContent(context, state, isLargeScreen),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
// --- BOTTOM NAVIGATION (Solo per Mobile) ---
|
||||||
|
bottomNavigationBar: isLargeScreen
|
||||||
|
? null
|
||||||
|
: BottomNavigationBar(
|
||||||
|
currentIndex: _selectedIndex,
|
||||||
|
onTap: (index) => setState(() => _selectedIndex = index),
|
||||||
|
items: const [
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(Icons.dashboard),
|
||||||
|
label: 'Home',
|
||||||
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(Icons.people),
|
||||||
|
label: 'Clienti',
|
||||||
|
),
|
||||||
|
BottomNavigationBarItem(
|
||||||
|
icon: Icon(Icons.receipt_long),
|
||||||
|
label: 'Ops',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Header per la Sidebar (Logo o Icona)
|
||||||
|
Widget _buildRailHeader(bool isExtended) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||||
|
child: isExtended
|
||||||
|
? Text(
|
||||||
|
'FLUX',
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 24,
|
||||||
|
color: context.accent,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Icon(Icons.bolt, color: context.accent, size: 32),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildMainContent(
|
||||||
|
BuildContext context,
|
||||||
|
SessionState state,
|
||||||
|
bool isLargeScreen,
|
||||||
|
) {
|
||||||
|
// Qui gestiamo lo switch tra le pagine
|
||||||
|
switch (_selectedIndex) {
|
||||||
|
case 0:
|
||||||
|
return DashboardContent(isLargeScreen: isLargeScreen);
|
||||||
|
case 1:
|
||||||
|
return const Center(child: Text('Pagina Clienti')); // La faremo!
|
||||||
|
default:
|
||||||
|
return const DashboardContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user