added navigation and selection of workspaces
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/screens/workspaces/workspace_model.dart';
|
||||
import 'package:qpay/screens/workspaces/workspace_provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@@ -27,7 +29,6 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
|
||||
late Animation<Offset> _slideAnimation;
|
||||
|
||||
AuthState authState = AuthState();
|
||||
bool _navigated = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -86,8 +87,6 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
|
||||
}
|
||||
|
||||
void _evaluateNavigation(WorkspaceProvider provider) {
|
||||
if (_navigated) return;
|
||||
|
||||
final workspaces = provider.workspaces;
|
||||
|
||||
if (workspaces.length == 1) {
|
||||
@@ -104,20 +103,16 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
|
||||
// 2+ workspaces: stay on this screen so the user can pick one.
|
||||
}
|
||||
|
||||
void _onWorkspaceSelected(String workspaceId) async {
|
||||
if (_navigated) return;
|
||||
_navigated = true;
|
||||
|
||||
void _onWorkspaceSelected(WorkspaceModel ws) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('workspaceId', workspaceId);
|
||||
await prefs.setString('workspaceId', ws.id);
|
||||
await prefs.setString('workspaceInitials', ws.name[0]);
|
||||
|
||||
if (!mounted) return;
|
||||
_navigateToHome();
|
||||
}
|
||||
|
||||
void _navigateToHome() {
|
||||
if (_navigated) return;
|
||||
_navigated = true;
|
||||
context.go('/');
|
||||
}
|
||||
|
||||
@@ -149,68 +144,73 @@ class _WorkspaceScreenState extends State<WorkspaceScreen>
|
||||
final workspaces = provider.workspaces;
|
||||
|
||||
return SafeArea(
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Spacer(flex: 2),
|
||||
// Header
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primary.withValues(
|
||||
alpha: 0.1,
|
||||
child: Center(
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: SizedBox(
|
||||
width: kIsWeb ? 600 : double.infinity,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 48),
|
||||
// Header
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primary.withValues(
|
||||
alpha: 0.1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.business_rounded,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.business_rounded,
|
||||
color: theme.colorScheme.primary,
|
||||
size: 28,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Select a workspace',
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Choose the workspace you want to work in.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
// Workspace list
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: workspaces.length,
|
||||
separatorBuilder: (_, __) =>
|
||||
const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) {
|
||||
final ws = workspaces[index];
|
||||
return _WorkspaceCard(
|
||||
name: ws.name,
|
||||
description: ws.description,
|
||||
email: ws.email,
|
||||
phone: ws.phone,
|
||||
onTap: () => _onWorkspaceSelected(ws),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'Select a workspace',
|
||||
style: theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Choose the workspace you want to work in.',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
// Workspace list
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: workspaces.length,
|
||||
separatorBuilder: (_, __) =>
|
||||
const SizedBox(height: 12),
|
||||
itemBuilder: (context, index) {
|
||||
final ws = workspaces[index];
|
||||
return _WorkspaceCard(
|
||||
name: ws.name,
|
||||
description: ws.description,
|
||||
email: ws.email,
|
||||
phone: ws.phone,
|
||||
onTap: () => _onWorkspaceSelected(ws.id),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Spacer(flex: 1),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user