second commit
This commit is contained in:
115
lib/presentation/auth/providers/auth_controller.dart
Normal file
115
lib/presentation/auth/providers/auth_controller.dart
Normal file
@@ -0,0 +1,115 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../domain/entities/store_account.dart';
|
||||
|
||||
/// Sign-in state for the terminal.
|
||||
sealed class AuthState {
|
||||
const AuthState();
|
||||
|
||||
bool get isAuthenticated => this is Authenticated;
|
||||
}
|
||||
|
||||
class Unauthenticated extends AuthState {
|
||||
const Unauthenticated();
|
||||
}
|
||||
|
||||
class Authenticating extends AuthState {
|
||||
const Authenticating();
|
||||
}
|
||||
|
||||
class Authenticated extends AuthState {
|
||||
const Authenticated({required this.store, required this.user});
|
||||
|
||||
final StoreAccount store;
|
||||
final StaffUser user;
|
||||
}
|
||||
|
||||
class AuthFailure extends AuthState {
|
||||
const AuthFailure(this.message);
|
||||
|
||||
final String message;
|
||||
}
|
||||
|
||||
/// Credentials that ship with the demo build.
|
||||
class DemoCredentials {
|
||||
const DemoCredentials._();
|
||||
|
||||
static const String email = 'admin@nearle.in';
|
||||
static const String password = 'nearle123';
|
||||
}
|
||||
|
||||
const _demoStore = StoreAccount(
|
||||
id: 'store-001',
|
||||
name: AppConstants.storeName,
|
||||
email: DemoCredentials.email,
|
||||
address: AppConstants.storeAddress,
|
||||
gstin: AppConstants.storeGstin,
|
||||
phone: AppConstants.storePhone,
|
||||
staff: [
|
||||
StaffUser(id: 'u1', name: 'Suriya', role: StaffRole.admin, pin: '1234'),
|
||||
StaffUser(id: 'u2', name: 'Divya', role: StaffRole.manager, pin: '2345'),
|
||||
StaffUser(id: 'u3', name: 'Rahul', role: StaffRole.cashier, pin: '3456'),
|
||||
],
|
||||
);
|
||||
|
||||
/// Validates store credentials and holds the signed-in session.
|
||||
///
|
||||
/// Backed by a hardcoded account for now; swapping in a real identity provider
|
||||
/// means changing only [signIn].
|
||||
class AuthController extends StateNotifier<AuthState> {
|
||||
AuthController() : super(const Unauthenticated());
|
||||
|
||||
Future<bool> signIn({
|
||||
required String email,
|
||||
required String password,
|
||||
}) async {
|
||||
state = const Authenticating();
|
||||
|
||||
// Stand-in for the network round trip.
|
||||
await Future<void>.delayed(const Duration(milliseconds: 600));
|
||||
|
||||
final normalised = email.trim().toLowerCase();
|
||||
|
||||
if (normalised != DemoCredentials.email) {
|
||||
state = const AuthFailure('No store is registered against that email.');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password != DemoCredentials.password) {
|
||||
state = const AuthFailure('Incorrect password. Please try again.');
|
||||
return false;
|
||||
}
|
||||
|
||||
state = Authenticated(store: _demoStore, user: _demoStore.staff.first);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Switches the active operator without signing the store out.
|
||||
void switchUser(StaffUser user) {
|
||||
final current = state;
|
||||
if (current is! Authenticated) return;
|
||||
state = Authenticated(store: current.store, user: user);
|
||||
}
|
||||
|
||||
void signOut() => state = const Unauthenticated();
|
||||
|
||||
void clearError() {
|
||||
if (state is AuthFailure) state = const Unauthenticated();
|
||||
}
|
||||
}
|
||||
|
||||
final authControllerProvider =
|
||||
StateNotifierProvider<AuthController, AuthState>((ref) => AuthController());
|
||||
|
||||
/// The signed-in store, or null before sign-in.
|
||||
final currentStoreProvider = Provider<StoreAccount?>((ref) {
|
||||
final s = ref.watch(authControllerProvider);
|
||||
return s is Authenticated ? s.store : null;
|
||||
});
|
||||
|
||||
/// The active operator, or null before sign-in.
|
||||
final currentUserProvider = Provider<StaffUser?>((ref) {
|
||||
final s = ref.watch(authControllerProvider);
|
||||
return s is Authenticated ? s.user : null;
|
||||
});
|
||||
549
lib/presentation/auth/screens/login_screen.dart
Normal file
549
lib/presentation/auth/screens/login_screen.dart
Normal file
@@ -0,0 +1,549 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/validators.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../providers/auth_controller.dart';
|
||||
|
||||
/// Store sign-in. The terminal shows this until a valid account is entered.
|
||||
class LoginScreen extends ConsumerStatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _email = TextEditingController(text: DemoCredentials.email);
|
||||
final _password = TextEditingController(text: DemoCredentials.password);
|
||||
|
||||
bool _obscure = true;
|
||||
bool _rememberTerminal = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_email.dispose();
|
||||
_password.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _submit() async {
|
||||
FocusScope.of(context).unfocus();
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
|
||||
final ok = await ref.read(authControllerProvider.notifier).signIn(
|
||||
email: _email.text,
|
||||
password: _password.text,
|
||||
);
|
||||
|
||||
if (ok && mounted) context.go(AppRoutes.welcome);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Below this there isn't room for the brand panel beside the form.
|
||||
final showBrandPanel = constraints.maxWidth >= 1000;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
if (showBrandPanel)
|
||||
const Expanded(flex: 5, child: _BrandPanel()),
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: _FormPanel(
|
||||
formKey: _formKey,
|
||||
email: _email,
|
||||
password: _password,
|
||||
obscure: _obscure,
|
||||
rememberTerminal: _rememberTerminal,
|
||||
showCompactLogo: !showBrandPanel,
|
||||
onToggleObscure: () => setState(() => _obscure = !_obscure),
|
||||
onToggleRemember: (v) =>
|
||||
setState(() => _rememberTerminal = v ?? true),
|
||||
onSubmit: _submit,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BrandPanel extends StatelessWidget {
|
||||
const _BrandPanel();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: const BoxDecoration(gradient: AppColors.primaryGradient),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.giant),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
'N',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 23,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
const Flexible(
|
||||
child: Text(
|
||||
'Nearle POS',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: -0.4,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.giant),
|
||||
const Text(
|
||||
'Billing that keeps up\nwith your counter.',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 34,
|
||||
height: 1.25,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: -1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Text(
|
||||
'Scanner-first billing, GST-ready invoices and loyalty '
|
||||
'built in — for supermarkets, pharmacies and retail.',
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.78),
|
||||
fontSize: 15,
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.giant),
|
||||
const _Feature(
|
||||
icon: Icons.qr_code_scanner_rounded,
|
||||
title: 'Scan and go',
|
||||
body: 'No dialogs between items. Barcode to bill instantly.',
|
||||
),
|
||||
const _Feature(
|
||||
icon: Icons.receipt_long_rounded,
|
||||
title: 'GST compliant',
|
||||
body: 'Per-slab tax split into CGST and SGST on every bill.',
|
||||
),
|
||||
const _Feature(
|
||||
icon: Icons.stars_rounded,
|
||||
title: 'Loyalty that runs itself',
|
||||
body: 'Tiers and points applied without cashier input.',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
).animate().fadeIn(duration: 300.ms);
|
||||
}
|
||||
}
|
||||
|
||||
class _Feature extends StatelessWidget {
|
||||
const _Feature({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.body,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String body;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.xl),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 38,
|
||||
height: 38,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.16),
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Icon(icon, color: Colors.white, size: 19),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
body,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.72),
|
||||
fontSize: 13,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FormPanel extends ConsumerWidget {
|
||||
const _FormPanel({
|
||||
required this.formKey,
|
||||
required this.email,
|
||||
required this.password,
|
||||
required this.obscure,
|
||||
required this.rememberTerminal,
|
||||
required this.showCompactLogo,
|
||||
required this.onToggleObscure,
|
||||
required this.onToggleRemember,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final GlobalKey<FormState> formKey;
|
||||
final TextEditingController email;
|
||||
final TextEditingController password;
|
||||
final bool obscure;
|
||||
final bool rememberTerminal;
|
||||
final bool showCompactLogo;
|
||||
final VoidCallback onToggleObscure;
|
||||
final ValueChanged<bool?> onToggleRemember;
|
||||
final VoidCallback onSubmit;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final auth = ref.watch(authControllerProvider);
|
||||
final session = ref.watch(cashierSessionProvider);
|
||||
final busy = auth is Authenticating;
|
||||
|
||||
return SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 420),
|
||||
child: Form(
|
||||
key: formKey,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (showCompactLogo) ...[
|
||||
Center(
|
||||
child: Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.primaryGradient,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
'N',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 26,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
],
|
||||
|
||||
Text(
|
||||
'Sign in to your store',
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
const Text(
|
||||
'Use the credentials issued when your outlet was '
|
||||
'registered.',
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
color: AppColors.textSecondary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxxl),
|
||||
|
||||
const _Label('Store email'),
|
||||
TextFormField(
|
||||
controller: email,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
enabled: !busy,
|
||||
validator: (v) => (v ?? '').trim().isEmpty
|
||||
? 'Store email is required'
|
||||
: Validators.emailOptional(v),
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'store@example.in',
|
||||
prefixIcon: Icon(Icons.storefront_outlined),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
const _Label('Password'),
|
||||
TextFormField(
|
||||
controller: password,
|
||||
obscureText: obscure,
|
||||
enabled: !busy,
|
||||
textInputAction: TextInputAction.done,
|
||||
onFieldSubmitted: (_) => onSubmit(),
|
||||
validator: (v) => (v ?? '').isEmpty
|
||||
? 'Password is required'
|
||||
: ((v ?? '').length < 6
|
||||
? 'Password looks too short'
|
||||
: null),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Enter your password',
|
||||
prefixIcon: const Icon(Icons.lock_outline_rounded),
|
||||
suffixIcon: IconButton(
|
||||
onPressed: onToggleObscure,
|
||||
icon: Icon(
|
||||
obscure
|
||||
? Icons.visibility_outlined
|
||||
: Icons.visibility_off_outlined,
|
||||
size: 20,
|
||||
),
|
||||
tooltip: obscure ? 'Show password' : 'Hide password',
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
|
||||
// Wrap, not Row — on a narrow tablet these would collide.
|
||||
Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: busy
|
||||
? null
|
||||
: () => onToggleRemember(!rememberTerminal),
|
||||
borderRadius: AppRadius.brXs,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: Checkbox(
|
||||
value: rememberTerminal,
|
||||
onChanged: busy ? null : onToggleRemember,
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
const Text(
|
||||
'Remember this terminal',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: busy ? null : () {},
|
||||
child: const Text('Forgot password?'),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
if (auth is AuthFailure) ...[
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dangerSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.error_outline_rounded,
|
||||
color: AppColors.danger, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
auth.message,
|
||||
style: const TextStyle(
|
||||
color: AppColors.danger,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
).animate().shake(duration: 320.ms, hz: 3),
|
||||
],
|
||||
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
PrimaryButton(
|
||||
label: 'Sign in',
|
||||
icon: Icons.login_rounded,
|
||||
large: true,
|
||||
busy: busy,
|
||||
onPressed: onSubmit,
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
_DemoHint(
|
||||
onFill: busy
|
||||
? null
|
||||
: () {
|
||||
email.text = DemoCredentials.email;
|
||||
password.text = DemoCredentials.password;
|
||||
},
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Center(
|
||||
child: Text(
|
||||
'Terminal ${session.terminalId}',
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Label extends StatelessWidget {
|
||||
const _Label(this.text);
|
||||
|
||||
final String text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DemoHint extends StatelessWidget {
|
||||
const _DemoHint({this.onFill});
|
||||
|
||||
final VoidCallback? onFill;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
border: Border.all(color: AppColors.primaryBorder),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.info_outline_rounded,
|
||||
size: 17, color: AppColors.primary),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Demo account',
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
SelectableText(
|
||||
'${DemoCredentials.email} · ${DemoCredentials.password}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: onFill,
|
||||
style: TextButton.styleFrom(
|
||||
minimumSize: const Size(0, 32),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
|
||||
),
|
||||
child: const Text('Fill', style: TextStyle(fontSize: 12.5)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
71
lib/presentation/customer/providers/customer_providers.dart
Normal file
71
lib/presentation/customer/providers/customer_providers.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../domain/entities/customer.dart';
|
||||
|
||||
/// Outcome of the mobile-number lookup on the Existing Customer screen.
|
||||
sealed class CustomerLookupState {
|
||||
const CustomerLookupState();
|
||||
}
|
||||
|
||||
class LookupIdle extends CustomerLookupState {
|
||||
const LookupIdle();
|
||||
}
|
||||
|
||||
class LookupSearching extends CustomerLookupState {
|
||||
const LookupSearching();
|
||||
}
|
||||
|
||||
class LookupFound extends CustomerLookupState {
|
||||
const LookupFound(this.customer);
|
||||
|
||||
final Customer customer;
|
||||
}
|
||||
|
||||
class LookupNotFound extends CustomerLookupState {
|
||||
const LookupNotFound(this.mobile);
|
||||
|
||||
final String mobile;
|
||||
}
|
||||
|
||||
class LookupError extends CustomerLookupState {
|
||||
const LookupError(this.message);
|
||||
|
||||
final String message;
|
||||
}
|
||||
|
||||
class CustomerLookupController extends StateNotifier<CustomerLookupState> {
|
||||
CustomerLookupController(this._ref) : super(const LookupIdle());
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<void> search(String mobile) async {
|
||||
final digits = mobile.replaceAll(RegExp(r'\D'), '');
|
||||
if (digits.length != 10) {
|
||||
state = const LookupIdle();
|
||||
return;
|
||||
}
|
||||
|
||||
state = const LookupSearching();
|
||||
try {
|
||||
final customer =
|
||||
await _ref.read(customerRepositoryProvider).findByMobile(digits);
|
||||
state = customer != null
|
||||
? LookupFound(customer)
|
||||
: LookupNotFound(digits);
|
||||
} catch (e) {
|
||||
state = LookupError(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
void reset() => state = const LookupIdle();
|
||||
}
|
||||
|
||||
final customerLookupProvider =
|
||||
StateNotifierProvider<CustomerLookupController, CustomerLookupState>(
|
||||
(ref) => CustomerLookupController(ref),
|
||||
);
|
||||
|
||||
final recentCustomersProvider = FutureProvider<List<Customer>>(
|
||||
(ref) => ref.watch(customerRepositoryProvider).recent(limit: 6),
|
||||
);
|
||||
@@ -0,0 +1,321 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/utils/validators.dart';
|
||||
import '../../../core/widgets/glass_card.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/customer.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../providers/customer_providers.dart';
|
||||
|
||||
/// Screen 2 — registers a shopper and drops straight into billing.
|
||||
class CustomerRegistrationScreen extends ConsumerStatefulWidget {
|
||||
const CustomerRegistrationScreen({super.key, this.prefillMobile});
|
||||
|
||||
final String? prefillMobile;
|
||||
|
||||
@override
|
||||
ConsumerState<CustomerRegistrationScreen> createState() =>
|
||||
_CustomerRegistrationScreenState();
|
||||
}
|
||||
|
||||
class _CustomerRegistrationScreenState
|
||||
extends ConsumerState<CustomerRegistrationScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late final TextEditingController _mobile;
|
||||
final _name = TextEditingController();
|
||||
final _email = TextEditingController();
|
||||
|
||||
Gender _gender = Gender.unspecified;
|
||||
DateTime? _dob;
|
||||
bool _saving = false;
|
||||
String? _serverError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_mobile = TextEditingController(text: widget.prefillMobile ?? '');
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_mobile.dispose();
|
||||
_name.dispose();
|
||||
_email.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
setState(() => _serverError = null);
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
|
||||
setState(() => _saving = true);
|
||||
try {
|
||||
final customer = await ref.read(customerRepositoryProvider).create(
|
||||
Customer(
|
||||
id: '',
|
||||
name: _name.text,
|
||||
mobile: _mobile.text,
|
||||
email: _email.text,
|
||||
gender: _gender,
|
||||
dateOfBirth: _dob,
|
||||
),
|
||||
);
|
||||
|
||||
ref.read(cartControllerProvider.notifier).attachCustomer(customer);
|
||||
ref.invalidate(recentCustomersProvider);
|
||||
|
||||
if (!mounted) return;
|
||||
context.go(AppRoutes.pos);
|
||||
} catch (e) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_saving = false;
|
||||
_serverError = e is StateError ? e.message : 'Could not save customer.';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickDob() async {
|
||||
final now = DateTime.now();
|
||||
final picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _dob ?? DateTime(now.year - 25),
|
||||
firstDate: DateTime(now.year - 100),
|
||||
lastDate: now,
|
||||
helpText: 'Date of birth',
|
||||
);
|
||||
if (picked != null) setState(() => _dob = picked);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('New Customer'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 640),
|
||||
child: GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxxl),
|
||||
radius: AppRadius.xl,
|
||||
shadows: AppColors.shadowMd,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Register a shopper',
|
||||
style: context.text.headlineSmall),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
'Only the mobile number and name are required.',
|
||||
style: context.text.bodySmall,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
|
||||
_Field(
|
||||
label: 'Mobile Number',
|
||||
required: true,
|
||||
child: TextFormField(
|
||||
controller: _mobile,
|
||||
autofocus: true,
|
||||
keyboardType: TextInputType.phone,
|
||||
maxLength: 10,
|
||||
validator: Validators.mobile,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
],
|
||||
decoration: const InputDecoration(
|
||||
hintText: '10-digit mobile number',
|
||||
prefixText: '+91 ',
|
||||
counterText: '',
|
||||
prefixIcon: Icon(Icons.phone_outlined),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
_Field(
|
||||
label: 'Customer Name',
|
||||
required: true,
|
||||
child: TextFormField(
|
||||
controller: _name,
|
||||
textCapitalization: TextCapitalization.words,
|
||||
validator: Validators.name,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Full name',
|
||||
prefixIcon: Icon(Icons.person_outline_rounded),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
_Field(
|
||||
label: 'Email',
|
||||
child: TextFormField(
|
||||
controller: _email,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
validator: Validators.emailOptional,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'name@example.com',
|
||||
prefixIcon: Icon(Icons.mail_outline_rounded),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
_Field(
|
||||
label: 'Gender',
|
||||
child: Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
children: Gender.values
|
||||
.map((g) => ChoiceChip(
|
||||
label: Text(g.label),
|
||||
selected: _gender == g,
|
||||
onSelected: (_) =>
|
||||
setState(() => _gender = g),
|
||||
labelStyle: TextStyle(
|
||||
color: _gender == g
|
||||
? Colors.white
|
||||
: AppColors.textSecondary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
|
||||
_Field(
|
||||
label: 'Date of Birth',
|
||||
child: InkWell(
|
||||
onTap: _pickDob,
|
||||
borderRadius: AppRadius.brMd,
|
||||
child: InputDecorator(
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.cake_outlined),
|
||||
),
|
||||
child: Text(
|
||||
_dob == null
|
||||
? 'Select a date (optional)'
|
||||
: Formatters.date(_dob!),
|
||||
style: TextStyle(
|
||||
color: _dob == null
|
||||
? AppColors.textTertiary
|
||||
: AppColors.textPrimary,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (_serverError != null) ...[
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dangerSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(children: [
|
||||
const Icon(Icons.error_outline_rounded,
|
||||
color: AppColors.danger, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_serverError!,
|
||||
style: const TextStyle(
|
||||
color: AppColors.danger,
|
||||
fontSize: 13.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: 'Cancel',
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed:
|
||||
_saving ? null : () => context.pop(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PrimaryButton(
|
||||
label: 'Save & Continue',
|
||||
icon: Icons.check_rounded,
|
||||
busy: _saving,
|
||||
onPressed: _save,
|
||||
),
|
||||
),
|
||||
]),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Field extends StatelessWidget {
|
||||
const _Field({
|
||||
required this.label,
|
||||
required this.child,
|
||||
this.required = false,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final Widget child;
|
||||
final bool required;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.lg),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(children: [
|
||||
Text(label,
|
||||
style: context.text.labelMedium
|
||||
?.copyWith(color: AppColors.textSecondary)),
|
||||
if (required)
|
||||
const Text(' *',
|
||||
style: TextStyle(color: AppColors.danger, fontSize: 13)),
|
||||
if (!required)
|
||||
Text(' optional',
|
||||
style: context.text.labelSmall
|
||||
?.copyWith(color: AppColors.textTertiary)),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
child,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
504
lib/presentation/customer/screens/existing_customer_screen.dart
Normal file
504
lib/presentation/customer/screens/existing_customer_screen.dart
Normal file
@@ -0,0 +1,504 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../../../core/widgets/glass_card.dart';
|
||||
import '../../../core/widgets/numeric_keypad.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../core/widgets/status_pill.dart';
|
||||
import '../../../domain/entities/customer.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../providers/customer_providers.dart';
|
||||
|
||||
/// Screen 3 — mobile lookup that auto-searches on the tenth digit.
|
||||
class ExistingCustomerScreen extends ConsumerStatefulWidget {
|
||||
const ExistingCustomerScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ExistingCustomerScreen> createState() =>
|
||||
_ExistingCustomerScreenState();
|
||||
}
|
||||
|
||||
class _ExistingCustomerScreenState
|
||||
extends ConsumerState<ExistingCustomerScreen> {
|
||||
String _digits = '';
|
||||
|
||||
void _append(String d) {
|
||||
if (_digits.length >= AppConstants.mobileNumberLength) return;
|
||||
setState(() => _digits += d);
|
||||
if (_digits.length == AppConstants.mobileNumberLength) _search();
|
||||
}
|
||||
|
||||
void _backspace() {
|
||||
if (_digits.isEmpty) return;
|
||||
setState(() => _digits = _digits.substring(0, _digits.length - 1));
|
||||
ref.read(customerLookupProvider.notifier).reset();
|
||||
}
|
||||
|
||||
void _clear() {
|
||||
setState(() => _digits = '');
|
||||
ref.read(customerLookupProvider.notifier).reset();
|
||||
}
|
||||
|
||||
void _search() => ref.read(customerLookupProvider.notifier).search(_digits);
|
||||
|
||||
void _continueWith(Customer customer) {
|
||||
ref.read(cartControllerProvider.notifier).attachCustomer(customer);
|
||||
context.go(AppRoutes.pos);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final lookup = ref.watch(customerLookupProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('Find Customer'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
actions: [
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
ref.read(cartControllerProvider.notifier).attachCustomer(null);
|
||||
context.go(AppRoutes.pos);
|
||||
},
|
||||
icon: const Icon(Icons.directions_walk_rounded,
|
||||
color: Colors.white, size: 18),
|
||||
label: const Text('Continue as Walk-in',
|
||||
style: TextStyle(color: Colors.white)),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: context.isCompact
|
||||
? SingleChildScrollView(
|
||||
child: Column(children: [
|
||||
_entryPanel(),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
// Bound the height: the panel uses Expanded/Spacer
|
||||
// internally, which a scroll view cannot supply.
|
||||
SizedBox(height: 480, child: _resultPanel(lookup)),
|
||||
]),
|
||||
)
|
||||
: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(flex: 4, child: _entryPanel()),
|
||||
const SizedBox(width: AppSpacing.xxl),
|
||||
Expanded(flex: 5, child: _resultPanel(lookup)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _entryPanel() {
|
||||
return GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
radius: AppRadius.xl,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Mobile number', style: context.text.labelMedium),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_display(),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Center(
|
||||
child: NumericKeypad(
|
||||
onKey: _append,
|
||||
onBackspace: _backspace,
|
||||
onClear: _clear,
|
||||
onSubmit:
|
||||
_digits.length == AppConstants.mobileNumberLength
|
||||
? _search
|
||||
: null,
|
||||
submitLabel: 'Search',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Ten slots so the cashier can see progress at a glance.
|
||||
Widget _display() {
|
||||
return Container(
|
||||
height: 72,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(color: AppColors.primaryBorder),
|
||||
),
|
||||
child: Row(children: [
|
||||
const Text('+91',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
)),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: List.generate(
|
||||
AppConstants.mobileNumberLength,
|
||||
(i) {
|
||||
final filled = i < _digits.length;
|
||||
return AnimatedContainer(
|
||||
duration: AppMotion.fast,
|
||||
width: 22,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
filled ? _digits[i] : '–',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: filled
|
||||
? AppColors.textPrimary
|
||||
: AppColors.textTertiary.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_digits.isNotEmpty)
|
||||
IconButton(
|
||||
onPressed: _clear,
|
||||
icon: const Icon(Icons.close_rounded, size: 20),
|
||||
color: AppColors.textTertiary,
|
||||
tooltip: 'Clear',
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _resultPanel(CustomerLookupState state) {
|
||||
return GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
radius: AppRadius.xl,
|
||||
child: switch (state) {
|
||||
LookupIdle() => _idle(),
|
||||
LookupSearching() => const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
),
|
||||
LookupFound(:final customer) => _found(customer),
|
||||
LookupNotFound(:final mobile) => _notFound(mobile),
|
||||
LookupError(:final message) => EmptyState(
|
||||
title: 'Something went wrong',
|
||||
message: message,
|
||||
emoji: '⚠️',
|
||||
),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _idle() {
|
||||
final recent = ref.watch(recentCustomersProvider);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Recent customers', style: context.text.titleMedium),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text('Tap to select, or key in a mobile number.',
|
||||
style: context.text.bodySmall),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: recent.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (e, _) => EmptyState(
|
||||
title: 'Could not load customers',
|
||||
message: '$e',
|
||||
emoji: '⚠️',
|
||||
compact: true,
|
||||
),
|
||||
data: (customers) => customers.isEmpty
|
||||
? const EmptyState(
|
||||
title: 'No customers yet',
|
||||
message: 'Register the first one from the welcome screen.',
|
||||
emoji: '👤',
|
||||
compact: true,
|
||||
)
|
||||
: ListView.separated(
|
||||
itemCount: customers.length,
|
||||
separatorBuilder: (_, __) =>
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
itemBuilder: (_, i) => _RecentTile(
|
||||
customer: customers[i],
|
||||
onTap: () => _continueWith(customers[i]),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _found(Customer c) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(children: [
|
||||
CircleAvatar(
|
||||
radius: 30,
|
||||
backgroundColor: AppColors.primarySurface,
|
||||
child: Text(
|
||||
Formatters.initials(c.name),
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(children: [
|
||||
Flexible(
|
||||
child: Text(c.name,
|
||||
style: context.text.headlineSmall,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
StatusPill.tier(c.tier),
|
||||
]),
|
||||
const SizedBox(height: 2),
|
||||
Text('+91 ${Formatters.mobile(c.mobile)}',
|
||||
style: context.text.bodyMedium
|
||||
?.copyWith(color: AppColors.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
if (c.isBirthdayToday) ...[
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.warningSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: const Row(children: [
|
||||
Text('🎂', style: TextStyle(fontSize: 18)),
|
||||
SizedBox(width: AppSpacing.sm),
|
||||
Text("It's their birthday today — wish them!",
|
||||
style: TextStyle(
|
||||
color: AppColors.warning,
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
]),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: _Stat(
|
||||
label: 'Loyalty Points',
|
||||
value: '${c.loyaltyPoints}',
|
||||
caption: 'Worth ${Formatters.money(c.redeemableValue)}',
|
||||
icon: Icons.stars_rounded,
|
||||
color: AppColors.tierGold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: _Stat(
|
||||
label: 'Lifetime Spend',
|
||||
value: Formatters.moneyCompact(c.lifetimeSpend),
|
||||
caption: '${c.visitCount} visits',
|
||||
icon: Icons.receipt_long_rounded,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
if (c.tier.discountRate > 0) ...[
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(children: [
|
||||
const Icon(Icons.local_offer_rounded,
|
||||
color: AppColors.success, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${c.tier.label} members get '
|
||||
'${Formatters.percent(c.tier.discountRate)} off '
|
||||
'automatically on every bill.',
|
||||
style: const TextStyle(
|
||||
color: AppColors.success,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
],
|
||||
|
||||
const Spacer(),
|
||||
PrimaryButton(
|
||||
label: 'Continue to Billing',
|
||||
icon: Icons.point_of_sale_rounded,
|
||||
large: true,
|
||||
onPressed: () => _continueWith(c),
|
||||
),
|
||||
],
|
||||
).animate().fadeIn(duration: 200.ms);
|
||||
}
|
||||
|
||||
Widget _notFound(String mobile) {
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: EmptyState(
|
||||
title: 'No customer found',
|
||||
message: 'Nobody is registered against '
|
||||
'+91 ${Formatters.mobile(mobile)}.',
|
||||
emoji: '🔍',
|
||||
),
|
||||
),
|
||||
PrimaryButton(
|
||||
label: 'Register Customer',
|
||||
icon: Icons.person_add_alt_1_rounded,
|
||||
onPressed: () => context.push(
|
||||
'${AppRoutes.registerCustomer}?mobile=$mobile',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
PrimaryButton(
|
||||
label: 'Continue as Walk-in',
|
||||
icon: Icons.directions_walk_rounded,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
ref.read(cartControllerProvider.notifier).attachCustomer(null);
|
||||
context.go(AppRoutes.pos);
|
||||
},
|
||||
),
|
||||
],
|
||||
).animate().fadeIn(duration: 200.ms);
|
||||
}
|
||||
}
|
||||
|
||||
class _RecentTile extends StatelessWidget {
|
||||
const _RecentTile({required this.customer, required this.onTap});
|
||||
|
||||
final Customer customer;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brMd,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: AppRadius.brMd,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Row(children: [
|
||||
CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundColor: AppColors.primarySurface,
|
||||
child: Text(
|
||||
Formatters.initials(customer.name),
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(customer.name,
|
||||
style: context.text.titleSmall,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
Text(Formatters.maskedMobile(customer.mobile),
|
||||
style: context.text.bodySmall),
|
||||
],
|
||||
),
|
||||
),
|
||||
StatusPill.tier(customer.tier, dense: true),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
const Icon(Icons.chevron_right_rounded,
|
||||
color: AppColors.textTertiary),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Stat extends StatelessWidget {
|
||||
const _Stat({
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.caption,
|
||||
required this.icon,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
final String caption;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brMd,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(children: [
|
||||
Icon(icon, size: 16, color: color),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(label,
|
||||
style: context.text.labelSmall
|
||||
?.copyWith(color: AppColors.textSecondary)),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(value,
|
||||
style: context.text.headlineSmall?.copyWith(color: color)),
|
||||
Text(caption, style: context.text.bodySmall),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
209
lib/presentation/modules/screens/customers_view.dart
Normal file
209
lib/presentation/modules/screens/customers_view.dart
Normal file
@@ -0,0 +1,209 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/status_pill.dart';
|
||||
import '../../../domain/entities/customer.dart';
|
||||
import '../widgets/module_widgets.dart';
|
||||
|
||||
/// Full customer book, independent of the six shown during billing.
|
||||
final allCustomersProvider = FutureProvider<List<Customer>>(
|
||||
(ref) => ref.watch(customerRepositoryProvider).recent(limit: 200),
|
||||
);
|
||||
|
||||
class CustomersView extends ConsumerStatefulWidget {
|
||||
const CustomersView({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<CustomersView> createState() => _CustomersViewState();
|
||||
}
|
||||
|
||||
class _CustomersViewState extends ConsumerState<CustomersView> {
|
||||
String _query = '';
|
||||
MembershipTier? _tier;
|
||||
|
||||
Color _tierColor(MembershipTier t) => switch (t) {
|
||||
MembershipTier.bronze => AppColors.tierBronze,
|
||||
MembershipTier.silver => AppColors.tierSilver,
|
||||
MembershipTier.gold => AppColors.tierGold,
|
||||
MembershipTier.platinum => AppColors.tierPlatinum,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final all = ref.watch(allCustomersProvider).value ?? const <Customer>[];
|
||||
|
||||
final filtered = all.where((c) {
|
||||
final q = _query.trim().toLowerCase();
|
||||
final matchesQuery = q.isEmpty ||
|
||||
c.name.toLowerCase().contains(q) ||
|
||||
c.mobile.contains(q);
|
||||
return matchesQuery && (_tier == null || c.tier == _tier);
|
||||
}).toList();
|
||||
|
||||
final lifetime = all.fold<double>(0, (s, c) => s + c.lifetimeSpend);
|
||||
final points = all.fold<int>(0, (s, c) => s + c.loyaltyPoints);
|
||||
|
||||
return ModulePage(
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: AppSpacing.lg,
|
||||
runSpacing: AppSpacing.lg,
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Total Customers',
|
||||
value: '${all.length}',
|
||||
icon: Icons.people_alt_rounded,
|
||||
caption: 'registered',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Lifetime Value',
|
||||
value: Formatters.moneyCompact(lifetime),
|
||||
icon: Icons.payments_rounded,
|
||||
color: AppColors.success,
|
||||
caption: 'all customers',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Points Outstanding',
|
||||
value: '$points',
|
||||
icon: Icons.stars_rounded,
|
||||
color: AppColors.tierGold,
|
||||
caption: 'worth ${Formatters.money(points * 0.25)}',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Avg Spend',
|
||||
value: Formatters.money(all.isEmpty ? 0 : lifetime / all.length),
|
||||
icon: Icons.trending_up_rounded,
|
||||
color: AppColors.info,
|
||||
caption: 'per customer',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
PanelCard(
|
||||
title: 'Tier distribution',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final t in MembershipTier.values)
|
||||
ProgressRow(
|
||||
label: '${t.label} · '
|
||||
'${(t.discountRate * 100).toStringAsFixed(0)}% off',
|
||||
value: '${all.where((c) => c.tier == t).length}',
|
||||
fraction: all.isEmpty
|
||||
? 0
|
||||
: all.where((c) => c.tier == t).length / all.length,
|
||||
color: _tierColor(t),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
PanelCard(
|
||||
title: 'Customer book',
|
||||
subtitle: '${filtered.length} shown',
|
||||
action: FilledButton.icon(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.person_add_alt_1_rounded, size: 17),
|
||||
label: const Text('Add customer'),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
minimumSize: const Size(0, 40),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextField(
|
||||
onChanged: (v) => setState(() => _query = v),
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Search by name or mobile number…',
|
||||
prefixIcon: Icon(Icons.search_rounded),
|
||||
isDense: true,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
ChoiceChip(
|
||||
label: const Text('All tiers'),
|
||||
selected: _tier == null,
|
||||
onSelected: (_) => setState(() => _tier = null),
|
||||
labelStyle: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _tier == null
|
||||
? Colors.white
|
||||
: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
for (final t in MembershipTier.values)
|
||||
ChoiceChip(
|
||||
label: Text(t.label),
|
||||
selected: _tier == t,
|
||||
onSelected: (_) =>
|
||||
setState(() => _tier = _tier == t ? null : t),
|
||||
labelStyle: TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _tier == t
|
||||
? Colors.white
|
||||
: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
ResponsiveTable(
|
||||
columns: const [
|
||||
TableCol('Customer', flex: 4),
|
||||
TableCol('Mobile', flex: 3, priority: 1),
|
||||
TableCol('Tier', flex: 2),
|
||||
TableCol('Points', flex: 2, numeric: true, priority: 1),
|
||||
TableCol('Lifetime', flex: 2, numeric: true),
|
||||
TableCol('Visits', flex: 2, numeric: true, priority: 1),
|
||||
],
|
||||
rows: filtered
|
||||
.map((c) => [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 14,
|
||||
backgroundColor: AppColors.primarySurface,
|
||||
child: Text(
|
||||
Formatters.initials(c.name),
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Flexible(child: Cell(c.name, bold: true)),
|
||||
],
|
||||
),
|
||||
Cell(Formatters.mobile(c.mobile), mono: true),
|
||||
StatusPill.tier(c.tier, dense: true),
|
||||
Cell('${c.loyaltyPoints}', mono: true),
|
||||
Cell(Formatters.moneyCompact(c.lifetimeSpend),
|
||||
mono: true, bold: true),
|
||||
Cell('${c.visitCount}', mono: true),
|
||||
])
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
287
lib/presentation/modules/screens/events_view.dart
Normal file
287
lib/presentation/modules/screens/events_view.dart
Normal file
@@ -0,0 +1,287 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/sync_event.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../widgets/module_widgets.dart';
|
||||
|
||||
/// The terminal's outbound half: what today produced, and what has been sent.
|
||||
class EventsView extends ConsumerWidget {
|
||||
const EventsView({super.key});
|
||||
|
||||
static Color statusColor(SyncStatus s) => switch (s) {
|
||||
SyncStatus.synced => AppColors.success,
|
||||
SyncStatus.failed => AppColors.danger,
|
||||
SyncStatus.syncing => AppColors.info,
|
||||
SyncStatus.pending => AppColors.warning,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final report = ref.watch(shiftReportProvider);
|
||||
final events = ref.watch(syncEventsProvider);
|
||||
final pushing = ref.watch(reportPushProvider);
|
||||
|
||||
return ModulePage(
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: AppSpacing.lg,
|
||||
runSpacing: AppSpacing.lg,
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Bills Today',
|
||||
value: '${report.billCount}',
|
||||
icon: Icons.receipt_long_rounded,
|
||||
caption: report.firstBillAt == null
|
||||
? 'no sales yet'
|
||||
: '${Formatters.time(report.firstBillAt!)} – '
|
||||
'${Formatters.time(report.lastBillAt!)}',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Items Sold',
|
||||
value: report.itemCount.toStringAsFixed(0),
|
||||
icon: Icons.shopping_basket_rounded,
|
||||
color: AppColors.info,
|
||||
caption: 'units across all bills',
|
||||
),
|
||||
StatTile(
|
||||
label: "Today's Sales",
|
||||
value: Formatters.money(report.grossSales),
|
||||
icon: Icons.payments_rounded,
|
||||
color: AppColors.success,
|
||||
caption: 'gross takings',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Average Basket',
|
||||
value: Formatters.money(report.averageBasket),
|
||||
icon: Icons.trending_up_rounded,
|
||||
color: AppColors.tierGold,
|
||||
caption: 'per bill',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
PanelCard(
|
||||
title: 'Shift report',
|
||||
subtitle: '${Formatters.date(report.businessDate)} · '
|
||||
'${report.cashierName} · ${report.terminalId}',
|
||||
action: TagChip(
|
||||
report.isEmpty ? 'Nothing to send' : 'Ready to push',
|
||||
color: report.isEmpty ? AppColors.textSecondary : AppColors.warning,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_row('Bills', '${report.billCount}'),
|
||||
_row('Items sold', report.itemCount.toStringAsFixed(0)),
|
||||
_row('Gross sales', Formatters.money(report.grossSales)),
|
||||
_row('Net of tax', Formatters.money(report.netOfTax)),
|
||||
_row('GST collected', Formatters.money(report.taxCollected)),
|
||||
_row('Discount given', Formatters.money(report.discountGiven)),
|
||||
_row('Round off', Formatters.money(report.roundOff)),
|
||||
_row('Points issued', '${report.loyaltyPointsIssued}'),
|
||||
_row('Points redeemed', '${report.loyaltyPointsRedeemed}'),
|
||||
|
||||
if (report.paymentBreakdown.isNotEmpty) ...[
|
||||
const Divider(height: AppSpacing.xxl),
|
||||
const Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'By payment method',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
for (final e in report.paymentBreakdown.entries)
|
||||
ProgressRow(
|
||||
label: '${e.key.emoji} ${e.key.label}',
|
||||
value: Formatters.money(e.value),
|
||||
fraction: report.grossSales <= 0
|
||||
? 0
|
||||
: e.value / report.grossSales,
|
||||
color: _methodColor(e.key),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
PrimaryButton(
|
||||
label: 'Push report to server',
|
||||
icon: Icons.cloud_upload_rounded,
|
||||
large: true,
|
||||
busy: pushing,
|
||||
onPressed: report.isEmpty
|
||||
? null
|
||||
: () async {
|
||||
final event = await ref
|
||||
.read(reportPushProvider.notifier)
|
||||
.pushToday();
|
||||
if (!context.mounted) return;
|
||||
final ok = event.status == SyncStatus.synced;
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(SnackBar(
|
||||
backgroundColor:
|
||||
ok ? AppColors.success : AppColors.danger,
|
||||
content: Text(
|
||||
ok
|
||||
? 'Shift report sent.'
|
||||
: 'Push failed — the report is still saved '
|
||||
'on this terminal.',
|
||||
),
|
||||
));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
const Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.shield_outlined,
|
||||
size: 15, color: AppColors.textTertiary),
|
||||
SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'A failed push never discards data. The report stays '
|
||||
'queued below and can be retried at any time.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textTertiary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
PanelCard(
|
||||
title: 'Event log',
|
||||
subtitle: '${events.length} recorded · '
|
||||
'${events.where((e) => e.status != SyncStatus.synced).length} '
|
||||
'outstanding',
|
||||
child: events.isEmpty
|
||||
? const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: AppSpacing.lg),
|
||||
child: Text(
|
||||
'No sync activity yet. Importing the catalogue or pushing '
|
||||
'a report will appear here.',
|
||||
style: TextStyle(color: AppColors.textTertiary),
|
||||
),
|
||||
)
|
||||
: ResponsiveTable(
|
||||
columns: const [
|
||||
TableCol('Event', flex: 3),
|
||||
TableCol('Detail', flex: 5, priority: 1),
|
||||
TableCol('Time', flex: 2, numeric: true, priority: 1),
|
||||
TableCol('Status', flex: 2, numeric: true),
|
||||
],
|
||||
rows: events
|
||||
.map((e) => [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
e.type.isInbound
|
||||
? Icons.cloud_download_rounded
|
||||
: Icons.cloud_upload_rounded,
|
||||
size: 15,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Flexible(child: Cell(e.type.label, bold: true)),
|
||||
],
|
||||
),
|
||||
Cell(
|
||||
e.error ?? e.summary,
|
||||
color: e.error != null
|
||||
? AppColors.danger
|
||||
: AppColors.textSecondary,
|
||||
),
|
||||
Cell(Formatters.time(e.createdAt),
|
||||
color: AppColors.textTertiary),
|
||||
e.status == SyncStatus.failed
|
||||
? _RetryButton(eventId: e.id)
|
||||
: TagChip(
|
||||
e.status.label,
|
||||
color: statusColor(e.status),
|
||||
),
|
||||
])
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static Color _methodColor(PaymentMethod m) => switch (m) {
|
||||
PaymentMethod.cash => AppColors.success,
|
||||
PaymentMethod.card => AppColors.info,
|
||||
PaymentMethod.upi => AppColors.primary,
|
||||
PaymentMethod.wallet => AppColors.warning,
|
||||
PaymentMethod.giftCard => AppColors.tierGold,
|
||||
PaymentMethod.loyalty => AppColors.tierSilver,
|
||||
};
|
||||
|
||||
Widget _row(String label, String value) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs + 2),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _RetryButton extends ConsumerWidget {
|
||||
const _RetryButton({required this.eventId});
|
||||
|
||||
final String eventId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final busy = ref.watch(reportPushProvider);
|
||||
|
||||
return TextButton.icon(
|
||||
onPressed: busy
|
||||
? null
|
||||
: () => ref.read(reportPushProvider.notifier).retry(eventId),
|
||||
icon: const Icon(Icons.refresh_rounded, size: 15),
|
||||
label: const Text('Retry', style: TextStyle(fontSize: 12.5)),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.danger,
|
||||
minimumSize: const Size(0, 30),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
338
lib/presentation/modules/screens/product_import_view.dart
Normal file
338
lib/presentation/modules/screens/product_import_view.dart
Normal file
@@ -0,0 +1,338 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/product.dart';
|
||||
import '../../pos/providers/catalog_providers.dart';
|
||||
import '../../pos/providers/navigation_provider.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../widgets/module_widgets.dart';
|
||||
|
||||
/// Pulls the catalogue onto the terminal.
|
||||
///
|
||||
/// This is the first thing a cashier does at the start of a session — until it
|
||||
/// succeeds there is nothing to bill. Once imported, everything runs locally.
|
||||
class ProductImportView extends ConsumerWidget {
|
||||
const ProductImportView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(catalogueImportProvider);
|
||||
final ready = ref.watch(catalogueReadyProvider);
|
||||
final lastImport = ref.watch(lastImportAtProvider);
|
||||
final products = ref.watch(allProductsProvider).value ?? const <Product>[];
|
||||
final revision = ref.watch(syncRepositoryProvider).catalogueRevision;
|
||||
|
||||
return ModulePage(
|
||||
children: [
|
||||
if (!ready) _NotImportedBanner(state: state),
|
||||
|
||||
if (ready) ...[
|
||||
Wrap(
|
||||
spacing: AppSpacing.lg,
|
||||
runSpacing: AppSpacing.lg,
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Products Loaded',
|
||||
value: '${products.length}',
|
||||
icon: Icons.inventory_2_rounded,
|
||||
color: AppColors.success,
|
||||
caption: 'available offline',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Catalogue Revision',
|
||||
value: revision ?? '—',
|
||||
icon: Icons.tag_rounded,
|
||||
color: AppColors.info,
|
||||
caption: 'server version',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Last Imported',
|
||||
value: lastImport == null
|
||||
? '—'
|
||||
: Formatters.time(lastImport),
|
||||
icon: Icons.schedule_rounded,
|
||||
caption: lastImport == null
|
||||
? 'never'
|
||||
: Formatters.date(lastImport),
|
||||
),
|
||||
StatTile(
|
||||
label: 'Stock Value',
|
||||
value: Formatters.moneyCompact(
|
||||
products.fold<double>(0, (s, p) => s + p.price * p.stock),
|
||||
),
|
||||
icon: Icons.savings_rounded,
|
||||
color: AppColors.tierGold,
|
||||
caption: 'at selling price',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
|
||||
PanelCard(
|
||||
title: ready ? 'Re-import catalogue' : 'Import catalogue',
|
||||
subtitle: ready
|
||||
? 'Pulls the latest prices and products. Stock already sold on '
|
||||
'this terminal is preserved.'
|
||||
: 'Connect once to load products, then bill offline all day.',
|
||||
child: _ImportPanel(state: state, ready: ready),
|
||||
),
|
||||
|
||||
if (ready) ...[
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
PanelCard(
|
||||
title: 'Imported products',
|
||||
subtitle: '${products.length} items on this terminal',
|
||||
child: ResponsiveTable(
|
||||
columns: const [
|
||||
TableCol('Product', flex: 4),
|
||||
TableCol('SKU', flex: 3, priority: 1),
|
||||
TableCol('Category', flex: 2, priority: 1),
|
||||
TableCol('Price', flex: 2, numeric: true),
|
||||
TableCol('Stock', flex: 2, numeric: true),
|
||||
],
|
||||
rows: products
|
||||
.map((p) => [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(p.emoji,
|
||||
style: const TextStyle(fontSize: 17)),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Flexible(child: Cell(p.name, bold: true)),
|
||||
],
|
||||
),
|
||||
Cell(p.sku, color: AppColors.textTertiary),
|
||||
TagChip(p.category.label,
|
||||
color: AppColors.textSecondary),
|
||||
Cell(Formatters.money(p.price), mono: true, bold: true),
|
||||
TagChip(
|
||||
p.isOutOfStock
|
||||
? 'Out'
|
||||
: '${p.stock.toStringAsFixed(0)} ${p.unit.symbol}',
|
||||
color: p.isOutOfStock
|
||||
? AppColors.danger
|
||||
: (p.isLowStock
|
||||
? AppColors.warning
|
||||
: AppColors.success),
|
||||
),
|
||||
])
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NotImportedBanner extends StatelessWidget {
|
||||
const _NotImportedBanner({required this.state});
|
||||
|
||||
final ImportState state;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.lg),
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.warningSurface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(color: AppColors.warning.withValues(alpha: 0.35)),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.cloud_download_outlined,
|
||||
color: AppColors.warning, size: 22),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
const Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'No catalogue on this terminal',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
'Billing is disabled until products are imported. This is '
|
||||
'the only step that needs a connection at the start of a '
|
||||
'shift.',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.textSecondary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ImportPanel extends ConsumerWidget {
|
||||
const _ImportPanel({required this.state, required this.ready});
|
||||
|
||||
final ImportState state;
|
||||
final bool ready;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final running = state is ImportRunning;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (state is ImportRunning) ...[
|
||||
Text(
|
||||
(state as ImportRunning).stage,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
ClipRRect(
|
||||
borderRadius: AppRadius.brPill,
|
||||
child: LinearProgressIndicator(
|
||||
value: (state as ImportRunning).progress,
|
||||
minHeight: 8,
|
||||
backgroundColor: AppColors.divider,
|
||||
valueColor:
|
||||
const AlwaysStoppedAnimation<Color>(AppColors.primary),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
|
||||
if (state is ImportFailed) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dangerSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.wifi_off_rounded,
|
||||
color: AppColors.danger, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
(state as ImportFailed).message,
|
||||
style: const TextStyle(
|
||||
color: AppColors.danger,
|
||||
fontSize: 13,
|
||||
height: 1.45,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
if (state is ImportDone) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle_outline_rounded,
|
||||
color: AppColors.success, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
(state as ImportDone).event.summary,
|
||||
style: const TextStyle(
|
||||
color: AppColors.success,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// Wrap so the buttons stack rather than overflow on a narrow panel.
|
||||
Wrap(
|
||||
spacing: AppSpacing.md,
|
||||
runSpacing: AppSpacing.md,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 240,
|
||||
child: PrimaryButton(
|
||||
label: ready ? 'Re-import now' : 'Import catalogue',
|
||||
icon: Icons.cloud_download_rounded,
|
||||
large: true,
|
||||
busy: running,
|
||||
onPressed: running
|
||||
? null
|
||||
: () => ref.read(catalogueImportProvider.notifier).run(),
|
||||
),
|
||||
),
|
||||
if (ready && !running)
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: PrimaryButton(
|
||||
label: 'Start billing',
|
||||
icon: Icons.point_of_sale_rounded,
|
||||
large: true,
|
||||
tone: ButtonTone.ghost,
|
||||
onPressed: () => ref
|
||||
.read(activeModuleProvider.notifier)
|
||||
.state = PosModule.pos,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.info_outline_rounded,
|
||||
size: 15, color: AppColors.textTertiary),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
'After this import the terminal works entirely offline. '
|
||||
'Sales, customers and parked bills are held locally and are '
|
||||
'only sent when you push the shift report at sign-out.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textTertiary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
202
lib/presentation/modules/screens/promos_view.dart
Normal file
202
lib/presentation/modules/screens/promos_view.dart
Normal file
@@ -0,0 +1,202 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../widgets/module_widgets.dart';
|
||||
|
||||
/// Discount rules and campaigns.
|
||||
class PromosView extends StatefulWidget {
|
||||
const PromosView({super.key});
|
||||
|
||||
@override
|
||||
State<PromosView> createState() => _PromosViewState();
|
||||
}
|
||||
|
||||
class _PromosViewState extends State<PromosView> {
|
||||
final Set<String> _enabled = {'WEEKEND10', 'DAIRY5', 'FESTIVE'};
|
||||
|
||||
static const _campaigns = [
|
||||
(
|
||||
'WEEKEND10',
|
||||
'Weekend Saver',
|
||||
'10% off bills above ₹500',
|
||||
'Sat–Sun',
|
||||
412,
|
||||
AppColors.primary,
|
||||
),
|
||||
(
|
||||
'DAIRY5',
|
||||
'Dairy Days',
|
||||
'5% off all dairy products',
|
||||
'Ends 31 Aug',
|
||||
286,
|
||||
AppColors.info,
|
||||
),
|
||||
(
|
||||
'FESTIVE',
|
||||
'Festive Bonus',
|
||||
'Double loyalty points',
|
||||
'Ends 15 Sep',
|
||||
178,
|
||||
AppColors.tierGold,
|
||||
),
|
||||
(
|
||||
'NEWCUST',
|
||||
'First Purchase',
|
||||
'₹50 off the first bill',
|
||||
'Always on',
|
||||
94,
|
||||
AppColors.success,
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ModulePage(
|
||||
children: [
|
||||
Wrap(
|
||||
spacing: AppSpacing.lg,
|
||||
runSpacing: AppSpacing.lg,
|
||||
children: [
|
||||
StatTile(
|
||||
label: 'Active Campaigns',
|
||||
value: '${_enabled.length}',
|
||||
icon: Icons.campaign_rounded,
|
||||
caption: 'of ${_campaigns.length} configured',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Redemptions',
|
||||
value: '970',
|
||||
icon: Icons.confirmation_number_rounded,
|
||||
color: AppColors.info,
|
||||
caption: 'this month',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Discount Given',
|
||||
value: '₹48,240',
|
||||
icon: Icons.local_offer_rounded,
|
||||
color: AppColors.warning,
|
||||
caption: '2.6% of sales',
|
||||
),
|
||||
StatTile(
|
||||
label: 'Incremental Sales',
|
||||
value: '₹2.14L',
|
||||
icon: Icons.trending_up_rounded,
|
||||
color: AppColors.success,
|
||||
delta: '+18%',
|
||||
caption: 'attributed',
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
PanelCard(
|
||||
title: 'Campaigns',
|
||||
subtitle: 'Toggle a rule to apply it at the till immediately',
|
||||
action: FilledButton.icon(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add_rounded, size: 18),
|
||||
label: const Text('New campaign'),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
minimumSize: const Size(0, 40),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (final c in _campaigns)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brMd,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
// Wrap prevents collision when the panel is narrow.
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: AppSpacing.md,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 320,
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 38,
|
||||
height: 38,
|
||||
decoration: BoxDecoration(
|
||||
color: c.$6.withValues(alpha: 0.12),
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Icon(Icons.sell_rounded,
|
||||
size: 18, color: c.$6),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
c.$2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
c.$3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TagChip(c.$1, color: c.$6),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
TagChip(c.$4, color: AppColors.textSecondary),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(
|
||||
'${c.$5} used',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Switch(
|
||||
value: _enabled.contains(c.$1),
|
||||
onChanged: (v) => setState(() {
|
||||
if (v) {
|
||||
_enabled.add(c.$1);
|
||||
} else {
|
||||
_enabled.remove(c.$1);
|
||||
}
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
322
lib/presentation/modules/screens/settings_view.dart
Normal file
322
lib/presentation/modules/screens/settings_view.dart
Normal file
@@ -0,0 +1,322 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/store_account.dart';
|
||||
import '../../../domain/entities/sync_event.dart';
|
||||
import '../../auth/providers/auth_controller.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../widgets/module_widgets.dart';
|
||||
|
||||
/// Terminal and store configuration.
|
||||
class SettingsView extends ConsumerStatefulWidget {
|
||||
const SettingsView({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<SettingsView> createState() => _SettingsViewState();
|
||||
}
|
||||
|
||||
class _SettingsViewState extends ConsumerState<SettingsView> {
|
||||
bool _scannerSound = true;
|
||||
bool _autoPrint = true;
|
||||
bool _openDrawer = true;
|
||||
bool _roundOff = true;
|
||||
bool _autoLoyalty = true;
|
||||
bool _offline = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final store = ref.watch(currentStoreProvider);
|
||||
final user = ref.watch(currentUserProvider);
|
||||
|
||||
return ModulePage(
|
||||
children: [
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= 1040;
|
||||
|
||||
final left = Column(
|
||||
children: [
|
||||
_storeCard(store),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_taxCard(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_loyaltyCard(),
|
||||
],
|
||||
);
|
||||
final right = Column(
|
||||
children: [
|
||||
_hardwareCard(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_connectivityCard(),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_staffCard(store, user),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_aboutCard(),
|
||||
],
|
||||
);
|
||||
|
||||
if (!wide) {
|
||||
return Column(
|
||||
children: [left, const SizedBox(height: AppSpacing.lg), right],
|
||||
);
|
||||
}
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: left),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(child: right),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _storeCard(StoreAccount? store) => PanelCard(
|
||||
title: 'Store details',
|
||||
subtitle: 'Printed on every invoice',
|
||||
action: TextButton(onPressed: () {}, child: const Text('Edit')),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_row('Store name', store?.name ?? AppConstants.storeName),
|
||||
_row('Address', store?.address ?? AppConstants.storeAddress),
|
||||
_row('GSTIN', store?.gstin ?? AppConstants.storeGstin, mono: true),
|
||||
_row('Phone', store?.phone ?? AppConstants.storePhone, mono: true),
|
||||
_row('Plan', store?.plan ?? 'Business'),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _taxCard() => PanelCard(
|
||||
title: 'Tax & pricing',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_row(
|
||||
'Default GST slab',
|
||||
Formatters.percent(AppConstants.defaultGstRate),
|
||||
),
|
||||
_row('Prices include tax', 'Yes'),
|
||||
_toggle(
|
||||
'Round bills to nearest rupee',
|
||||
'Shows the adjustment as a Round Off line',
|
||||
_roundOff,
|
||||
(v) => setState(() => _roundOff = v),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _loyaltyCard() => PanelCard(
|
||||
title: 'Loyalty programme',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_row(
|
||||
'Earn rate',
|
||||
'1 point per '
|
||||
'${Formatters.money(AppConstants.loyaltyRupeesPerPoint)}',
|
||||
),
|
||||
_row(
|
||||
'Point value',
|
||||
Formatters.money(AppConstants.loyaltyPointValue),
|
||||
),
|
||||
_toggle(
|
||||
'Apply tier discount automatically',
|
||||
'Silver 2%, Gold 5%, Platinum 8%',
|
||||
_autoLoyalty,
|
||||
(v) => setState(() => _autoLoyalty = v),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _hardwareCard() => PanelCard(
|
||||
title: 'Hardware & peripherals',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_toggle(
|
||||
'Scanner beep',
|
||||
'Audible confirmation on every scan',
|
||||
_scannerSound,
|
||||
(v) => setState(() => _scannerSound = v),
|
||||
),
|
||||
_toggle(
|
||||
'Print receipt automatically',
|
||||
'Sends to the default roll printer with no dialog',
|
||||
_autoPrint,
|
||||
(v) => setState(() => _autoPrint = v),
|
||||
),
|
||||
_toggle(
|
||||
'Open cash drawer on cash sales',
|
||||
'Sends the ESC/POS kick pulse',
|
||||
_openDrawer,
|
||||
(v) => setState(() => _openDrawer = v),
|
||||
),
|
||||
const Divider(height: AppSpacing.xxl),
|
||||
_row('Receipt printer', 'EPSON TM-T82 (default)'),
|
||||
_row('Barcode scanner', 'Keyboard wedge · detected'),
|
||||
_row('Cash drawer', 'Connected via printer'),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _staffCard(StoreAccount? store, StaffUser? current) => PanelCard(
|
||||
title: 'Users & roles',
|
||||
action: TextButton(onPressed: () {}, child: const Text('Manage')),
|
||||
child: ResponsiveTable(
|
||||
stackBelow: 360,
|
||||
columns: const [
|
||||
TableCol('Name', flex: 3),
|
||||
TableCol('Role', flex: 3),
|
||||
TableCol('', flex: 2, numeric: true),
|
||||
],
|
||||
rows: (store?.staff ?? const <StaffUser>[])
|
||||
.map((s) => [
|
||||
Cell(s.name, bold: true),
|
||||
Cell(s.role.label, color: AppColors.textSecondary),
|
||||
s.id == current?.id
|
||||
? const TagChip('Signed in',
|
||||
color: AppColors.success)
|
||||
: const SizedBox.shrink(),
|
||||
])
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _connectivityCard() {
|
||||
final ready = ref.watch(catalogueReadyProvider);
|
||||
final lastImport = ref.watch(lastImportAtProvider);
|
||||
final outstanding = ref
|
||||
.watch(syncEventsProvider)
|
||||
.where((e) => e.status != SyncStatus.synced)
|
||||
.length;
|
||||
|
||||
return PanelCard(
|
||||
title: 'Connectivity & sync',
|
||||
subtitle: 'This terminal only needs a connection to import the '
|
||||
'catalogue and to push the shift report.',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_row('Catalogue', ready ? 'Loaded' : 'Not imported'),
|
||||
_row(
|
||||
'Last import',
|
||||
lastImport == null ? 'Never' : Formatters.dateTime(lastImport),
|
||||
),
|
||||
_row('Outstanding pushes', '$outstanding'),
|
||||
_toggle(
|
||||
'Simulate offline',
|
||||
'Forces import and push to fail, so you can confirm nothing is '
|
||||
'lost when the network drops',
|
||||
_offline,
|
||||
(v) {
|
||||
setState(() => _offline = v);
|
||||
ref.read(remoteCatalogueProvider).simulateOffline = v;
|
||||
ref.read(remoteReportSinkProvider).simulateOffline = v;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _aboutCard() => PanelCard(
|
||||
title: 'About',
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_row('Application', '${AppConstants.appName} 1.0.0'),
|
||||
_row('Terminal', 'TERM-01'),
|
||||
_row('Data store', 'Local — offline first'),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.sync_rounded, size: 17),
|
||||
label: const Text('Check for updates'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _row(String label, String value, {bool mono = false}) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.sm),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 148,
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
textAlign: TextAlign.right,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
fontFamily: mono ? 'monospace' : null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _toggle(
|
||||
String title,
|
||||
String subtitle,
|
||||
bool value,
|
||||
ValueChanged<bool> onChanged,
|
||||
) =>
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Switch(value: value, onChanged: onChanged),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
580
lib/presentation/modules/widgets/module_widgets.dart
Normal file
580
lib/presentation/modules/widgets/module_widgets.dart
Normal file
@@ -0,0 +1,580 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
|
||||
/// Scrollable page body shared by every module screen.
|
||||
///
|
||||
/// Always scrolls vertically, so no module can overflow no matter how short
|
||||
/// the viewport gets.
|
||||
class ModulePage extends StatelessWidget {
|
||||
const ModulePage({
|
||||
super.key,
|
||||
required this.children,
|
||||
this.padding = AppSpacing.xxl,
|
||||
});
|
||||
|
||||
final List<Widget> children;
|
||||
final double padding;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
padding: EdgeInsets.all(padding),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// KPI card. Designed to sit inside a [Wrap] so it reflows instead of
|
||||
/// overflowing when the window narrows.
|
||||
class StatTile extends StatelessWidget {
|
||||
const StatTile({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.icon,
|
||||
this.color = AppColors.primary,
|
||||
this.delta,
|
||||
this.deltaPositive = true,
|
||||
this.caption,
|
||||
this.width = 232,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final String? delta;
|
||||
final bool deltaPositive;
|
||||
final String? caption;
|
||||
final double width;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: width,
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 34,
|
||||
height: 34,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.12),
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Icon(icon, size: 17, color: color),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(value, style: AppTypography.money(24)),
|
||||
),
|
||||
if (delta != null || caption != null) ...[
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Row(
|
||||
children: [
|
||||
if (delta != null) ...[
|
||||
Icon(
|
||||
deltaPositive
|
||||
? Icons.trending_up_rounded
|
||||
: Icons.trending_down_rounded,
|
||||
size: 14,
|
||||
color:
|
||||
deltaPositive ? AppColors.success : AppColors.danger,
|
||||
),
|
||||
const SizedBox(width: 3),
|
||||
Text(
|
||||
delta!,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color:
|
||||
deltaPositive ? AppColors.success : AppColors.danger,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
],
|
||||
if (caption != null)
|
||||
Expanded(
|
||||
child: Text(
|
||||
caption!,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Titled container for a block of module content.
|
||||
class PanelCard extends StatelessWidget {
|
||||
const PanelCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.child,
|
||||
this.subtitle,
|
||||
this.action,
|
||||
this.padding = AppSpacing.lg,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final Widget child;
|
||||
final String? subtitle;
|
||||
final Widget? action;
|
||||
final double padding;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(padding, padding, padding, AppSpacing.md),
|
||||
// Wrap so a long title plus an action never collide.
|
||||
child: Wrap(
|
||||
alignment: WrapAlignment.spaceBetween,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: AppSpacing.md,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 15.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
if (subtitle != null)
|
||||
Text(
|
||||
subtitle!,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (action != null) action!,
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
Padding(padding: EdgeInsets.all(padding), child: child),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One column of a [ResponsiveTable].
|
||||
class TableCol {
|
||||
const TableCol(
|
||||
this.label, {
|
||||
this.flex = 2,
|
||||
this.numeric = false,
|
||||
this.priority = 0,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final int flex;
|
||||
final bool numeric;
|
||||
|
||||
/// Higher numbers are dropped first as the table narrows.
|
||||
final int priority;
|
||||
}
|
||||
|
||||
/// Table that degrades into stacked cards rather than overflowing.
|
||||
///
|
||||
/// Above [stackBelow] it renders as aligned columns; below, each row becomes a
|
||||
/// label/value card. Low-priority columns are hidden at intermediate widths.
|
||||
class ResponsiveTable extends StatelessWidget {
|
||||
const ResponsiveTable({
|
||||
super.key,
|
||||
required this.columns,
|
||||
required this.rows,
|
||||
this.stackBelow = 620,
|
||||
this.hideSecondaryBelow = 900,
|
||||
this.onRowTap,
|
||||
});
|
||||
|
||||
final List<TableCol> columns;
|
||||
|
||||
/// Each row must supply exactly one cell per column.
|
||||
final List<List<Widget>> rows;
|
||||
|
||||
final double stackBelow;
|
||||
final double hideSecondaryBelow;
|
||||
final void Function(int index)? onRowTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (rows.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: AppSpacing.xxl),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Nothing to show yet.',
|
||||
style: TextStyle(color: AppColors.textTertiary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final w = constraints.maxWidth;
|
||||
|
||||
if (w < stackBelow) return _stacked();
|
||||
|
||||
final visible = <int>[
|
||||
for (var i = 0; i < columns.length; i++)
|
||||
if (w >= hideSecondaryBelow || columns[i].priority == 0) i,
|
||||
];
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final i in visible)
|
||||
Expanded(
|
||||
flex: columns[i].flex,
|
||||
child: Text(
|
||||
columns[i].label.toUpperCase(),
|
||||
textAlign:
|
||||
columns[i].numeric ? TextAlign.right : TextAlign.left,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: AppTypography.sectionLabel(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
for (var r = 0; r < rows.length; r++)
|
||||
InkWell(
|
||||
onTap: onRowTap == null ? null : () => onRowTap!(r),
|
||||
borderRadius: AppRadius.brXs,
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: AppSpacing.md),
|
||||
decoration: const BoxDecoration(
|
||||
border:
|
||||
Border(bottom: BorderSide(color: AppColors.divider)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
for (final i in visible)
|
||||
Expanded(
|
||||
flex: columns[i].flex,
|
||||
child: Align(
|
||||
alignment: columns[i].numeric
|
||||
? Alignment.centerRight
|
||||
: Alignment.centerLeft,
|
||||
child: rows[r][i],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _stacked() {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (var r = 0; r < rows.length; r++)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brSm,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (var c = 0; c < columns.length; c++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 104,
|
||||
child: Text(
|
||||
columns[c].label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: rows[r][c],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Plain text cell.
|
||||
class Cell extends StatelessWidget {
|
||||
const Cell(
|
||||
this.text, {
|
||||
super.key,
|
||||
this.bold = false,
|
||||
this.color,
|
||||
this.mono = false,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final bool bold;
|
||||
final Color? color;
|
||||
final bool mono;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text(
|
||||
text,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: mono
|
||||
? AppTypography.money(13.5,
|
||||
weight: bold ? FontWeight.w700 : FontWeight.w500, color: color)
|
||||
: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: bold ? FontWeight.w600 : FontWeight.w400,
|
||||
color: color ?? AppColors.textPrimary,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Small coloured status label.
|
||||
class TagChip extends StatelessWidget {
|
||||
const TagChip(this.label, {super.key, this.color = AppColors.primary});
|
||||
|
||||
final String label;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.sm, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withValues(alpha: 0.12),
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Lightweight bar chart painted in code, so no charting dependency is needed.
|
||||
class MiniBarChart extends StatelessWidget {
|
||||
const MiniBarChart({
|
||||
super.key,
|
||||
required this.values,
|
||||
required this.labels,
|
||||
this.height = 180,
|
||||
this.color = AppColors.primary,
|
||||
});
|
||||
|
||||
final List<double> values;
|
||||
final List<String> labels;
|
||||
final double height;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (values.isEmpty) return SizedBox(height: height);
|
||||
final max = values.reduce((a, b) => a > b ? a : b);
|
||||
|
||||
return SizedBox(
|
||||
height: height,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
// Labels are dropped rather than squeezed when space is tight.
|
||||
final showLabels = constraints.maxWidth / values.length >= 28;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
for (var i = 0; i < values.length; i++)
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Expanded(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.bottomCenter,
|
||||
heightFactor:
|
||||
max <= 0 ? 0 : (values[i] / max).clamp(0.03, 1),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
color,
|
||||
color.withValues(alpha: 0.45),
|
||||
],
|
||||
),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(5),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showLabels) ...[
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
labels[i],
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.clip,
|
||||
style: const TextStyle(
|
||||
fontSize: 10.5,
|
||||
color: AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Horizontal proportion bar used for breakdowns.
|
||||
class ProgressRow extends StatelessWidget {
|
||||
const ProgressRow({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.fraction,
|
||||
this.color = AppColors.primary,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
final double fraction;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.sm),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(value, style: AppTypography.money(13)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
ClipRRect(
|
||||
borderRadius: AppRadius.brPill,
|
||||
child: LinearProgressIndicator(
|
||||
value: fraction.clamp(0, 1),
|
||||
minHeight: 6,
|
||||
backgroundColor: AppColors.divider,
|
||||
valueColor: AlwaysStoppedAnimation(color),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
187
lib/presentation/payment/providers/payment_controller.dart
Normal file
187
lib/presentation/payment/providers/payment_controller.dart
Normal file
@@ -0,0 +1,187 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../../domain/usecases/checkout_sale.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../../pos/providers/catalog_providers.dart';
|
||||
|
||||
/// UI state for the payment screen.
|
||||
class PaymentState {
|
||||
const PaymentState({
|
||||
this.splits = const [],
|
||||
this.activeMethod = PaymentMethod.cash,
|
||||
this.cashTendered = 0,
|
||||
this.reference = '',
|
||||
this.isProcessing = false,
|
||||
this.error,
|
||||
this.result,
|
||||
});
|
||||
|
||||
final List<PaymentSplit> splits;
|
||||
final PaymentMethod activeMethod;
|
||||
final double cashTendered;
|
||||
final String reference;
|
||||
final bool isProcessing;
|
||||
final String? error;
|
||||
final CheckoutResult? result;
|
||||
|
||||
double get settled =>
|
||||
splits.fold(0.0, (sum, s) => sum + s.amount).asMoney;
|
||||
|
||||
bool get isComplete => result != null;
|
||||
|
||||
PaymentState copyWith({
|
||||
List<PaymentSplit>? splits,
|
||||
PaymentMethod? activeMethod,
|
||||
double? cashTendered,
|
||||
String? reference,
|
||||
bool? isProcessing,
|
||||
String? error,
|
||||
bool clearError = false,
|
||||
CheckoutResult? result,
|
||||
}) {
|
||||
return PaymentState(
|
||||
splits: splits ?? this.splits,
|
||||
activeMethod: activeMethod ?? this.activeMethod,
|
||||
cashTendered: cashTendered ?? this.cashTendered,
|
||||
reference: reference ?? this.reference,
|
||||
isProcessing: isProcessing ?? this.isProcessing,
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
result: result ?? this.result,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PaymentController extends StateNotifier<PaymentState> {
|
||||
PaymentController(this._ref) : super(const PaymentState());
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
double get _billTotal => _ref.read(cartControllerProvider).grandTotal;
|
||||
|
||||
/// Amount still outstanding after the tenders recorded so far.
|
||||
double get balanceDue =>
|
||||
(_billTotal - state.settled).clamp(0, double.infinity);
|
||||
|
||||
double get changeDue {
|
||||
if (!state.activeMethod.needsChange) return 0;
|
||||
final diff = state.cashTendered - balanceDue;
|
||||
return diff > 0 ? diff.asMoney : 0;
|
||||
}
|
||||
|
||||
bool get canConfirm {
|
||||
if (state.activeMethod.needsChange) {
|
||||
return state.cashTendered >= balanceDue && balanceDue > 0;
|
||||
}
|
||||
return balanceDue > 0;
|
||||
}
|
||||
|
||||
void selectMethod(PaymentMethod method) {
|
||||
state = state.copyWith(
|
||||
activeMethod: method,
|
||||
cashTendered: 0,
|
||||
reference: '',
|
||||
clearError: true,
|
||||
);
|
||||
}
|
||||
|
||||
void setCashTendered(double amount) =>
|
||||
state = state.copyWith(cashTendered: amount, clearError: true);
|
||||
|
||||
/// Adds to the tendered amount — powers the quick-cash denomination chips.
|
||||
void addCash(double amount) => setCashTendered(state.cashTendered + amount);
|
||||
|
||||
/// Fills the exact balance, the most common cash case.
|
||||
void tenderExact() => setCashTendered(balanceDue);
|
||||
|
||||
void setReference(String value) =>
|
||||
state = state.copyWith(reference: value, clearError: true);
|
||||
|
||||
/// Records the active tender. For a split payment, call this once per part.
|
||||
void addSplit({double? amount}) {
|
||||
final value = (amount ?? balanceDue).clamp(0, balanceDue).toDouble();
|
||||
if (value <= 0) return;
|
||||
|
||||
final split = PaymentSplit(
|
||||
method: state.activeMethod,
|
||||
amount: value.asMoney,
|
||||
tendered: state.activeMethod.needsChange
|
||||
? (state.cashTendered > 0 ? state.cashTendered : value)
|
||||
: null,
|
||||
reference: state.reference.trim().isEmpty ? null : state.reference.trim(),
|
||||
);
|
||||
|
||||
state = state.copyWith(
|
||||
splits: [...state.splits, split],
|
||||
cashTendered: 0,
|
||||
reference: '',
|
||||
clearError: true,
|
||||
);
|
||||
}
|
||||
|
||||
void removeSplit(int index) {
|
||||
final next = [...state.splits]..removeAt(index);
|
||||
state = state.copyWith(splits: next);
|
||||
}
|
||||
|
||||
void clearSplits() => state = state.copyWith(splits: const []);
|
||||
|
||||
/// Finalises the sale. On success the caller navigates to the receipt.
|
||||
Future<CheckoutResult?> confirm() async {
|
||||
if (state.isProcessing) return null;
|
||||
|
||||
// A single-tender sale needn't be staged first — fold it in automatically.
|
||||
var splits = state.splits;
|
||||
if (splits.isEmpty || balanceDue > 0.01) {
|
||||
addSplit();
|
||||
splits = state.splits;
|
||||
}
|
||||
|
||||
state = state.copyWith(isProcessing: true, clearError: true);
|
||||
|
||||
try {
|
||||
final cart = _ref.read(cartControllerProvider);
|
||||
final session = _ref.read(cashierSessionProvider);
|
||||
|
||||
final result = await _ref.read(checkoutSaleProvider)(
|
||||
cart: cart,
|
||||
payments: splits,
|
||||
cashierName: session.name,
|
||||
);
|
||||
|
||||
state = state.copyWith(isProcessing: false, result: result);
|
||||
|
||||
// Fire and forget — printing must never block the next sale.
|
||||
final receipts = _ref.read(receiptServiceProvider);
|
||||
unawaited(receipts.printDirect(result.transaction));
|
||||
unawaited(receipts.openCashDrawer());
|
||||
unawaited(_ref.read(soundServiceProvider).saleComplete());
|
||||
|
||||
// Stock changed, so the grid must refresh.
|
||||
_ref.invalidate(allProductsProvider);
|
||||
_ref.invalidate(visibleProductsProvider);
|
||||
|
||||
return result;
|
||||
} on CheckoutFailure catch (e) {
|
||||
state = state.copyWith(isProcessing: false, error: e.message);
|
||||
return null;
|
||||
} catch (e) {
|
||||
state = state.copyWith(
|
||||
isProcessing: false,
|
||||
error: 'Could not complete the sale. $e',
|
||||
);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void reset() => state = const PaymentState();
|
||||
}
|
||||
|
||||
final paymentControllerProvider =
|
||||
StateNotifierProvider.autoDispose<PaymentController, PaymentState>(
|
||||
(ref) => PaymentController(ref),
|
||||
);
|
||||
511
lib/presentation/payment/screens/payment_screen.dart
Normal file
511
lib/presentation/payment/screens/payment_screen.dart
Normal file
@@ -0,0 +1,511 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/glass_card.dart';
|
||||
import '../../../core/widgets/numeric_keypad.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../providers/payment_controller.dart';
|
||||
|
||||
class PaymentScreen extends ConsumerStatefulWidget {
|
||||
const PaymentScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<PaymentScreen> createState() => _PaymentScreenState();
|
||||
}
|
||||
|
||||
class _PaymentScreenState extends ConsumerState<PaymentScreen> {
|
||||
String _cashBuffer = '';
|
||||
|
||||
void _syncCash() {
|
||||
final value = double.tryParse(_cashBuffer) ?? 0;
|
||||
ref.read(paymentControllerProvider.notifier).setCashTendered(value);
|
||||
}
|
||||
|
||||
void _appendCash(String d) {
|
||||
if (d == '.' && _cashBuffer.contains('.')) return;
|
||||
if (_cashBuffer.length >= 8) return;
|
||||
setState(() => _cashBuffer += d);
|
||||
_syncCash();
|
||||
}
|
||||
|
||||
void _backspaceCash() {
|
||||
if (_cashBuffer.isEmpty) return;
|
||||
setState(() => _cashBuffer = _cashBuffer.substring(0, _cashBuffer.length - 1));
|
||||
_syncCash();
|
||||
}
|
||||
|
||||
void _setCash(double value) {
|
||||
setState(() => _cashBuffer = value.toStringAsFixed(0));
|
||||
_syncCash();
|
||||
}
|
||||
|
||||
Future<void> _confirm() async {
|
||||
final result = await ref.read(paymentControllerProvider.notifier).confirm();
|
||||
if (result == null || !mounted) return;
|
||||
|
||||
// Sale is banked — clear the terminal and show the receipt.
|
||||
ref.read(cartControllerProvider.notifier).reset();
|
||||
context.go(AppRoutes.receipt, extra: result.transaction);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cart = ref.watch(cartControllerProvider);
|
||||
final state = ref.watch(paymentControllerProvider);
|
||||
final controller = ref.read(paymentControllerProvider.notifier);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
title: const Text('Payment'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: context.isCompact
|
||||
? SingleChildScrollView(
|
||||
child: Column(children: [
|
||||
_amountCard(controller, state),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_methodsCard(controller, state),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_tenderCard(controller, state),
|
||||
]),
|
||||
)
|
||||
: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: Column(children: [
|
||||
_amountCard(controller, state),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Expanded(child: _methodsCard(controller, state)),
|
||||
]),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(flex: 5, child: _tenderCard(controller, state)),
|
||||
],
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xxl,
|
||||
0,
|
||||
AppSpacing.xxl,
|
||||
AppSpacing.xxl,
|
||||
),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
if (state.error != null) ...[
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dangerSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(children: [
|
||||
const Icon(Icons.error_outline_rounded,
|
||||
color: AppColors.danger, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(state.error!,
|
||||
style: const TextStyle(color: AppColors.danger)),
|
||||
),
|
||||
]),
|
||||
).animate().shake(duration: 300.ms, hz: 3),
|
||||
],
|
||||
PrimaryButton(
|
||||
label: 'Complete Sale',
|
||||
icon: Icons.check_circle_outline_rounded,
|
||||
large: true,
|
||||
tone: ButtonTone.success,
|
||||
busy: state.isProcessing,
|
||||
onPressed: cart.isEmpty ? null : _confirm,
|
||||
trailing: Text(
|
||||
Formatters.money(cart.grandTotal),
|
||||
style: AppTypography.money(21, color: Colors.white),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- Sections
|
||||
Widget _amountCard(PaymentController controller, PaymentState state) {
|
||||
final cart = ref.watch(cartControllerProvider);
|
||||
|
||||
return GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
radius: AppRadius.xl,
|
||||
tinted: true,
|
||||
child: Column(children: [
|
||||
Text('Amount due', style: context.text.labelMedium),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
Formatters.money(controller.balanceDue),
|
||||
style: AppTypography.money(40, color: AppColors.primary),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
|
||||
_mini('Items', '${cart.lineCount}'),
|
||||
_dot(),
|
||||
_mini('Bill total', Formatters.money(cart.grandTotal)),
|
||||
if (state.settled > 0) ...[
|
||||
_dot(),
|
||||
_mini('Settled', Formatters.money(state.settled)),
|
||||
],
|
||||
]),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _methodsCard(PaymentController controller, PaymentState state) {
|
||||
return GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xl),
|
||||
radius: AppRadius.xl,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Payment method', style: context.text.titleMedium),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Wrap(
|
||||
spacing: AppSpacing.md,
|
||||
runSpacing: AppSpacing.md,
|
||||
children: PaymentMethod.values
|
||||
.where((m) => m != PaymentMethod.loyalty)
|
||||
.map((m) => _MethodTile(
|
||||
method: m,
|
||||
selected: state.activeMethod == m,
|
||||
onTap: () {
|
||||
setState(() => _cashBuffer = '');
|
||||
controller.selectMethod(m);
|
||||
},
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
|
||||
if (state.splits.isNotEmpty) ...[
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
const Divider(),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Row(children: [
|
||||
Text('Split tenders', style: context.text.titleSmall),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: controller.clearSplits,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.danger),
|
||||
child: const Text('Clear all'),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
...state.splits.asMap().entries.map((e) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
child: Row(children: [
|
||||
Text(e.value.method.emoji,
|
||||
style: const TextStyle(fontSize: 16)),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(child: Text(e.value.method.label)),
|
||||
Text(Formatters.money(e.value.amount),
|
||||
style: AppTypography.money(14.5)),
|
||||
IconButton(
|
||||
onPressed: () => controller.removeSplit(e.key),
|
||||
icon: const Icon(Icons.close_rounded, size: 17),
|
||||
color: AppColors.textTertiary,
|
||||
constraints:
|
||||
const BoxConstraints(minWidth: 30, minHeight: 30),
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
]),
|
||||
)),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tenderCard(PaymentController controller, PaymentState state) {
|
||||
final isCash = state.activeMethod.needsChange;
|
||||
|
||||
return GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xl),
|
||||
radius: AppRadius.xl,
|
||||
child: isCash
|
||||
? _cashTender(controller, state)
|
||||
: _referenceTender(controller, state),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cashTender(PaymentController controller, PaymentState state) {
|
||||
final change = controller.changeDue;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Cash received', style: context.text.titleMedium),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.lg,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Row(children: [
|
||||
const Text('₹',
|
||||
style: TextStyle(fontSize: 24, color: AppColors.textTertiary)),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_cashBuffer.isEmpty ? '0' : _cashBuffer,
|
||||
style: AppTypography.money(30),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.done_all_rounded, size: 15),
|
||||
label: const Text('Exact'),
|
||||
onPressed: () => _setCash(controller.balanceDue),
|
||||
),
|
||||
...[50, 100, 200, 500, 2000].map(
|
||||
(note) => ActionChip(
|
||||
label: Text('₹$note'),
|
||||
onPressed: () => _setCash(
|
||||
(double.tryParse(_cashBuffer) ?? 0) + note,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
AnimatedContainer(
|
||||
duration: AppMotion.normal,
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: change > 0
|
||||
? AppColors.successSurface
|
||||
: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brMd,
|
||||
),
|
||||
child: Row(children: [
|
||||
Icon(
|
||||
change > 0
|
||||
? Icons.currency_exchange_rounded
|
||||
: Icons.info_outline_rounded,
|
||||
size: 19,
|
||||
color: change > 0 ? AppColors.success : AppColors.textTertiary,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Text(
|
||||
'Change to return',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: change > 0
|
||||
? AppColors.success
|
||||
: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
Formatters.money(change),
|
||||
style: AppTypography.money(
|
||||
22,
|
||||
color: change > 0 ? AppColors.success : AppColors.textTertiary,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Center(
|
||||
child: NumericKeypad(
|
||||
allowDecimal: true,
|
||||
maxWidth: 330,
|
||||
onKey: _appendCash,
|
||||
onBackspace: _backspaceCash,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
OutlinedButton.icon(
|
||||
onPressed: controller.balanceDue > 0
|
||||
? () {
|
||||
controller.addSplit(
|
||||
amount: (double.tryParse(_cashBuffer) ?? 0)
|
||||
.clamp(0, controller.balanceDue)
|
||||
.toDouble(),
|
||||
);
|
||||
setState(() => _cashBuffer = '');
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.call_split_rounded, size: 17),
|
||||
label: const Text('Add as split payment'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _referenceTender(PaymentController controller, PaymentState state) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Row(children: [
|
||||
Text(state.activeMethod.emoji, style: const TextStyle(fontSize: 22)),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text('${state.activeMethod.label} payment',
|
||||
style: context.text.titleMedium),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
|
||||
Center(
|
||||
child: Column(children: [
|
||||
Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brXl,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(state.activeMethod.emoji,
|
||||
style: const TextStyle(fontSize: 52)),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Text(
|
||||
'Charge ${Formatters.money(controller.balanceDue)} '
|
||||
'on the ${state.activeMethod.label.toLowerCase()} terminal',
|
||||
textAlign: TextAlign.center,
|
||||
style: context.text.bodyMedium,
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
if (state.activeMethod.needsReference)
|
||||
TextField(
|
||||
onChanged: controller.setReference,
|
||||
decoration: InputDecoration(
|
||||
labelText: switch (state.activeMethod) {
|
||||
PaymentMethod.card => 'Approval code',
|
||||
PaymentMethod.upi => 'UPI transaction ID',
|
||||
PaymentMethod.giftCard => 'Gift card number',
|
||||
_ => 'Reference',
|
||||
},
|
||||
prefixIcon: const Icon(Icons.tag_rounded),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xxxl),
|
||||
OutlinedButton.icon(
|
||||
onPressed: controller.balanceDue > 0
|
||||
? () => controller.addSplit()
|
||||
: null,
|
||||
icon: const Icon(Icons.call_split_rounded, size: 17),
|
||||
label: const Text('Add as split payment'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mini(String label, String value) => Column(children: [
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: AppColors.textSecondary,
|
||||
)),
|
||||
Text(value,
|
||||
style: AppTypography.money(14, weight: FontWeight.w600)),
|
||||
]);
|
||||
|
||||
Widget _dot() => Container(
|
||||
width: 3,
|
||||
height: 3,
|
||||
margin: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.textTertiary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _MethodTile extends StatelessWidget {
|
||||
const _MethodTile({
|
||||
required this.method,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final PaymentMethod method;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: selected ? AppColors.primary : AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brMd,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: AppRadius.brMd,
|
||||
child: AnimatedContainer(
|
||||
duration: AppMotion.fast,
|
||||
width: 118,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.lg,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: AppRadius.brMd,
|
||||
border: Border.all(
|
||||
color: selected ? AppColors.primary : AppColors.border,
|
||||
),
|
||||
),
|
||||
child: Column(children: [
|
||||
Text(method.emoji, style: const TextStyle(fontSize: 24)),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
method.label,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected ? Colors.white : AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
307
lib/presentation/pos/providers/cart_controller.dart
Normal file
307
lib/presentation/pos/providers/cart_controller.dart
Normal file
@@ -0,0 +1,307 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/services/sound_service.dart';
|
||||
import '../../../domain/entities/cart.dart';
|
||||
import '../../../domain/entities/customer.dart';
|
||||
import '../../../domain/entities/product.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../../domain/repositories/product_repository.dart';
|
||||
import '../../../domain/repositories/transaction_repository.dart';
|
||||
|
||||
/// Transient feedback for the scan toast — never a blocking dialog.
|
||||
enum ScanOutcome { added, incremented, notFound, outOfStock }
|
||||
|
||||
class ScanFeedback {
|
||||
const ScanFeedback({
|
||||
required this.outcome,
|
||||
required this.stamp,
|
||||
this.product,
|
||||
this.message,
|
||||
});
|
||||
|
||||
final ScanOutcome outcome;
|
||||
final DateTime stamp;
|
||||
final Product? product;
|
||||
final String? message;
|
||||
|
||||
bool get isSuccess =>
|
||||
outcome == ScanOutcome.added || outcome == ScanOutcome.incremented;
|
||||
}
|
||||
|
||||
/// Owns the live bill.
|
||||
///
|
||||
/// All mutations funnel through here so that scanner input, product taps and
|
||||
/// keyboard shortcuts share one code path and one set of guarantees.
|
||||
class CartController extends StateNotifier<Cart> {
|
||||
CartController({
|
||||
required ProductRepository products,
|
||||
required TransactionRepository transactions,
|
||||
required SoundService sound,
|
||||
required this.onFeedback,
|
||||
}) : _products = products,
|
||||
_transactions = transactions,
|
||||
_sound = sound,
|
||||
super(Cart.empty);
|
||||
|
||||
final ProductRepository _products;
|
||||
final TransactionRepository _transactions;
|
||||
final SoundService _sound;
|
||||
final void Function(ScanFeedback) onFeedback;
|
||||
|
||||
static const _uuid = Uuid();
|
||||
|
||||
/// Snapshots for undo — capped so memory can't grow unbounded on a terminal
|
||||
/// that runs for days.
|
||||
final List<Cart> _undoStack = [];
|
||||
static const int _maxUndo = 25;
|
||||
|
||||
bool get canUndo => _undoStack.isNotEmpty;
|
||||
|
||||
void _push() {
|
||||
_undoStack.add(state);
|
||||
if (_undoStack.length > _maxUndo) _undoStack.removeAt(0);
|
||||
}
|
||||
|
||||
void undo() {
|
||||
if (_undoStack.isEmpty) return;
|
||||
state = _undoStack.removeLast();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ Line items
|
||||
/// Adds a product, merging into the existing line when already present.
|
||||
void addProduct(Product product, {double quantity = 1}) {
|
||||
if (product.isOutOfStock) {
|
||||
_sound.scanError();
|
||||
onFeedback(ScanFeedback(
|
||||
outcome: ScanOutcome.outOfStock,
|
||||
stamp: DateTime.now(),
|
||||
product: product,
|
||||
message: '${product.name} is out of stock',
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
_push();
|
||||
|
||||
final existing = state.lineFor(product.id);
|
||||
final requested = (existing?.quantity ?? 0) + quantity;
|
||||
|
||||
if (requested > product.stock) {
|
||||
_undoStack.removeLast();
|
||||
_sound.scanError();
|
||||
onFeedback(ScanFeedback(
|
||||
outcome: ScanOutcome.outOfStock,
|
||||
stamp: DateTime.now(),
|
||||
product: product,
|
||||
message: 'Only ${product.stock.toStringAsFixed(0)} '
|
||||
'${product.unit.symbol} left',
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
if (existing == null) {
|
||||
state = state.copyWith(lines: [
|
||||
...state.lines,
|
||||
CartLine(
|
||||
product: product,
|
||||
quantity: quantity,
|
||||
addedAt: DateTime.now(),
|
||||
),
|
||||
]);
|
||||
} else {
|
||||
state = state.copyWith(
|
||||
lines: _replace(existing.copyWith(quantity: requested)),
|
||||
);
|
||||
}
|
||||
|
||||
_clampRedemption();
|
||||
_sound.scanSuccess();
|
||||
onFeedback(ScanFeedback(
|
||||
outcome: existing == null ? ScanOutcome.added : ScanOutcome.incremented,
|
||||
stamp: DateTime.now(),
|
||||
product: product,
|
||||
));
|
||||
}
|
||||
|
||||
/// Scanner entry point. Resolves the barcode and adds it with no dialogs.
|
||||
Future<void> scanBarcode(String code) async {
|
||||
final product = await _products.findByBarcode(code);
|
||||
|
||||
if (product == null) {
|
||||
_sound.scanError();
|
||||
onFeedback(ScanFeedback(
|
||||
outcome: ScanOutcome.notFound,
|
||||
stamp: DateTime.now(),
|
||||
message: 'No product for barcode $code',
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
addProduct(product);
|
||||
}
|
||||
|
||||
void setQuantity(String productId, double quantity) {
|
||||
final line = state.lineFor(productId);
|
||||
if (line == null) return;
|
||||
|
||||
if (quantity <= 0) {
|
||||
removeLine(productId);
|
||||
return;
|
||||
}
|
||||
|
||||
final capped = quantity
|
||||
.clamp(0, AppConstants.maxCartQuantityPerLine.toDouble())
|
||||
.toDouble();
|
||||
|
||||
if (capped > line.product.stock) {
|
||||
_sound.scanError();
|
||||
onFeedback(ScanFeedback(
|
||||
outcome: ScanOutcome.outOfStock,
|
||||
stamp: DateTime.now(),
|
||||
product: line.product,
|
||||
message: 'Only ${line.product.stock.toStringAsFixed(0)} in stock',
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
_push();
|
||||
state = state.copyWith(lines: _replace(line.copyWith(quantity: capped)));
|
||||
_clampRedemption();
|
||||
}
|
||||
|
||||
void increment(String productId, {double by = 1}) {
|
||||
final line = state.lineFor(productId);
|
||||
if (line == null) return;
|
||||
setQuantity(productId, line.quantity + by);
|
||||
}
|
||||
|
||||
void decrement(String productId, {double by = 1}) {
|
||||
final line = state.lineFor(productId);
|
||||
if (line == null) return;
|
||||
setQuantity(productId, line.quantity - by);
|
||||
}
|
||||
|
||||
void removeLine(String productId) {
|
||||
if (!state.contains(productId)) return;
|
||||
_push();
|
||||
state = state.copyWith(
|
||||
lines: state.lines.where((l) => l.product.id != productId).toList(),
|
||||
);
|
||||
_clampRedemption();
|
||||
}
|
||||
|
||||
void applyLineDiscount(String productId, Discount discount) {
|
||||
final line = state.lineFor(productId);
|
||||
if (line == null) return;
|
||||
_push();
|
||||
state = state.copyWith(lines: _replace(line.copyWith(discount: discount)));
|
||||
_clampRedemption();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ Bill level
|
||||
void applyBillDiscount(Discount discount) {
|
||||
_push();
|
||||
state = state.copyWith(billDiscount: discount);
|
||||
_clampRedemption();
|
||||
}
|
||||
|
||||
void clearBillDiscount() => applyBillDiscount(Discount.none);
|
||||
|
||||
void attachCustomer(Customer? customer) {
|
||||
_push();
|
||||
state = customer == null
|
||||
? state.copyWith(clearCustomer: true, pointsRedeemed: 0)
|
||||
: state.copyWith(customer: customer);
|
||||
_clampRedemption();
|
||||
}
|
||||
|
||||
void redeemPoints(int points) {
|
||||
final max = state.maxRedeemablePoints;
|
||||
_push();
|
||||
state = state.copyWith(pointsRedeemed: points.clamp(0, max));
|
||||
}
|
||||
|
||||
void redeemAllPoints() => redeemPoints(state.maxRedeemablePoints);
|
||||
|
||||
void clearRedemption() => redeemPoints(0);
|
||||
|
||||
void setNote(String? note) => state = state.copyWith(note: note);
|
||||
|
||||
/// Keeps redemption legal after the bill shrinks below the redeemed value.
|
||||
void _clampRedemption() {
|
||||
if (state.pointsRedeemed == 0) return;
|
||||
final max = state.maxRedeemablePoints;
|
||||
if (state.pointsRedeemed > max) {
|
||||
state = state.copyWith(pointsRedeemed: max);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------- Session
|
||||
void clear() {
|
||||
_push();
|
||||
state = Cart.empty;
|
||||
}
|
||||
|
||||
/// Starts a brand new sale, dropping undo history and the customer.
|
||||
void reset() {
|
||||
_undoStack.clear();
|
||||
state = Cart.empty;
|
||||
}
|
||||
|
||||
/// Keeps the customer attached for a follow-up bill.
|
||||
void resetKeepingCustomer() {
|
||||
_undoStack.clear();
|
||||
state = Cart(customer: state.customer);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------- Parked bills
|
||||
Future<void> park({String? label}) async {
|
||||
if (state.isEmpty) return;
|
||||
await _transactions.park(ParkedBill(
|
||||
id: _uuid.v4(),
|
||||
cart: state,
|
||||
parkedAt: DateTime.now(),
|
||||
label: label,
|
||||
));
|
||||
reset();
|
||||
}
|
||||
|
||||
Future<void> resume(ParkedBill bill) async {
|
||||
await _transactions.removeParked(bill.id);
|
||||
_undoStack.clear();
|
||||
state = bill.cart;
|
||||
}
|
||||
|
||||
List<CartLine> _replace(CartLine updated) => [
|
||||
for (final l in state.lines)
|
||||
if (l.product.id == updated.product.id) updated else l,
|
||||
];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- Providers
|
||||
final scanFeedbackProvider = StateProvider<ScanFeedback?>((ref) => null);
|
||||
|
||||
final cartControllerProvider =
|
||||
StateNotifierProvider<CartController, Cart>((ref) {
|
||||
return CartController(
|
||||
products: ref.watch(productRepositoryProvider),
|
||||
transactions: ref.watch(transactionRepositoryProvider),
|
||||
sound: ref.watch(soundServiceProvider),
|
||||
onFeedback: (feedback) =>
|
||||
ref.read(scanFeedbackProvider.notifier).state = feedback,
|
||||
);
|
||||
});
|
||||
|
||||
/// Convenience selectors — each rebuilds only the widget that needs it.
|
||||
final cartTotalProvider =
|
||||
Provider<double>((ref) => ref.watch(cartControllerProvider).grandTotal);
|
||||
|
||||
final cartItemCountProvider =
|
||||
Provider<int>((ref) => ref.watch(cartControllerProvider).lineCount);
|
||||
|
||||
final parkedBillsProvider = FutureProvider<List<ParkedBill>>(
|
||||
(ref) => ref.watch(transactionRepositoryProvider).parkedBills(),
|
||||
);
|
||||
44
lib/presentation/pos/providers/catalog_providers.dart
Normal file
44
lib/presentation/pos/providers/catalog_providers.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../domain/entities/product.dart';
|
||||
|
||||
/// `null` means the "All" chip is selected.
|
||||
final selectedCategoryProvider =
|
||||
StateProvider<ProductCategory?>((ref) => null);
|
||||
|
||||
final searchQueryProvider = StateProvider<String>((ref) => '');
|
||||
|
||||
final allProductsProvider = FutureProvider<List<Product>>(
|
||||
(ref) => ref.watch(productRepositoryProvider).getAll(),
|
||||
);
|
||||
|
||||
/// The grid's data source: category filter and search applied together.
|
||||
final visibleProductsProvider = FutureProvider<List<Product>>((ref) async {
|
||||
final repo = ref.watch(productRepositoryProvider);
|
||||
final query = ref.watch(searchQueryProvider);
|
||||
final category = ref.watch(selectedCategoryProvider);
|
||||
|
||||
final base = query.trim().isEmpty
|
||||
? await repo.getAll()
|
||||
: await repo.search(query);
|
||||
|
||||
if (category == null) return base;
|
||||
return base.where((p) => p.category == category).toList();
|
||||
});
|
||||
|
||||
/// Counts per category for the chip badges.
|
||||
final categoryCountsProvider =
|
||||
FutureProvider<Map<ProductCategory, int>>((ref) async {
|
||||
final products = await ref.watch(allProductsProvider.future);
|
||||
final map = <ProductCategory, int>{};
|
||||
for (final p in products) {
|
||||
map[p.category] = (map[p.category] ?? 0) + 1;
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
final lowStockProductsProvider = FutureProvider<List<Product>>((ref) async {
|
||||
final products = await ref.watch(allProductsProvider.future);
|
||||
return products.where((p) => p.isLowStock || p.isOutOfStock).toList();
|
||||
});
|
||||
44
lib/presentation/pos/providers/navigation_provider.dart
Normal file
44
lib/presentation/pos/providers/navigation_provider.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
/// The modules a cashier needs. Deliberately excludes analytics — this
|
||||
/// terminal is for billing, not back-office reporting.
|
||||
enum PosModule {
|
||||
pos('Point of Sale', 'POS', Icons.point_of_sale_rounded, NavSection.billing),
|
||||
customers('Customers', 'Customers', Icons.people_alt_rounded,
|
||||
NavSection.billing),
|
||||
|
||||
productImport('Product Import', 'Product Import',
|
||||
Icons.cloud_download_rounded, NavSection.catalogue),
|
||||
promos('Promotions', 'Promo', Icons.sell_rounded, NavSection.catalogue),
|
||||
|
||||
events('Events', 'Events', Icons.sync_rounded, NavSection.session),
|
||||
settings('Settings', 'Settings', Icons.settings_rounded, NavSection.session);
|
||||
|
||||
const PosModule(this.title, this.label, this.icon, this.section);
|
||||
|
||||
/// Long form, shown in the page header.
|
||||
final String title;
|
||||
|
||||
/// Short form, shown in the sidebar.
|
||||
final String label;
|
||||
|
||||
final IconData icon;
|
||||
final NavSection section;
|
||||
}
|
||||
|
||||
/// Groups the navigation into labelled blocks.
|
||||
enum NavSection {
|
||||
billing('Billing'),
|
||||
catalogue('Catalogue'),
|
||||
session('Session');
|
||||
|
||||
const NavSection(this.label);
|
||||
|
||||
final String label;
|
||||
|
||||
List<PosModule> get modules =>
|
||||
PosModule.values.where((m) => m.section == this).toList();
|
||||
}
|
||||
|
||||
final activeModuleProvider = StateProvider<PosModule>((ref) => PosModule.pos);
|
||||
171
lib/presentation/pos/screens/pos_dashboard_screen.dart
Normal file
171
lib/presentation/pos/screens/pos_dashboard_screen.dart
Normal file
@@ -0,0 +1,171 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/services/barcode_service.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_layout.dart';
|
||||
import '../../modules/screens/customers_view.dart';
|
||||
import '../../modules/screens/events_view.dart';
|
||||
import '../../modules/screens/product_import_view.dart';
|
||||
import '../../modules/screens/promos_view.dart';
|
||||
import '../../modules/screens/settings_view.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import '../providers/navigation_provider.dart';
|
||||
import '../widgets/app_sidebar.dart';
|
||||
import '../widgets/billing_panel.dart';
|
||||
import '../widgets/cart_fab.dart';
|
||||
import '../widgets/page_header.dart';
|
||||
import 'pos_view.dart';
|
||||
|
||||
/// Application shell.
|
||||
///
|
||||
/// Owns the sidebar, page header and the body for whichever module is active.
|
||||
/// Keeping one shell means navigation never rebuilds the chrome, and the
|
||||
/// scanner stays live across modules.
|
||||
///
|
||||
/// Layout collapses in a fixed order as width shrinks:
|
||||
///
|
||||
/// * `>= 1300` sidebar with labels, docked bill
|
||||
/// * `1120–1300` sidebar as an icon rail, docked bill
|
||||
/// * `920–1120` icon rail, bill becomes a bottom sheet
|
||||
/// * `< 920` sidebar goes off-canvas behind a menu button
|
||||
class PosDashboardScreen extends ConsumerStatefulWidget {
|
||||
const PosDashboardScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<PosDashboardScreen> createState() => _PosDashboardScreenState();
|
||||
}
|
||||
|
||||
class _PosDashboardScreenState extends ConsumerState<PosDashboardScreen> {
|
||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
final FocusNode _searchFocus = FocusNode();
|
||||
late final BarcodeService _barcode;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// The scanner behaves like a keyboard, so listen globally rather than
|
||||
// depending on any one field holding focus. A scan from another module
|
||||
// jumps back to billing, which is what a cashier expects.
|
||||
_barcode = BarcodeService(
|
||||
onScan: (code) {
|
||||
// Without an imported catalogue there is nothing to resolve against.
|
||||
if (!ref.read(catalogueReadyProvider)) return;
|
||||
ref.read(activeModuleProvider.notifier).state = PosModule.pos;
|
||||
ref.read(cartControllerProvider.notifier).scanBarcode(code);
|
||||
},
|
||||
)..attach();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_barcode.dispose();
|
||||
_searchFocus.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _openBillingSheet() {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) => FractionallySizedBox(
|
||||
heightFactor: 0.92,
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(AppRadius.xxl),
|
||||
),
|
||||
child: const BillingPanel(inSheet: true),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _body(PosModule module, PosLayout layout) => switch (module) {
|
||||
PosModule.pos => PosView(layout: layout, searchFocus: _searchFocus),
|
||||
PosModule.customers => const CustomersView(),
|
||||
PosModule.productImport => const ProductImportView(),
|
||||
PosModule.promos => const PromosView(),
|
||||
PosModule.events => const EventsView(),
|
||||
PosModule.settings => const SettingsView(),
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final layout = PosLayout.of(context);
|
||||
final module = ref.watch(activeModuleProvider);
|
||||
final ready = ref.watch(catalogueReadyProvider);
|
||||
final isPos = module == PosModule.pos && ready;
|
||||
|
||||
// Only the terminal itself needs the bill docked beside it.
|
||||
final showDockedBill = isPos && !layout.billingIsSheet;
|
||||
final showCartFab = isPos && layout.billingIsSheet;
|
||||
|
||||
return Scaffold(
|
||||
key: _scaffoldKey,
|
||||
backgroundColor: AppColors.background,
|
||||
drawer: layout.sidebarIsDrawer
|
||||
? Drawer(
|
||||
width: PosLayout.expandedWidth,
|
||||
backgroundColor: AppColors.surface,
|
||||
child: AppSidebar(
|
||||
mode: SidebarMode.expanded,
|
||||
onDestinationTap: () => Navigator.of(context).maybePop(),
|
||||
),
|
||||
)
|
||||
: null,
|
||||
floatingActionButton:
|
||||
showCartFab ? CartFab(onTap: _openBillingSheet) : null,
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
||||
body: CallbackShortcuts(
|
||||
bindings: {
|
||||
const SingleActivator(LogicalKeyboardKey.f2):
|
||||
_searchFocus.requestFocus,
|
||||
const SingleActivator(LogicalKeyboardKey.f8): () =>
|
||||
ref.read(cartControllerProvider.notifier).undo(),
|
||||
const SingleActivator(LogicalKeyboardKey.escape):
|
||||
_searchFocus.unfocus,
|
||||
},
|
||||
child: Focus(
|
||||
autofocus: true,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (!layout.sidebarIsDrawer) AppSidebar(mode: layout.sidebar),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
PageHeader(
|
||||
layout: layout,
|
||||
onMenuTap: () => _scaffoldKey.currentState?.openDrawer(),
|
||||
),
|
||||
Expanded(
|
||||
child: AnimatedSwitcher(
|
||||
duration: AppMotion.fast,
|
||||
child: KeyedSubtree(
|
||||
key: ValueKey(module),
|
||||
child: _body(module, layout),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (showDockedBill) ...[
|
||||
const VerticalDivider(width: 1),
|
||||
SizedBox(
|
||||
width: layout.billingWidth,
|
||||
child: const BillingPanel(),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
197
lib/presentation/pos/screens/pos_view.dart
Normal file
197
lib/presentation/pos/screens/pos_view.dart
Normal file
@@ -0,0 +1,197 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_layout.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../providers/navigation_provider.dart';
|
||||
import '../widgets/category_chips.dart';
|
||||
import '../widgets/customer_bar.dart';
|
||||
import '../widgets/product_grid.dart';
|
||||
import '../widgets/scan_toast.dart';
|
||||
import '../widgets/search_field.dart';
|
||||
|
||||
/// Catalogue half of the terminal.
|
||||
///
|
||||
/// Gated on the catalogue import: with no products loaded there is nothing to
|
||||
/// sell, so the cashier is sent to the import step instead of a broken grid.
|
||||
class PosView extends ConsumerWidget {
|
||||
const PosView({super.key, required this.layout, required this.searchFocus});
|
||||
|
||||
final PosLayout layout;
|
||||
final FocusNode searchFocus;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
if (!ref.watch(catalogueReadyProvider)) {
|
||||
return const _CatalogueRequired();
|
||||
}
|
||||
|
||||
final pad = layout.contentPadding;
|
||||
|
||||
// Keep the last grid row clear of the floating bill button.
|
||||
final bottomInset = layout.billingIsSheet
|
||||
? AppSizes.buttonHeightLarge + AppSpacing.xxxl
|
||||
: AppSpacing.xxl;
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const CustomerBar(),
|
||||
const Divider(height: 1),
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.fromLTRB(pad, AppSpacing.lg, pad, AppSpacing.md),
|
||||
child: PosSearchField(focusNode: searchFocus),
|
||||
),
|
||||
CategoryChips(horizontalPadding: pad),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Expanded(
|
||||
child: ProductGrid(
|
||||
horizontalPadding: pad,
|
||||
tileExtent: layout.gridTileExtent,
|
||||
bottomPadding: bottomInset,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: bottomInset,
|
||||
child: const Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ScanToast(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Shown until the catalogue has been pulled onto this terminal.
|
||||
class _CatalogueRequired extends ConsumerWidget {
|
||||
const _CatalogueRequired();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final state = ref.watch(catalogueImportProvider);
|
||||
final running = state is ImportRunning;
|
||||
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 460),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 96,
|
||||
height: 96,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.cloud_download_outlined,
|
||||
size: 42, color: AppColors.primary),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Text(
|
||||
'Import products to start billing',
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
const Text(
|
||||
'This terminal has no catalogue yet. Pull the current products '
|
||||
'once at the start of your shift — after that everything runs '
|
||||
'offline.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
|
||||
if (running) ...[
|
||||
Text(
|
||||
state.stage,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
ClipRRect(
|
||||
borderRadius: AppRadius.brPill,
|
||||
child: LinearProgressIndicator(
|
||||
value: state.progress,
|
||||
minHeight: 8,
|
||||
backgroundColor: AppColors.divider,
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(
|
||||
AppColors.primary),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
],
|
||||
|
||||
if (state is ImportFailed) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dangerSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.wifi_off_rounded,
|
||||
color: AppColors.danger, size: 18),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.message,
|
||||
style: const TextStyle(
|
||||
color: AppColors.danger,
|
||||
fontSize: 13,
|
||||
height: 1.45,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
PrimaryButton(
|
||||
label: 'Import catalogue now',
|
||||
icon: Icons.cloud_download_rounded,
|
||||
large: true,
|
||||
busy: running,
|
||||
onPressed: running
|
||||
? null
|
||||
: () => ref.read(catalogueImportProvider.notifier).run(),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
TextButton.icon(
|
||||
onPressed: () => ref
|
||||
.read(activeModuleProvider.notifier)
|
||||
.state = PosModule.productImport,
|
||||
icon: const Icon(Icons.open_in_new_rounded, size: 16),
|
||||
label: const Text('Open Product Import'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
485
lib/presentation/pos/widgets/app_sidebar.dart
Normal file
485
lib/presentation/pos/widgets/app_sidebar.dart
Normal file
@@ -0,0 +1,485 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_layout.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/sync_event.dart';
|
||||
import '../../auth/providers/auth_controller.dart';
|
||||
import '../../sync/widgets/sign_out_dialog.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import '../../sync/providers/sync_controller.dart';
|
||||
import '../providers/navigation_provider.dart';
|
||||
|
||||
/// Left navigation rail.
|
||||
///
|
||||
/// Renders in three widths: full labels on desktop, icons only on tablet
|
||||
/// landscape, and off-canvas below that. The same widget serves all three so
|
||||
/// the active state and badges never drift apart.
|
||||
class AppSidebar extends ConsumerWidget {
|
||||
const AppSidebar({
|
||||
super.key,
|
||||
required this.mode,
|
||||
this.onDestinationTap,
|
||||
});
|
||||
|
||||
final SidebarMode mode;
|
||||
|
||||
/// Lets the drawer close itself after a tap.
|
||||
final VoidCallback? onDestinationTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// The drawer presentation uses the expanded layout at full width.
|
||||
final expanded = mode != SidebarMode.rail;
|
||||
final width = mode == SidebarMode.rail
|
||||
? PosLayout.railWidth
|
||||
: PosLayout.expandedWidth;
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: AppMotion.normal,
|
||||
curve: AppMotion.emphasized,
|
||||
width: width,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
border: Border(right: BorderSide(color: AppColors.border)),
|
||||
),
|
||||
child: SafeArea(
|
||||
right: false,
|
||||
child: Column(
|
||||
children: [
|
||||
_Brand(expanded: expanded),
|
||||
const Divider(height: 1),
|
||||
_Profile(expanded: expanded),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.md),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final section in NavSection.values)
|
||||
_Section(
|
||||
section: section,
|
||||
expanded: expanded,
|
||||
onDestinationTap: onDestinationTap,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(height: 1),
|
||||
_LogoutTile(expanded: expanded),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Brand extends StatelessWidget {
|
||||
const _Brand({required this.expanded});
|
||||
|
||||
final bool expanded;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: AppSizes.headerHeight,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: expanded ? AppSpacing.xl : AppSpacing.md,
|
||||
),
|
||||
alignment: expanded ? Alignment.centerLeft : Alignment.center,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.primaryGradient,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
'N',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (expanded) ...[
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Nearle',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: -0.3,
|
||||
color: AppColors.textPrimary,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'POS',
|
||||
style: AppTypography.sectionLabel()
|
||||
.copyWith(color: AppColors.primary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Profile extends ConsumerWidget {
|
||||
const _Profile({required this.expanded});
|
||||
|
||||
final bool expanded;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final user = ref.watch(currentUserProvider);
|
||||
final name = user?.name ?? ref.watch(cashierSessionProvider).name;
|
||||
final role = user?.role.label ?? ref.watch(cashierSessionProvider).role;
|
||||
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: expanded ? AppSpacing.lg : AppSpacing.sm,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
expanded ? MainAxisAlignment.start : MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 38,
|
||||
height: 38,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
border: Border.all(color: AppColors.primaryBorder),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
Formatters.initials(name),
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (expanded) ...[
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
height: 1.2,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
role,
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
height: 1.3,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Section extends ConsumerWidget {
|
||||
const _Section({
|
||||
required this.section,
|
||||
required this.expanded,
|
||||
this.onDestinationTap,
|
||||
});
|
||||
|
||||
final NavSection section;
|
||||
final bool expanded;
|
||||
final VoidCallback? onDestinationTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final active = ref.watch(activeModuleProvider);
|
||||
final cartCount = ref.watch(cartItemCountProvider);
|
||||
final ready = ref.watch(catalogueReadyProvider);
|
||||
final outstanding = ref
|
||||
.watch(syncEventsProvider)
|
||||
.where((e) => e.status != SyncStatus.synced)
|
||||
.length;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (expanded)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xl,
|
||||
AppSpacing.lg,
|
||||
AppSpacing.xl,
|
||||
AppSpacing.sm,
|
||||
),
|
||||
child: Text(section.label.toUpperCase(),
|
||||
style: AppTypography.sectionLabel()),
|
||||
)
|
||||
else
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
child: Divider(height: 1),
|
||||
),
|
||||
for (final module in section.modules)
|
||||
_NavTile(
|
||||
module: module,
|
||||
expanded: expanded,
|
||||
selected: active == module,
|
||||
badge: switch (module) {
|
||||
PosModule.pos => cartCount > 0 ? cartCount : null,
|
||||
PosModule.productImport => ready ? null : 1,
|
||||
PosModule.events => outstanding > 0 ? outstanding : null,
|
||||
_ => null,
|
||||
},
|
||||
badgeColor: switch (module) {
|
||||
PosModule.productImport => AppColors.danger,
|
||||
PosModule.events => AppColors.warning,
|
||||
_ => AppColors.primary,
|
||||
},
|
||||
onTap: () {
|
||||
ref.read(activeModuleProvider.notifier).state = module;
|
||||
onDestinationTap?.call();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NavTile extends StatefulWidget {
|
||||
const _NavTile({
|
||||
required this.module,
|
||||
required this.expanded,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
this.badge,
|
||||
this.badgeColor,
|
||||
});
|
||||
|
||||
final PosModule module;
|
||||
final bool expanded;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
final int? badge;
|
||||
final Color? badgeColor;
|
||||
|
||||
@override
|
||||
State<_NavTile> createState() => _NavTileState();
|
||||
}
|
||||
|
||||
class _NavTileState extends State<_NavTile> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final selected = widget.selected;
|
||||
final fg = selected
|
||||
? AppColors.primary
|
||||
: (_hovered ? AppColors.textPrimary : AppColors.textSecondary);
|
||||
|
||||
final tile = AnimatedContainer(
|
||||
duration: AppMotion.fast,
|
||||
height: AppSizes.navItemHeight,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: widget.expanded ? AppSpacing.md : 0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: selected
|
||||
? AppColors.primarySurface
|
||||
: (_hovered ? AppColors.surfaceAlt : Colors.transparent),
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: widget.expanded
|
||||
? MainAxisAlignment.start
|
||||
: MainAxisAlignment.center,
|
||||
children: [
|
||||
Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Icon(widget.module.icon, size: 20, color: fg),
|
||||
// In rail mode the label is gone, so the badge rides the icon.
|
||||
if (widget.badge != null && !widget.expanded)
|
||||
Positioned(
|
||||
top: -5,
|
||||
right: -8,
|
||||
child: _Badge(
|
||||
value: widget.badge!,
|
||||
color: widget.badgeColor ?? AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.expanded) ...[
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.module.label,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.w500,
|
||||
color: fg,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.badge != null)
|
||||
_Badge(
|
||||
value: widget.badge!,
|
||||
color: widget.badgeColor ?? AppColors.primary,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: widget.expanded ? AppSpacing.md : AppSpacing.lg,
|
||||
vertical: 2,
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
borderRadius: AppRadius.brSm,
|
||||
child: widget.expanded
|
||||
? tile
|
||||
: Tooltip(message: widget.module.title, child: tile),
|
||||
),
|
||||
),
|
||||
// Accent bar marking the active destination.
|
||||
if (selected)
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: 10,
|
||||
bottom: 10,
|
||||
child: Container(
|
||||
width: 3,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Badge extends StatelessWidget {
|
||||
const _Badge({required this.value, required this.color});
|
||||
|
||||
final int value;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
constraints: const BoxConstraints(minWidth: 19),
|
||||
height: 19,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
decoration: BoxDecoration(color: color, borderRadius: AppRadius.brPill),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
value > 99 ? '99+' : '$value',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LogoutTile extends ConsumerWidget {
|
||||
const _LogoutTile({required this.expanded});
|
||||
|
||||
final bool expanded;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => showSignOutDialog(context, ref),
|
||||
borderRadius: AppRadius.brSm,
|
||||
child: Container(
|
||||
height: AppSizes.navItemHeight,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: expanded ? AppSpacing.md : 0,
|
||||
),
|
||||
alignment: expanded ? Alignment.centerLeft : Alignment.center,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.logout_rounded,
|
||||
size: 19, color: AppColors.danger),
|
||||
if (expanded) ...[
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
const Text(
|
||||
'Logout',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.danger,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
368
lib/presentation/pos/widgets/billing_panel.dart
Normal file
368
lib/presentation/pos/widgets/billing_panel.dart
Normal file
@@ -0,0 +1,368 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/cart.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import 'cart_line_tile.dart';
|
||||
import 'discount_sheet.dart';
|
||||
|
||||
/// Always-visible bill on the right of the dashboard.
|
||||
class BillingPanel extends ConsumerWidget {
|
||||
const BillingPanel({super.key, this.inSheet = false});
|
||||
|
||||
final bool inSheet;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final cart = ref.watch(cartControllerProvider);
|
||||
final controller = ref.read(cartControllerProvider.notifier);
|
||||
|
||||
return Container(
|
||||
color: AppColors.surface,
|
||||
child: Column(children: [
|
||||
_Header(cart: cart, inSheet: inSheet),
|
||||
const Divider(height: 1),
|
||||
Expanded(
|
||||
child: cart.isEmpty
|
||||
? const EmptyState(
|
||||
title: 'Cart is empty',
|
||||
message: 'Scan a barcode or tap a product to begin.',
|
||||
emoji: '🛒',
|
||||
compact: true,
|
||||
)
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.lg,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
itemCount: cart.lines.length,
|
||||
separatorBuilder: (_, __) =>
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
itemBuilder: (_, i) {
|
||||
// Newest line first mirrors what the cashier just scanned.
|
||||
final line = cart.lines[cart.lines.length - 1 - i];
|
||||
return CartLineTile(
|
||||
key: ValueKey(line.product.id),
|
||||
line: line,
|
||||
onIncrement: () => controller.increment(line.product.id),
|
||||
onDecrement: () => controller.decrement(line.product.id),
|
||||
onRemove: () => controller.removeLine(line.product.id),
|
||||
onDiscount: () =>
|
||||
showLineDiscountSheet(context, ref, line),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (cart.isNotEmpty) _Summary(cart: cart),
|
||||
_Actions(cart: cart),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Header extends ConsumerWidget {
|
||||
const _Header({required this.cart, required this.inSheet});
|
||||
|
||||
final Cart cart;
|
||||
final bool inSheet;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final controller = ref.read(cartControllerProvider.notifier);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xl,
|
||||
AppSpacing.lg,
|
||||
AppSpacing.md,
|
||||
AppSpacing.lg,
|
||||
),
|
||||
child: Row(children: [
|
||||
Text('Cart', style: context.text.headlineSmall),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
if (cart.isNotEmpty)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
child: Text(
|
||||
'${cart.lineCount}',
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (controller.canUndo)
|
||||
IconButton(
|
||||
tooltip: 'Undo (F8)',
|
||||
onPressed: controller.undo,
|
||||
icon: const Icon(Icons.undo_rounded, size: 19),
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
if (cart.isNotEmpty) ...[
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
await controller.park();
|
||||
ref.invalidate(parkedBillsProvider);
|
||||
if (context.mounted) context.showSnack('Bill parked');
|
||||
},
|
||||
icon: const Icon(Icons.pause_circle_outline_rounded, size: 17),
|
||||
label: const Text('Park'),
|
||||
style: TextButton.styleFrom(foregroundColor: AppColors.warning),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: controller.clear,
|
||||
style: TextButton.styleFrom(foregroundColor: AppColors.danger),
|
||||
child: const Text('Clear'),
|
||||
),
|
||||
],
|
||||
if (inSheet)
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.close_rounded),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Summary extends ConsumerWidget {
|
||||
const _Summary({required this.cart});
|
||||
|
||||
final Cart cart;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final controller = ref.read(cartControllerProvider.notifier);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xl,
|
||||
AppSpacing.lg,
|
||||
AppSpacing.xl,
|
||||
AppSpacing.md,
|
||||
),
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(top: BorderSide(color: AppColors.divider)),
|
||||
),
|
||||
child: Column(children: [
|
||||
if (cart.pointsEarned > 0)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm + 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(children: [
|
||||
const Icon(Icons.stars_rounded,
|
||||
size: 16, color: AppColors.success),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(
|
||||
'This sale earns +${cart.pointsEarned} pts',
|
||||
style: const TextStyle(
|
||||
color: AppColors.success,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
_Row(label: 'Subtotal', value: Formatters.money(cart.subtotal)),
|
||||
|
||||
if (cart.membershipDiscountAmount > 0)
|
||||
_Row(
|
||||
label: '${cart.customer!.tier.label} discount',
|
||||
value: '-${Formatters.money(cart.membershipDiscountAmount)}',
|
||||
valueColor: AppColors.success,
|
||||
),
|
||||
|
||||
_Row(
|
||||
label: 'GST',
|
||||
value: Formatters.money(cart.taxAmount),
|
||||
hint: cart.taxBreakdown.keys.isEmpty
|
||||
? null
|
||||
: cart.taxBreakdown.keys
|
||||
.map((r) => '${(r * 100).toStringAsFixed(0)}%')
|
||||
.join(', '),
|
||||
),
|
||||
|
||||
InkWell(
|
||||
onTap: () => showBillDiscountSheet(context, ref),
|
||||
borderRadius: AppRadius.brXs,
|
||||
child: _Row(
|
||||
label: 'Discount',
|
||||
value: cart.manualBillDiscountAmount > 0
|
||||
? '-${Formatters.money(cart.manualBillDiscountAmount)}'
|
||||
: '-${Formatters.money(0)}',
|
||||
valueColor: cart.manualBillDiscountAmount > 0
|
||||
? AppColors.success
|
||||
: null,
|
||||
trailingIcon: Icons.edit_outlined,
|
||||
),
|
||||
),
|
||||
|
||||
if (cart.maxRedeemablePoints > 0 || cart.pointsRedeemed > 0)
|
||||
InkWell(
|
||||
onTap: () => cart.pointsRedeemed > 0
|
||||
? controller.clearRedemption()
|
||||
: controller.redeemAllPoints(),
|
||||
borderRadius: AppRadius.brXs,
|
||||
child: _Row(
|
||||
label: cart.pointsRedeemed > 0
|
||||
? 'Points redeemed (${cart.pointsRedeemed})'
|
||||
: 'Redeem ${cart.maxRedeemablePoints} points',
|
||||
value: cart.pointsRedeemed > 0
|
||||
? '-${Formatters.money(cart.loyaltyRedemptionValue)}'
|
||||
: 'Apply',
|
||||
valueColor: AppColors.primary,
|
||||
trailingIcon: cart.pointsRedeemed > 0
|
||||
? Icons.close_rounded
|
||||
: Icons.add_rounded,
|
||||
),
|
||||
),
|
||||
|
||||
if (cart.roundOff != 0)
|
||||
_Row(
|
||||
label: 'Round Off',
|
||||
value: '${cart.roundOff >= 0 ? '+' : ''}'
|
||||
'${Formatters.money(cart.roundOff)}',
|
||||
),
|
||||
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: AppSpacing.md),
|
||||
child: Divider(height: 1),
|
||||
),
|
||||
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Total', style: context.text.titleLarge),
|
||||
Text(
|
||||
Formatters.money(cart.grandTotal),
|
||||
style: AppTypography.money(26, color: AppColors.primary),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
if (cart.totalSavings > 0)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: AppSpacing.xs),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Text(
|
||||
'You saved ${Formatters.money(cart.totalSavings)}',
|
||||
style: const TextStyle(
|
||||
color: AppColors.success,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Row extends StatelessWidget {
|
||||
const _Row({
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.valueColor,
|
||||
this.hint,
|
||||
this.trailingIcon,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
final Color? valueColor;
|
||||
final String? hint;
|
||||
final IconData? trailingIcon;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs + 2),
|
||||
child: Row(children: [
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
)),
|
||||
if (hint != null) ...[
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text('($hint)',
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
)),
|
||||
],
|
||||
const Spacer(),
|
||||
Text(
|
||||
value,
|
||||
style: AppTypography.money(
|
||||
14.5,
|
||||
weight: FontWeight.w600,
|
||||
color: valueColor ?? AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
if (trailingIcon != null) ...[
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Icon(trailingIcon, size: 14, color: AppColors.textTertiary),
|
||||
],
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Actions extends ConsumerWidget {
|
||||
const _Actions({required this.cart});
|
||||
|
||||
final Cart cart;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final enabled = cart.isNotEmpty;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xl,
|
||||
AppSpacing.sm,
|
||||
AppSpacing.xl,
|
||||
AppSpacing.xl,
|
||||
),
|
||||
child: PrimaryButton(
|
||||
label: 'CHARGE',
|
||||
large: true,
|
||||
onPressed: enabled ? () => context.push(AppRoutes.payment) : null,
|
||||
trailing: enabled
|
||||
? Text(
|
||||
Formatters.money(cart.grandTotal),
|
||||
style: AppTypography.money(21, color: Colors.white),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
83
lib/presentation/pos/widgets/cart_fab.dart
Normal file
83
lib/presentation/pos/widgets/cart_fab.dart
Normal file
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
|
||||
/// Floating bill summary shown when the billing panel is collapsed into a
|
||||
/// sheet. Gives the cashier the running total without opening anything.
|
||||
class CartFab extends ConsumerWidget {
|
||||
const CartFab({super.key, required this.onTap});
|
||||
|
||||
final VoidCallback onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final cart = ref.watch(cartControllerProvider);
|
||||
if (cart.isEmpty) return const SizedBox.shrink();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
child: Material(
|
||||
color: AppColors.primary,
|
||||
borderRadius: AppRadius.brLg,
|
||||
elevation: 0,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: AppRadius.brLg,
|
||||
child: Container(
|
||||
height: AppSizes.buttonHeightLarge,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xl),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: AppRadius.brLg,
|
||||
boxShadow: AppColors.shadowLg,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.22),
|
||||
borderRadius: AppRadius.brXs,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'${cart.lineCount}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
const Text(
|
||||
'View bill',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xl),
|
||||
Text(
|
||||
Formatters.money(cart.grandTotal),
|
||||
style: AppTypography.money(19, color: Colors.white),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
const Icon(Icons.keyboard_arrow_up_rounded,
|
||||
color: Colors.white, size: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
).animate().fadeIn(duration: 180.ms).slideY(begin: 0.3, end: 0);
|
||||
}
|
||||
}
|
||||
241
lib/presentation/pos/widgets/cart_line_tile.dart
Normal file
241
lib/presentation/pos/widgets/cart_line_tile.dart
Normal file
@@ -0,0 +1,241 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/cart.dart';
|
||||
|
||||
/// One row of the bill, with inline quantity stepper.
|
||||
class CartLineTile extends StatelessWidget {
|
||||
const CartLineTile({
|
||||
super.key,
|
||||
required this.line,
|
||||
required this.onIncrement,
|
||||
required this.onDecrement,
|
||||
required this.onRemove,
|
||||
this.onDiscount,
|
||||
});
|
||||
|
||||
final CartLine line;
|
||||
final VoidCallback onIncrement;
|
||||
final VoidCallback onDecrement;
|
||||
final VoidCallback onRemove;
|
||||
final VoidCallback? onDiscount;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final p = line.product;
|
||||
|
||||
return Dismissible(
|
||||
key: ValueKey('dismiss_${p.id}'),
|
||||
direction: DismissDirection.endToStart,
|
||||
onDismissed: (_) => onRemove(),
|
||||
background: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: AppSpacing.xl),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.dangerSurface,
|
||||
borderRadius: AppRadius.brMd,
|
||||
),
|
||||
child: const Icon(Icons.delete_outline_rounded,
|
||||
color: AppColors.danger),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceAlt,
|
||||
borderRadius: AppRadius.brMd,
|
||||
border: Border.all(
|
||||
color: line.exceedsStock ? AppColors.danger : AppColors.border,
|
||||
),
|
||||
),
|
||||
child: Column(children: [
|
||||
Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(p.emoji, style: const TextStyle(fontSize: 21)),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
p.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Row(children: [
|
||||
Text(
|
||||
Formatters.money(p.price),
|
||||
style: AppTypography.money(13.5,
|
||||
weight: FontWeight.w600,
|
||||
color: AppColors.textSecondary),
|
||||
),
|
||||
Text(' / ${p.unit.symbol}',
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
)),
|
||||
if (line.discount.isActive) ...[
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 5, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
line.discount.label,
|
||||
style: const TextStyle(
|
||||
fontSize: 10,
|
||||
color: AppColors.success,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
]),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onRemove,
|
||||
icon: const Icon(Icons.close_rounded, size: 18),
|
||||
color: AppColors.textTertiary,
|
||||
constraints: const BoxConstraints(minWidth: 32, minHeight: 32),
|
||||
padding: EdgeInsets.zero,
|
||||
tooltip: 'Remove',
|
||||
),
|
||||
]),
|
||||
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
|
||||
Row(children: [
|
||||
_Stepper(
|
||||
quantity: line.quantity,
|
||||
unit: p.unit.symbol,
|
||||
onIncrement: onIncrement,
|
||||
onDecrement: onDecrement,
|
||||
),
|
||||
if (onDiscount != null) ...[
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
IconButton(
|
||||
onPressed: onDiscount,
|
||||
icon: const Icon(Icons.local_offer_outlined, size: 17),
|
||||
color: AppColors.textSecondary,
|
||||
constraints: const BoxConstraints(minWidth: 34, minHeight: 34),
|
||||
padding: EdgeInsets.zero,
|
||||
tooltip: 'Line discount',
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
if (line.discountAmount > 0)
|
||||
Text(
|
||||
Formatters.money(line.grossAmount),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
decoration: TextDecoration.lineThrough,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
Formatters.money(line.payable),
|
||||
style: AppTypography.money(16),
|
||||
),
|
||||
],
|
||||
),
|
||||
]),
|
||||
|
||||
if (line.exceedsStock)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: AppSpacing.sm),
|
||||
child: Row(children: [
|
||||
const Icon(Icons.error_outline_rounded,
|
||||
size: 14, color: AppColors.danger),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text(
|
||||
'Only ${p.stock.toStringAsFixed(0)} ${p.unit.symbol} '
|
||||
'available',
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.danger,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Stepper extends StatelessWidget {
|
||||
const _Stepper({
|
||||
required this.quantity,
|
||||
required this.unit,
|
||||
required this.onIncrement,
|
||||
required this.onDecrement,
|
||||
});
|
||||
|
||||
final double quantity;
|
||||
final String unit;
|
||||
final VoidCallback onIncrement;
|
||||
final VoidCallback onDecrement;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
border: Border.all(color: AppColors.border),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
_btn(Icons.remove_rounded, onDecrement),
|
||||
Container(
|
||||
constraints: const BoxConstraints(minWidth: 42),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
quantity % 1 == 0
|
||||
? quantity.toStringAsFixed(0)
|
||||
: quantity.toStringAsFixed(2),
|
||||
style: AppTypography.money(15.5),
|
||||
),
|
||||
),
|
||||
_btn(Icons.add_rounded, onIncrement),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _btn(IconData icon, VoidCallback onTap) => Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: AppRadius.brSm,
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: Icon(icon, size: 17, color: AppColors.primary),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
117
lib/presentation/pos/widgets/category_chips.dart
Normal file
117
lib/presentation/pos/widgets/category_chips.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../domain/entities/product.dart';
|
||||
import '../providers/catalog_providers.dart';
|
||||
|
||||
class CategoryChips extends ConsumerWidget {
|
||||
const CategoryChips({super.key, this.horizontalPadding = AppSpacing.xxl});
|
||||
|
||||
/// Matched to the surrounding content gutter by the dashboard layout.
|
||||
final double horizontalPadding;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final selected = ref.watch(selectedCategoryProvider);
|
||||
final counts = ref.watch(categoryCountsProvider).value ?? const {};
|
||||
|
||||
return SizedBox(
|
||||
height: 52,
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
|
||||
children: [
|
||||
_Chip(
|
||||
label: 'All',
|
||||
selected: selected == null,
|
||||
onTap: () =>
|
||||
ref.read(selectedCategoryProvider.notifier).state = null,
|
||||
),
|
||||
for (final category in ProductCategory.values)
|
||||
_Chip(
|
||||
label: category.label,
|
||||
emoji: category.emoji,
|
||||
count: counts[category],
|
||||
selected: selected == category,
|
||||
onTap: () => ref.read(selectedCategoryProvider.notifier).state =
|
||||
selected == category ? null : category,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Chip extends StatelessWidget {
|
||||
const _Chip({
|
||||
required this.label,
|
||||
required this.selected,
|
||||
required this.onTap,
|
||||
this.emoji,
|
||||
this.count,
|
||||
});
|
||||
|
||||
final String label;
|
||||
final bool selected;
|
||||
final VoidCallback onTap;
|
||||
final String? emoji;
|
||||
final int? count;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: AppSpacing.md),
|
||||
child: Material(
|
||||
color: selected ? AppColors.primary : AppColors.surface,
|
||||
borderRadius: AppRadius.brPill,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: AppRadius.brPill,
|
||||
child: AnimatedContainer(
|
||||
duration: AppMotion.fast,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: AppRadius.brPill,
|
||||
border: Border.all(
|
||||
color: selected ? AppColors.primary : AppColors.border,
|
||||
),
|
||||
boxShadow: selected ? AppColors.shadowSm : null,
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
if (emoji != null) ...[
|
||||
Text(emoji!, style: const TextStyle(fontSize: 15)),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
],
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: selected ? Colors.white : AppColors.textPrimary,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14.5,
|
||||
),
|
||||
),
|
||||
if (count != null) ...[
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(
|
||||
'$count',
|
||||
style: TextStyle(
|
||||
color: selected
|
||||
? Colors.white.withValues(alpha: 0.75)
|
||||
: AppColors.textTertiary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
99
lib/presentation/pos/widgets/customer_bar.dart
Normal file
99
lib/presentation/pos/widgets/customer_bar.dart
Normal file
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/status_pill.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
|
||||
/// Strip above the product grid showing who the sale belongs to.
|
||||
class CustomerBar extends ConsumerWidget {
|
||||
const CustomerBar({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final customer = ref.watch(
|
||||
cartControllerProvider.select((cart) => cart.customer),
|
||||
);
|
||||
|
||||
return Container(
|
||||
height: AppSizes.customerBarHeight,
|
||||
color: AppColors.surface,
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.xxl),
|
||||
child: Row(children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: customer == null
|
||||
? AppColors.border
|
||||
: AppColors.primarySurface,
|
||||
child: customer == null
|
||||
? const Icon(Icons.directions_walk_rounded,
|
||||
size: 20, color: AppColors.textSecondary)
|
||||
: Text(
|
||||
Formatters.initials(customer.name),
|
||||
style: const TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
customer?.name ?? 'Walk-in Customer',
|
||||
style: context.text.titleMedium,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (customer != null) ...[
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
StatusPill.tier(customer.tier, dense: true),
|
||||
],
|
||||
]),
|
||||
if (customer != null)
|
||||
Text(
|
||||
'${Formatters.mobile(customer.mobile)} · '
|
||||
'${customer.loyaltyPoints} pts',
|
||||
style: context.text.bodySmall,
|
||||
)
|
||||
else
|
||||
Text('No loyalty tracking for this sale',
|
||||
style: context.text.bodySmall),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
if (customer != null)
|
||||
TextButton.icon(
|
||||
onPressed: () =>
|
||||
ref.read(cartControllerProvider.notifier).attachCustomer(null),
|
||||
icon: const Icon(Icons.person_off_outlined, size: 17),
|
||||
label: const Text('Detach'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.textSecondary),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () => context.push(AppRoutes.existingCustomer),
|
||||
icon: const Icon(Icons.sync_alt_rounded, size: 17),
|
||||
label: Text(customer == null ? 'Add Customer' : 'Change'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(0, 44),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
|
||||
),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
213
lib/presentation/pos/widgets/discount_sheet.dart
Normal file
213
lib/presentation/pos/widgets/discount_sheet.dart
Normal file
@@ -0,0 +1,213 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/cart.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
|
||||
Future<void> showLineDiscountSheet(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
CartLine line,
|
||||
) {
|
||||
return _show(
|
||||
context: context,
|
||||
title: line.product.name,
|
||||
subtitle: 'Line value ${Formatters.money(line.grossAmount)}',
|
||||
current: line.discount,
|
||||
onApply: (d) => ref
|
||||
.read(cartControllerProvider.notifier)
|
||||
.applyLineDiscount(line.product.id, d),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> showBillDiscountSheet(BuildContext context, WidgetRef ref) {
|
||||
final cart = ref.read(cartControllerProvider);
|
||||
return _show(
|
||||
context: context,
|
||||
title: 'Bill discount',
|
||||
subtitle: 'Subtotal ${Formatters.money(cart.subtotal)}',
|
||||
current: cart.billDiscount,
|
||||
onApply: (d) =>
|
||||
ref.read(cartControllerProvider.notifier).applyBillDiscount(d),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _show({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required Discount current,
|
||||
required ValueChanged<Discount> onApply,
|
||||
}) {
|
||||
return showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) => _DiscountSheet(
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
current: current,
|
||||
onApply: onApply,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _DiscountSheet extends StatefulWidget {
|
||||
const _DiscountSheet({
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.current,
|
||||
required this.onApply,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final Discount current;
|
||||
final ValueChanged<Discount> onApply;
|
||||
|
||||
@override
|
||||
State<_DiscountSheet> createState() => _DiscountSheetState();
|
||||
}
|
||||
|
||||
class _DiscountSheetState extends State<_DiscountSheet> {
|
||||
late DiscountType _type =
|
||||
widget.current.type == DiscountType.none
|
||||
? DiscountType.percentage
|
||||
: widget.current.type;
|
||||
late final TextEditingController _value = TextEditingController(
|
||||
text: widget.current.isActive
|
||||
? widget.current.value.toStringAsFixed(0)
|
||||
: '',
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_value.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _apply() {
|
||||
final v = double.tryParse(_value.text.trim()) ?? 0;
|
||||
widget.onApply(
|
||||
v <= 0 ? Discount.none : Discount(type: _type, value: v),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.viewInsetsOf(context).bottom,
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(AppRadius.xxl)),
|
||||
),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.border,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
|
||||
Text(widget.title,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 2),
|
||||
Text(widget.subtitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.textSecondary,
|
||||
)),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
|
||||
SegmentedButton<DiscountType>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: DiscountType.percentage,
|
||||
label: Text('Percentage'),
|
||||
icon: Icon(Icons.percent_rounded, size: 17),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: DiscountType.flat,
|
||||
label: Text('Flat amount'),
|
||||
icon: Icon(Icons.currency_rupee_rounded, size: 17),
|
||||
),
|
||||
],
|
||||
selected: {_type},
|
||||
onSelectionChanged: (s) => setState(() => _type = s.first),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
|
||||
TextField(
|
||||
controller: _value,
|
||||
autofocus: true,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d{0,2}')),
|
||||
],
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.w700),
|
||||
textAlign: TextAlign.center,
|
||||
decoration: InputDecoration(
|
||||
hintText: '0',
|
||||
prefixText: _type == DiscountType.flat ? '₹ ' : null,
|
||||
suffixText: _type == DiscountType.percentage ? '%' : null,
|
||||
),
|
||||
onSubmitted: (_) => _apply(),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
|
||||
Wrap(
|
||||
spacing: AppSpacing.sm,
|
||||
children: (_type == DiscountType.percentage
|
||||
? const [5, 10, 15, 20, 25]
|
||||
: const [10, 20, 50, 100, 200])
|
||||
.map((v) => ActionChip(
|
||||
label: Text(_type == DiscountType.percentage
|
||||
? '$v%'
|
||||
: '₹$v'),
|
||||
onPressed: () =>
|
||||
setState(() => _value.text = v.toString()),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: 'Remove',
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
widget.onApply(Discount.none);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PrimaryButton(
|
||||
label: 'Apply discount',
|
||||
icon: Icons.check_rounded,
|
||||
onPressed: _apply,
|
||||
),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
324
lib/presentation/pos/widgets/page_header.dart
Normal file
324
lib/presentation/pos/widgets/page_header.dart
Normal file
@@ -0,0 +1,324 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_layout.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import '../providers/navigation_provider.dart';
|
||||
|
||||
/// White page header: breadcrumb, title, and the terminal's quick actions.
|
||||
///
|
||||
/// Replaces the old purple app bar now that branding lives in the sidebar.
|
||||
class PageHeader extends ConsumerWidget {
|
||||
const PageHeader({
|
||||
super.key,
|
||||
required this.layout,
|
||||
this.onMenuTap,
|
||||
});
|
||||
|
||||
final PosLayout layout;
|
||||
final VoidCallback? onMenuTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final module = ref.watch(activeModuleProvider);
|
||||
final now = ref.watch(clockProvider).value ?? DateTime.now();
|
||||
final compact = layout.sidebarIsDrawer;
|
||||
|
||||
return Container(
|
||||
constraints: const BoxConstraints(minHeight: AppSizes.headerHeight),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: layout.contentPadding,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
border: Border(bottom: BorderSide(color: AppColors.border)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (compact) ...[
|
||||
IconButton(
|
||||
onPressed: onMenuTap,
|
||||
icon: const Icon(Icons.menu_rounded),
|
||||
tooltip: 'Menu',
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
],
|
||||
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
module.title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: -0.4,
|
||||
color: AppColors.textPrimary,
|
||||
height: 1.2,
|
||||
),
|
||||
),
|
||||
if (!compact) _Breadcrumb(module: module),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
if (!compact) ...[
|
||||
const _LivePill(),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Text(
|
||||
Formatters.time(now),
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.textSecondary,
|
||||
fontFeatures: [FontFeature.tabularFigures()],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Container(width: 1, height: 26, color: AppColors.border),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
],
|
||||
|
||||
_ParkedBillsButton(compact: compact),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
_NewSaleButton(compact: compact),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Breadcrumb extends StatelessWidget {
|
||||
const _Breadcrumb({required this.module});
|
||||
|
||||
final PosModule module;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const style = TextStyle(fontSize: 12, color: AppColors.textTertiary);
|
||||
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('Home', style: style),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: AppSpacing.xs + 2),
|
||||
child: Icon(Icons.chevron_right_rounded,
|
||||
size: 13, color: AppColors.textTertiary),
|
||||
),
|
||||
Text(module.section.label, style: style),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: AppSpacing.xs + 2),
|
||||
child: Icon(Icons.chevron_right_rounded,
|
||||
size: 13, color: AppColors.textTertiary),
|
||||
),
|
||||
Text(
|
||||
module.label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LivePill extends StatefulWidget {
|
||||
const _LivePill();
|
||||
|
||||
@override
|
||||
State<_LivePill> createState() => _LivePillState();
|
||||
}
|
||||
|
||||
class _LivePillState extends State<_LivePill>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _c = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1400),
|
||||
)..repeat(reverse: true);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_c.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.xs + 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FadeTransition(
|
||||
opacity: _c,
|
||||
child: Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.success,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xs + 2),
|
||||
const Text(
|
||||
'LIVE',
|
||||
style: TextStyle(
|
||||
color: AppColors.success,
|
||||
fontSize: 10.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
letterSpacing: 0.8,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ParkedBillsButton extends ConsumerWidget {
|
||||
const _ParkedBillsButton({required this.compact});
|
||||
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final parked = ref.watch(parkedBillsProvider).value ?? const [];
|
||||
|
||||
if (compact) {
|
||||
return IconButton(
|
||||
tooltip: 'Parked bills',
|
||||
onPressed: () => _openParked(context, ref),
|
||||
icon: Badge(
|
||||
isLabelVisible: parked.isNotEmpty,
|
||||
label: Text('${parked.length}'),
|
||||
backgroundColor: AppColors.warning,
|
||||
child: const Icon(Icons.pause_circle_outline_rounded),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return OutlinedButton.icon(
|
||||
onPressed: () => _openParked(context, ref),
|
||||
icon: const Icon(Icons.pause_circle_outline_rounded, size: 17),
|
||||
label: Text(
|
||||
parked.isEmpty ? 'Parked' : 'Parked (${parked.length})',
|
||||
),
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(0, 42),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
|
||||
foregroundColor: AppColors.textSecondary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _openParked(BuildContext context, WidgetRef ref) {
|
||||
final parked = ref.read(parkedBillsProvider).value ?? const [];
|
||||
|
||||
if (parked.isEmpty) {
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(const SnackBar(content: Text('No parked bills.')));
|
||||
return;
|
||||
}
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text('Parked bills'),
|
||||
content: SizedBox(
|
||||
width: 380,
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
itemCount: parked.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (_, i) {
|
||||
final bill = parked[i];
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.receipt_long_rounded,
|
||||
color: AppColors.primary),
|
||||
title: Text(bill.displayLabel),
|
||||
subtitle: Text(
|
||||
'${bill.cart.lineCount} items · '
|
||||
'${Formatters.money(bill.cart.grandTotal)} · '
|
||||
'${Formatters.time(bill.parkedAt)}',
|
||||
),
|
||||
onTap: () async {
|
||||
await ref
|
||||
.read(cartControllerProvider.notifier)
|
||||
.resume(bill);
|
||||
ref.invalidate(parkedBillsProvider);
|
||||
if (context.mounted) Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NewSaleButton extends ConsumerWidget {
|
||||
const _NewSaleButton({required this.compact});
|
||||
|
||||
final bool compact;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
void start() {
|
||||
ref.read(cartControllerProvider.notifier).reset();
|
||||
context.go(AppRoutes.welcome);
|
||||
}
|
||||
|
||||
if (compact) {
|
||||
return IconButton.filled(
|
||||
tooltip: 'New sale',
|
||||
onPressed: start,
|
||||
icon: const Icon(Icons.add_rounded),
|
||||
style: IconButton.styleFrom(backgroundColor: AppColors.primary),
|
||||
);
|
||||
}
|
||||
|
||||
return FilledButton.icon(
|
||||
onPressed: start,
|
||||
icon: const Icon(Icons.add_rounded, size: 18),
|
||||
label: const Text('New Sale'),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
minimumSize: const Size(0, 42),
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
|
||||
shape: const RoundedRectangleBorder(borderRadius: AppRadius.brSm),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
217
lib/presentation/pos/widgets/product_card.dart
Normal file
217
lib/presentation/pos/widgets/product_card.dart
Normal file
@@ -0,0 +1,217 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/product.dart';
|
||||
|
||||
/// Tapping anywhere on the card bills the item — no confirm step.
|
||||
class ProductCard extends StatefulWidget {
|
||||
const ProductCard({
|
||||
super.key,
|
||||
required this.product,
|
||||
required this.onTap,
|
||||
this.inCartQuantity = 0,
|
||||
});
|
||||
|
||||
final Product product;
|
||||
final VoidCallback onTap;
|
||||
final double inCartQuantity;
|
||||
|
||||
@override
|
||||
State<ProductCard> createState() => _ProductCardState();
|
||||
}
|
||||
|
||||
class _ProductCardState extends State<ProductCard> {
|
||||
bool _hovered = false;
|
||||
bool _pressed = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final p = widget.product;
|
||||
final disabled = p.isOutOfStock;
|
||||
final inCart = widget.inCartQuantity > 0;
|
||||
|
||||
return MouseRegion(
|
||||
cursor: disabled ? SystemMouseCursors.forbidden : SystemMouseCursors.click,
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) => setState(() => _pressed = true),
|
||||
onTapUp: (_) => setState(() => _pressed = false),
|
||||
onTapCancel: () => setState(() => _pressed = false),
|
||||
onTap: disabled ? null : widget.onTap,
|
||||
child: AnimatedScale(
|
||||
scale: _pressed ? 0.96 : 1,
|
||||
duration: AppMotion.instant,
|
||||
child: AnimatedContainer(
|
||||
duration: AppMotion.fast,
|
||||
decoration: BoxDecoration(
|
||||
color: disabled ? AppColors.surfaceAlt : AppColors.surface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(
|
||||
color: inCart
|
||||
? AppColors.primary
|
||||
: (_hovered ? AppColors.primaryBorder : AppColors.border),
|
||||
width: inCart ? 1.8 : 1,
|
||||
),
|
||||
boxShadow: _hovered && !disabled
|
||||
? AppColors.shadowMd
|
||||
: AppColors.shadowSm,
|
||||
),
|
||||
child: Stack(children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Opacity(
|
||||
opacity: disabled ? 0.4 : 1,
|
||||
child: Text(p.emoji,
|
||||
style: const TextStyle(fontSize: 40)),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text(
|
||||
p.name,
|
||||
maxLines: 2,
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.25,
|
||||
color: disabled
|
||||
? AppColors.textTertiary
|
||||
: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs + 2),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
Formatters.money(p.price),
|
||||
style: AppTypography.money(17,
|
||||
color: disabled
|
||||
? AppColors.textTertiary
|
||||
: AppColors.primary),
|
||||
),
|
||||
if (p.hasDiscount) ...[
|
||||
const SizedBox(width: AppSpacing.xs + 2),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 1.5),
|
||||
child: Text(
|
||||
Formatters.money(p.mrp!),
|
||||
style: const TextStyle(
|
||||
fontSize: 11.5,
|
||||
color: AppColors.textTertiary,
|
||||
decoration: TextDecoration.lineThrough,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
disabled
|
||||
? 'Out of stock'
|
||||
: '${p.stock.toStringAsFixed(0)} in stock',
|
||||
style: TextStyle(
|
||||
fontSize: 11.5,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: disabled
|
||||
? AppColors.danger
|
||||
: (p.isLowStock
|
||||
? AppColors.warning
|
||||
: AppColors.textTertiary),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
if (p.hasDiscount && !disabled)
|
||||
Positioned(
|
||||
top: AppSpacing.sm,
|
||||
left: AppSpacing.sm,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.success,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Text(
|
||||
'${p.discountPercent.toStringAsFixed(0)}%',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (p.isLowStock && !disabled)
|
||||
const Positioned(
|
||||
top: AppSpacing.sm,
|
||||
right: AppSpacing.sm,
|
||||
child: Icon(Icons.warning_amber_rounded,
|
||||
size: 15, color: AppColors.warning),
|
||||
),
|
||||
|
||||
// Quantity badge once the item is on the bill.
|
||||
if (inCart)
|
||||
Positioned(
|
||||
top: AppSpacing.sm,
|
||||
right: AppSpacing.sm,
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(minWidth: 24),
|
||||
height: 24,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.rectangle,
|
||||
borderRadius: AppRadius.brPill,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
widget.inCartQuantity % 1 == 0
|
||||
? widget.inCartQuantity.toStringAsFixed(0)
|
||||
: widget.inCartQuantity.toStringAsFixed(2),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Hover-only add affordance keeps the resting card clean.
|
||||
if (_hovered && !disabled && !inCart)
|
||||
Positioned(
|
||||
bottom: AppSpacing.sm,
|
||||
right: AppSpacing.sm,
|
||||
child: Container(
|
||||
width: 28,
|
||||
height: 28,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.add_rounded,
|
||||
size: 18, color: Colors.white),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
82
lib/presentation/pos/widgets/product_grid.dart
Normal file
82
lib/presentation/pos/widgets/product_grid.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import '../providers/catalog_providers.dart';
|
||||
import 'product_card.dart';
|
||||
|
||||
/// Responsive grid that fills the available width with cards of a stable
|
||||
/// minimum size, rather than a fixed column count.
|
||||
class ProductGrid extends ConsumerWidget {
|
||||
const ProductGrid({
|
||||
super.key,
|
||||
this.horizontalPadding = AppSpacing.xxl,
|
||||
this.tileExtent = 186,
|
||||
this.bottomPadding = AppSpacing.xxl,
|
||||
});
|
||||
|
||||
/// Content gutter, supplied by the dashboard layout.
|
||||
final double horizontalPadding;
|
||||
|
||||
/// Maximum card width; the grid fits as many columns as will fit.
|
||||
final double tileExtent;
|
||||
|
||||
/// Extra space so the floating bill button never covers the last row.
|
||||
final double bottomPadding;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final products = ref.watch(visibleProductsProvider);
|
||||
final cart = ref.watch(cartControllerProvider);
|
||||
|
||||
return products.when(
|
||||
loading: () => const Center(
|
||||
child: CircularProgressIndicator(color: AppColors.primary),
|
||||
),
|
||||
error: (e, _) => EmptyState(
|
||||
title: 'Could not load products',
|
||||
message: '$e',
|
||||
emoji: '⚠️',
|
||||
),
|
||||
data: (items) {
|
||||
if (items.isEmpty) {
|
||||
return const EmptyState(
|
||||
title: 'No products match',
|
||||
message: 'Try a different search term or category.',
|
||||
emoji: '🔎',
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
horizontalPadding,
|
||||
0,
|
||||
horizontalPadding,
|
||||
bottomPadding,
|
||||
),
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: tileExtent,
|
||||
mainAxisSpacing: AppSpacing.md,
|
||||
crossAxisSpacing: AppSpacing.md,
|
||||
childAspectRatio: AppSizes.productCardAspect,
|
||||
),
|
||||
itemCount: items.length,
|
||||
itemBuilder: (context, i) {
|
||||
final product = items[i];
|
||||
return ProductCard(
|
||||
key: ValueKey(product.id),
|
||||
product: product,
|
||||
inCartQuantity: cart.lineFor(product.id)?.quantity ?? 0,
|
||||
onTap: () => ref
|
||||
.read(cartControllerProvider.notifier)
|
||||
.addProduct(product),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
121
lib/presentation/pos/widgets/scan_toast.dart
Normal file
121
lib/presentation/pos/widgets/scan_toast.dart
Normal file
@@ -0,0 +1,121 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
|
||||
/// Brief floating confirmation after a scan.
|
||||
///
|
||||
/// Deliberately not a dialog: the cashier must never have to dismiss anything
|
||||
/// between items.
|
||||
class ScanToast extends ConsumerStatefulWidget {
|
||||
const ScanToast({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ScanToast> createState() => _ScanToastState();
|
||||
}
|
||||
|
||||
class _ScanToastState extends ConsumerState<ScanToast> {
|
||||
Timer? _timer;
|
||||
ScanFeedback? _visible;
|
||||
|
||||
void _show(ScanFeedback feedback) {
|
||||
_timer?.cancel();
|
||||
setState(() => _visible = feedback);
|
||||
_timer = Timer(
|
||||
const Duration(milliseconds: 1600),
|
||||
() {
|
||||
if (mounted) setState(() => _visible = null);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
ref.listen<ScanFeedback?>(scanFeedbackProvider, (prev, next) {
|
||||
if (next != null) _show(next);
|
||||
});
|
||||
|
||||
final feedback = _visible;
|
||||
if (feedback == null) return const SizedBox.shrink();
|
||||
|
||||
final success = feedback.isSuccess;
|
||||
final color = success ? AppColors.success : AppColors.danger;
|
||||
final product = feedback.product;
|
||||
|
||||
final message = feedback.message ??
|
||||
switch (feedback.outcome) {
|
||||
ScanOutcome.added => 'Added to bill',
|
||||
ScanOutcome.incremented => 'Quantity updated',
|
||||
ScanOutcome.notFound => 'Product not found',
|
||||
ScanOutcome.outOfStock => 'Out of stock',
|
||||
};
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: AppSpacing.xxl),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.md,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.textPrimary,
|
||||
borderRadius: AppRadius.brPill,
|
||||
boxShadow: AppColors.shadowLg,
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 26,
|
||||
height: 26,
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
child: Icon(
|
||||
success ? Icons.check_rounded : Icons.priority_high_rounded,
|
||||
size: 17,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
if (product != null) ...[
|
||||
Text(product.emoji, style: const TextStyle(fontSize: 17)),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 220),
|
||||
child: Text(
|
||||
product.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 14.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Container(width: 1, height: 16, color: Colors.white24),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
],
|
||||
Text(
|
||||
message,
|
||||
style: TextStyle(
|
||||
color: Colors.white.withValues(alpha: 0.85),
|
||||
fontSize: 13.5,
|
||||
),
|
||||
),
|
||||
]),
|
||||
)
|
||||
.animate(key: ValueKey(feedback.stamp))
|
||||
.fadeIn(duration: 140.ms)
|
||||
.slideY(begin: 0.4, end: 0, curve: Curves.easeOutBack)
|
||||
.then(delay: 1200.ms)
|
||||
.fadeOut(duration: 250.ms);
|
||||
}
|
||||
}
|
||||
103
lib/presentation/pos/widgets/search_field.dart
Normal file
103
lib/presentation/pos/widgets/search_field.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/validators.dart';
|
||||
import '../providers/cart_controller.dart';
|
||||
import '../providers/catalog_providers.dart';
|
||||
|
||||
/// Doubles as the barcode input.
|
||||
///
|
||||
/// If the submitted text looks like a barcode we bill it immediately and clear
|
||||
/// the field; otherwise it stays as a live search term.
|
||||
class PosSearchField extends ConsumerStatefulWidget {
|
||||
const PosSearchField({super.key, this.focusNode});
|
||||
|
||||
final FocusNode? focusNode;
|
||||
|
||||
@override
|
||||
ConsumerState<PosSearchField> createState() => _PosSearchFieldState();
|
||||
}
|
||||
|
||||
class _PosSearchFieldState extends ConsumerState<PosSearchField> {
|
||||
final _controller = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit(String value) {
|
||||
final text = value.trim();
|
||||
if (text.isEmpty) return;
|
||||
|
||||
if (Validators.isLikelyBarcode(text)) {
|
||||
ref.read(cartControllerProvider.notifier).scanBarcode(text);
|
||||
_controller.clear();
|
||||
ref.read(searchQueryProvider.notifier).state = '';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final query = ref.watch(searchQueryProvider);
|
||||
|
||||
return TextField(
|
||||
controller: _controller,
|
||||
focusNode: widget.focusNode,
|
||||
autofocus: true,
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
onChanged: (v) => ref.read(searchQueryProvider.notifier).state = v,
|
||||
onSubmitted: _submit,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search product, scan barcode or enter SKU…',
|
||||
prefixIcon: const Padding(
|
||||
padding: EdgeInsets.only(left: AppSpacing.md, right: AppSpacing.sm),
|
||||
child: Icon(Icons.search_rounded, color: AppColors.textTertiary),
|
||||
),
|
||||
prefixIconConstraints: const BoxConstraints(minWidth: 0),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.lg,
|
||||
vertical: AppSpacing.lg + 2,
|
||||
),
|
||||
suffixIcon: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
if (query.isNotEmpty)
|
||||
IconButton(
|
||||
tooltip: 'Clear',
|
||||
icon: const Icon(Icons.close_rounded, size: 20),
|
||||
color: AppColors.textTertiary,
|
||||
onPressed: () {
|
||||
_controller.clear();
|
||||
ref.read(searchQueryProvider.notifier).state = '';
|
||||
},
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(right: AppSpacing.sm),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.md,
|
||||
vertical: AppSpacing.sm,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: const Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
Icon(Icons.qr_code_scanner_rounded,
|
||||
size: 18, color: AppColors.primary),
|
||||
SizedBox(width: AppSpacing.xs + 2),
|
||||
Text('Scanner ready',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
250
lib/presentation/receipt/screens/receipt_screen.dart
Normal file
250
lib/presentation/receipt/screens/receipt_screen.dart
Normal file
@@ -0,0 +1,250 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/glass_card.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../widgets/receipt_preview.dart';
|
||||
|
||||
/// Confirmation screen. Counts down and starts the next sale on its own so an
|
||||
/// unattended terminal never sits on a finished bill.
|
||||
class ReceiptScreen extends ConsumerStatefulWidget {
|
||||
const ReceiptScreen({super.key, required this.transaction});
|
||||
|
||||
final SaleTransaction transaction;
|
||||
|
||||
@override
|
||||
ConsumerState<ReceiptScreen> createState() => _ReceiptScreenState();
|
||||
}
|
||||
|
||||
class _ReceiptScreenState extends ConsumerState<ReceiptScreen> {
|
||||
late int _seconds = AppConstants.postSaleResetDelay.inSeconds + 5;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_timer = Timer.periodic(const Duration(seconds: 1), (t) {
|
||||
if (!mounted) return;
|
||||
setState(() => _seconds--);
|
||||
if (_seconds <= 0) _newSale();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _cancelAutoReturn() {
|
||||
_timer?.cancel();
|
||||
if (mounted) setState(() => _seconds = -1);
|
||||
}
|
||||
|
||||
void _newSale() {
|
||||
_timer?.cancel();
|
||||
ref.read(cartControllerProvider.notifier).reset();
|
||||
if (mounted) context.go(AppRoutes.welcome);
|
||||
}
|
||||
|
||||
void _continueBilling() {
|
||||
_timer?.cancel();
|
||||
ref.read(cartControllerProvider.notifier).reset();
|
||||
if (mounted) context.go(AppRoutes.pos);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final txn = widget.transaction;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
body: SafeArea(
|
||||
child: Listener(
|
||||
onPointerDown: (_) => _cancelAutoReturn(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: context.isCompact
|
||||
? SingleChildScrollView(
|
||||
child: Column(children: [
|
||||
_summary(txn),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
SizedBox(
|
||||
height: 480,
|
||||
child: ReceiptPreview(transaction: txn),
|
||||
),
|
||||
]),
|
||||
)
|
||||
: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Expanded(flex: 5, child: _summary(txn)),
|
||||
const SizedBox(width: AppSpacing.xxl),
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: ReceiptPreview(transaction: txn),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _summary(SaleTransaction txn) {
|
||||
return GlassCard(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxxl),
|
||||
radius: AppRadius.xxl,
|
||||
shadows: AppColors.shadowMd,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 84,
|
||||
height: 84,
|
||||
decoration: const BoxDecoration(
|
||||
color: AppColors.successSurface,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.check_rounded,
|
||||
size: 44, color: AppColors.success),
|
||||
)
|
||||
.animate()
|
||||
.scale(
|
||||
duration: 340.ms,
|
||||
curve: Curves.easeOutBack,
|
||||
begin: const Offset(0.5, 0.5),
|
||||
)
|
||||
.fadeIn(),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xl),
|
||||
Text('Sale complete',
|
||||
textAlign: TextAlign.center,
|
||||
style: context.text.headlineMedium),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
'${txn.invoiceNumber} · ${Formatters.dateTime(txn.createdAt)}',
|
||||
textAlign: TextAlign.center,
|
||||
style: context.text.bodySmall,
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.xl),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
),
|
||||
child: Column(children: [
|
||||
Text('Amount paid', style: context.text.labelMedium),
|
||||
Text(
|
||||
Formatters.money(txn.total),
|
||||
style: AppTypography.money(36, color: AppColors.primary),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
const Divider(),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_row('Paid via', txn.paymentSummary),
|
||||
if (txn.changeDue > 0)
|
||||
_row('Change returned', Formatters.money(txn.changeDue),
|
||||
highlight: AppColors.success),
|
||||
_row('Items', '${txn.cart.lineCount}'),
|
||||
if (txn.customer != null) ...[
|
||||
_row('Customer', txn.customer!.name),
|
||||
_row('Points earned', '+${txn.pointsEarned}',
|
||||
highlight: AppColors.success),
|
||||
if (txn.pointsRedeemed > 0)
|
||||
_row('Points redeemed', '-${txn.pointsRedeemed}'),
|
||||
],
|
||||
if (txn.cart.totalSavings > 0)
|
||||
_row(
|
||||
'Customer saved',
|
||||
Formatters.money(txn.cart.totalSavings),
|
||||
highlight: AppColors.success,
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
const SizedBox(height: AppSpacing.xxl),
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: 'Reprint',
|
||||
icon: Icons.print_outlined,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
_cancelAutoReturn();
|
||||
ref.read(receiptServiceProvider).printWithDialog(txn);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Expanded(
|
||||
child: PrimaryButton(
|
||||
label: 'Share',
|
||||
icon: Icons.ios_share_rounded,
|
||||
tone: ButtonTone.neutral,
|
||||
onPressed: () {
|
||||
_cancelAutoReturn();
|
||||
ref.read(receiptServiceProvider).share(txn);
|
||||
},
|
||||
),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
PrimaryButton(
|
||||
label: _seconds > 0
|
||||
? 'New Sale ($_seconds)'
|
||||
: 'New Sale',
|
||||
icon: Icons.add_shopping_cart_rounded,
|
||||
large: true,
|
||||
onPressed: _newSale,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
TextButton(
|
||||
onPressed: _continueBilling,
|
||||
child: const Text('Back to billing screen'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row(String label, String value, {Color? highlight}) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
color: AppColors.textSecondary,
|
||||
)),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: highlight ?? AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
289
lib/presentation/receipt/widgets/receipt_preview.dart
Normal file
289
lib/presentation/receipt/widgets/receipt_preview.dart
Normal file
@@ -0,0 +1,289 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/theme/app_typography.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../domain/entities/transaction.dart';
|
||||
|
||||
/// Paper-like preview of what the thermal printer produced.
|
||||
class ReceiptPreview extends StatelessWidget {
|
||||
const ReceiptPreview({super.key, required this.transaction});
|
||||
|
||||
final SaleTransaction transaction;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final txn = transaction;
|
||||
final cart = txn.cart;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: AppRadius.brLg,
|
||||
boxShadow: AppColors.shadowMd,
|
||||
),
|
||||
child: Column(children: [
|
||||
const _Perforation(top: true),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xxl,
|
||||
vertical: AppSpacing.xl,
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: AppTypography.mono(11.5, color: AppColors.textPrimary),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Center(
|
||||
child: Column(children: [
|
||||
Text(
|
||||
AppConstants.storeName.toUpperCase(),
|
||||
style: AppTypography.mono(15)
|
||||
.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(AppConstants.storeAddress,
|
||||
textAlign: TextAlign.center,
|
||||
style: AppTypography.mono(9.5)),
|
||||
Text('GSTIN: ${AppConstants.storeGstin}',
|
||||
style: AppTypography.mono(9.5)),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text('TAX INVOICE',
|
||||
style: AppTypography.mono(11.5)
|
||||
.copyWith(fontWeight: FontWeight.w700)),
|
||||
]),
|
||||
),
|
||||
|
||||
const _Dashes(),
|
||||
_row('Invoice', txn.invoiceNumber),
|
||||
_row('Date', Formatters.receiptStamp(txn.createdAt)),
|
||||
_row('Cashier', txn.cashierName),
|
||||
_row('Customer', txn.customer?.name ?? 'Walk-in'),
|
||||
|
||||
const _Dashes(),
|
||||
Row(children: [
|
||||
Expanded(flex: 5, child: _bold('Item')),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: _bold('Qty', align: TextAlign.center),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: _bold('Amount', align: TextAlign.right),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
|
||||
...cart.lines.map((line) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 2.5),
|
||||
child: Row(children: [
|
||||
Expanded(flex: 5, child: Text(line.product.name)),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
line.quantity % 1 == 0
|
||||
? line.quantity.toStringAsFixed(0)
|
||||
: line.quantity.toStringAsFixed(2),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
line.payable.toStringAsFixed(2),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
]),
|
||||
)),
|
||||
|
||||
const _Dashes(),
|
||||
_row('Subtotal', cart.subtotal.toStringAsFixed(2)),
|
||||
if (cart.billDiscountTotal > 0)
|
||||
_row('Discount',
|
||||
'-${cart.billDiscountTotal.toStringAsFixed(2)}'),
|
||||
if (cart.loyaltyRedemptionValue > 0)
|
||||
_row('Points redeemed',
|
||||
'-${cart.loyaltyRedemptionValue.toStringAsFixed(2)}'),
|
||||
_row('CGST', cart.cgst.toStringAsFixed(2)),
|
||||
_row('SGST', cart.sgst.toStringAsFixed(2)),
|
||||
if (cart.roundOff != 0)
|
||||
_row('Round off', cart.roundOff.toStringAsFixed(2)),
|
||||
|
||||
const _Dashes(),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('TOTAL',
|
||||
style: AppTypography.mono(15).copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: AppColors.textPrimary,
|
||||
)),
|
||||
Text(
|
||||
Formatters.money(txn.total),
|
||||
style: AppTypography.mono(15).copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const _Dashes(),
|
||||
...txn.payments.map((p) =>
|
||||
_row(p.method.label, p.amount.toStringAsFixed(2))),
|
||||
if (txn.changeDue > 0)
|
||||
_row('Change', txn.changeDue.toStringAsFixed(2)),
|
||||
|
||||
if (txn.customer != null) ...[
|
||||
const _Dashes(),
|
||||
_row('Points earned', '+${txn.pointsEarned}'),
|
||||
_row('Membership', txn.customer!.tier.label),
|
||||
],
|
||||
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
Center(
|
||||
child: Column(children: [
|
||||
_FakeBarcode(value: txn.invoiceNumber),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Text('Thank you for shopping with us!',
|
||||
style: AppTypography.mono(11)
|
||||
.copyWith(fontWeight: FontWeight.w700)),
|
||||
const SizedBox(height: 2),
|
||||
Text('Powered by Nearle POS',
|
||||
style: AppTypography.mono(9)),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const _Perforation(top: false),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row(String label, String value) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 1.5),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [Text(label), Text(value)],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _bold(String text, {TextAlign align = TextAlign.left}) => Text(
|
||||
text,
|
||||
textAlign: align,
|
||||
style: AppTypography.mono(11.5).copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _Dashes extends StatelessWidget {
|
||||
const _Dashes();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: AppSpacing.sm),
|
||||
child: Text(
|
||||
'- - - - - - - - - - - - - - - - - - - - - - - - - -',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.clip,
|
||||
style: TextStyle(color: AppColors.textTertiary, fontSize: 10),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Zig-zag torn-paper edge.
|
||||
class _Perforation extends StatelessWidget {
|
||||
const _Perforation({required this.top});
|
||||
|
||||
final bool top;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 10,
|
||||
child: CustomPaint(
|
||||
size: const Size(double.infinity, 10),
|
||||
painter: _PerforationPainter(top: top),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PerforationPainter extends CustomPainter {
|
||||
const _PerforationPainter({required this.top});
|
||||
|
||||
final bool top;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
const tooth = 12.0;
|
||||
final path = Path();
|
||||
|
||||
if (top) {
|
||||
path.moveTo(0, size.height);
|
||||
for (var x = 0.0; x < size.width; x += tooth) {
|
||||
path.lineTo(x + tooth / 2, 0);
|
||||
path.lineTo(x + tooth, size.height);
|
||||
}
|
||||
path.lineTo(size.width, size.height);
|
||||
} else {
|
||||
path.moveTo(0, 0);
|
||||
for (var x = 0.0; x < size.width; x += tooth) {
|
||||
path.lineTo(x + tooth / 2, size.height);
|
||||
path.lineTo(x + tooth, 0);
|
||||
}
|
||||
path.lineTo(size.width, 0);
|
||||
}
|
||||
path.close();
|
||||
|
||||
canvas.drawPath(path, Paint()..color = AppColors.surface);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _PerforationPainter oldDelegate) =>
|
||||
oldDelegate.top != top;
|
||||
}
|
||||
|
||||
/// Decorative Code-128-style bar rendering for the preview only.
|
||||
class _FakeBarcode extends StatelessWidget {
|
||||
const _FakeBarcode({required this.value});
|
||||
|
||||
final String value;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bars = value.codeUnits;
|
||||
|
||||
return Column(children: [
|
||||
SizedBox(
|
||||
height: 38,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
for (var i = 0; i < bars.length * 2; i++)
|
||||
Container(
|
||||
width: (bars[i ~/ 2] % 3 == 0) ? 3 : 1.5,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 0.7),
|
||||
color: i.isEven
|
||||
? AppColors.textPrimary
|
||||
: Colors.transparent,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Text(value, style: AppTypography.mono(9)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
156
lib/presentation/sync/providers/sync_controller.dart
Normal file
156
lib/presentation/sync/providers/sync_controller.dart
Normal file
@@ -0,0 +1,156 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../domain/entities/shift_report.dart';
|
||||
import '../../../domain/entities/sync_event.dart';
|
||||
import '../../auth/providers/auth_controller.dart';
|
||||
import '../../pos/providers/catalog_providers.dart';
|
||||
|
||||
/// Progress of a catalogue pull.
|
||||
sealed class ImportState {
|
||||
const ImportState();
|
||||
}
|
||||
|
||||
class ImportIdle extends ImportState {
|
||||
const ImportIdle();
|
||||
}
|
||||
|
||||
class ImportRunning extends ImportState {
|
||||
const ImportRunning(this.progress, this.stage);
|
||||
|
||||
final double progress;
|
||||
final String stage;
|
||||
}
|
||||
|
||||
class ImportDone extends ImportState {
|
||||
const ImportDone(this.event);
|
||||
|
||||
final SyncEvent event;
|
||||
}
|
||||
|
||||
class ImportFailed extends ImportState {
|
||||
const ImportFailed(this.message);
|
||||
|
||||
final String message;
|
||||
}
|
||||
|
||||
/// Bumped after every successful import so catalogue providers refetch.
|
||||
final catalogueVersionProvider = StateProvider<int>((ref) => 0);
|
||||
|
||||
/// Whether the terminal has products to sell. The POS is gated on this.
|
||||
final catalogueReadyProvider = Provider<bool>((ref) {
|
||||
ref.watch(catalogueVersionProvider);
|
||||
return ref.watch(syncRepositoryProvider).hasCatalogue;
|
||||
});
|
||||
|
||||
final lastImportAtProvider = Provider<DateTime?>((ref) {
|
||||
ref.watch(catalogueVersionProvider);
|
||||
return ref.watch(syncRepositoryProvider).lastImportAt;
|
||||
});
|
||||
|
||||
class CatalogueImportController extends StateNotifier<ImportState> {
|
||||
CatalogueImportController(this._ref) : super(const ImportIdle());
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<bool> run() async {
|
||||
if (state is ImportRunning) return false;
|
||||
|
||||
state = const ImportRunning(0, 'Starting…');
|
||||
|
||||
final event = await _ref.read(syncRepositoryProvider).importCatalogue(
|
||||
onProgress: (progress, stage) {
|
||||
if (mounted) state = ImportRunning(progress, stage);
|
||||
},
|
||||
);
|
||||
|
||||
if (event.status == SyncStatus.synced) {
|
||||
// Force every catalogue-backed provider to refetch.
|
||||
_ref.read(catalogueVersionProvider.notifier).state++;
|
||||
_ref.invalidate(allProductsProvider);
|
||||
_ref.invalidate(visibleProductsProvider);
|
||||
_ref.invalidate(categoryCountsProvider);
|
||||
_ref.invalidate(lowStockProductsProvider);
|
||||
|
||||
state = ImportDone(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
state = ImportFailed(event.error ?? 'Import failed.');
|
||||
return false;
|
||||
}
|
||||
|
||||
void reset() => state = const ImportIdle();
|
||||
}
|
||||
|
||||
final catalogueImportProvider =
|
||||
StateNotifierProvider<CatalogueImportController, ImportState>(
|
||||
(ref) => CatalogueImportController(ref),
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------------ Events
|
||||
/// Bumped whenever the event log changes.
|
||||
final syncVersionProvider = StateProvider<int>((ref) => 0);
|
||||
|
||||
final syncEventsProvider = Provider<List<SyncEvent>>((ref) {
|
||||
ref.watch(syncVersionProvider);
|
||||
ref.watch(catalogueVersionProvider);
|
||||
return ref.watch(syncRepositoryProvider).events;
|
||||
});
|
||||
|
||||
final hasUnsyncedProvider = Provider<bool>((ref) {
|
||||
ref.watch(syncVersionProvider);
|
||||
ref.watch(catalogueVersionProvider);
|
||||
return ref.watch(syncRepositoryProvider).hasUnsyncedEvents;
|
||||
});
|
||||
|
||||
/// Today's takings, recomputed from local sales on every change.
|
||||
final shiftReportProvider = Provider<ShiftReport>((ref) {
|
||||
ref.watch(syncVersionProvider);
|
||||
final session = ref.watch(cashierSessionProvider);
|
||||
final user = ref.watch(currentUserProvider);
|
||||
|
||||
return ref.watch(syncRepositoryProvider).buildShiftReport(
|
||||
businessDate: DateTime.now(),
|
||||
terminalId: session.terminalId,
|
||||
cashierName: user?.name ?? session.name,
|
||||
);
|
||||
});
|
||||
|
||||
/// Drives the push button and the sign-out dialog.
|
||||
class ReportPushController extends StateNotifier<bool> {
|
||||
ReportPushController(this._ref) : super(false);
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
/// Pushes today's report. Returns the resulting event so the caller can
|
||||
/// tell the cashier whether it landed.
|
||||
Future<SyncEvent> pushToday() async {
|
||||
state = true;
|
||||
try {
|
||||
final report = _ref.read(shiftReportProvider);
|
||||
final event =
|
||||
await _ref.read(syncRepositoryProvider).pushShiftReport(report);
|
||||
_ref.read(syncVersionProvider.notifier).state++;
|
||||
return event;
|
||||
} finally {
|
||||
if (mounted) state = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<SyncEvent> retry(String eventId) async {
|
||||
state = true;
|
||||
try {
|
||||
final event = await _ref.read(syncRepositoryProvider).retry(eventId);
|
||||
_ref.read(syncVersionProvider.notifier).state++;
|
||||
return event;
|
||||
} finally {
|
||||
if (mounted) state = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final reportPushProvider =
|
||||
StateNotifierProvider<ReportPushController, bool>(
|
||||
(ref) => ReportPushController(ref),
|
||||
);
|
||||
233
lib/presentation/sync/widgets/sign_out_dialog.dart
Normal file
233
lib/presentation/sync/widgets/sign_out_dialog.dart
Normal file
@@ -0,0 +1,233 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/primary_button.dart';
|
||||
import '../../../domain/entities/sync_event.dart';
|
||||
import '../../auth/providers/auth_controller.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../providers/sync_controller.dart';
|
||||
|
||||
/// End-of-shift flow.
|
||||
///
|
||||
/// The day's takings are pushed here — the second and last moment this
|
||||
/// terminal needs a connection. Signing out without pushing is allowed, but
|
||||
/// the report stays queued locally rather than being discarded.
|
||||
Future<void> showSignOutDialog(BuildContext context, WidgetRef ref) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => const _SignOutDialog(),
|
||||
);
|
||||
}
|
||||
|
||||
class _SignOutDialog extends ConsumerStatefulWidget {
|
||||
const _SignOutDialog();
|
||||
|
||||
@override
|
||||
ConsumerState<_SignOutDialog> createState() => _SignOutDialogState();
|
||||
}
|
||||
|
||||
class _SignOutDialogState extends ConsumerState<_SignOutDialog> {
|
||||
SyncEvent? _result;
|
||||
|
||||
void _finish() {
|
||||
ref.read(cartControllerProvider.notifier).reset();
|
||||
ref.read(authControllerProvider.notifier).signOut();
|
||||
Navigator.of(context).pop();
|
||||
context.go(AppRoutes.login);
|
||||
}
|
||||
|
||||
Future<void> _pushThenFinish() async {
|
||||
final event = await ref.read(reportPushProvider.notifier).pushToday();
|
||||
if (!mounted) return;
|
||||
|
||||
setState(() => _result = event);
|
||||
|
||||
if (event.status == SyncStatus.synced) {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 700));
|
||||
if (mounted) _finish();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final report = ref.watch(shiftReportProvider);
|
||||
final cart = ref.watch(cartControllerProvider);
|
||||
final pushing = ref.watch(reportPushProvider);
|
||||
final failed = _result?.status == SyncStatus.failed;
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('End shift'),
|
||||
contentPadding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xxl,
|
||||
AppSpacing.lg,
|
||||
AppSpacing.xxl,
|
||||
AppSpacing.sm,
|
||||
),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (cart.isNotEmpty)
|
||||
_Banner(
|
||||
icon: Icons.warning_amber_rounded,
|
||||
color: AppColors.warning,
|
||||
background: AppColors.warningSurface,
|
||||
message: 'The current bill has ${cart.lineCount} item(s) '
|
||||
'and will be cleared. Park it first if you need it.',
|
||||
),
|
||||
|
||||
if (report.isEmpty)
|
||||
const _Banner(
|
||||
icon: Icons.info_outline_rounded,
|
||||
color: AppColors.textSecondary,
|
||||
background: AppColors.surfaceAlt,
|
||||
message: 'No sales were recorded today, so there is nothing '
|
||||
'to push.',
|
||||
)
|
||||
else ...[
|
||||
const Text(
|
||||
"Today's takings",
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
_row('Bills', '${report.billCount}'),
|
||||
_row('Items sold', report.itemCount.toStringAsFixed(0)),
|
||||
_row('Gross sales', Formatters.money(report.grossSales)),
|
||||
_row('GST collected', Formatters.money(report.taxCollected)),
|
||||
_row('Average basket',
|
||||
Formatters.money(report.averageBasket)),
|
||||
],
|
||||
|
||||
if (failed) ...[
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_Banner(
|
||||
icon: Icons.wifi_off_rounded,
|
||||
color: AppColors.danger,
|
||||
background: AppColors.dangerSurface,
|
||||
message: _result?.error ??
|
||||
'The push failed. The report is still saved on this '
|
||||
'terminal and can be retried from Events.',
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actionsPadding: const EdgeInsets.fromLTRB(
|
||||
AppSpacing.xxl,
|
||||
0,
|
||||
AppSpacing.xxl,
|
||||
AppSpacing.lg,
|
||||
),
|
||||
actions: [
|
||||
// Wrap keeps three actions from overflowing a narrow dialog.
|
||||
Wrap(
|
||||
alignment: WrapAlignment.end,
|
||||
spacing: AppSpacing.sm,
|
||||
runSpacing: AppSpacing.sm,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: pushing ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: pushing ? null : _finish,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.textSecondary,
|
||||
),
|
||||
child: Text(
|
||||
report.isEmpty ? 'Sign out' : 'Sign out without pushing',
|
||||
),
|
||||
),
|
||||
if (!report.isEmpty)
|
||||
SizedBox(
|
||||
width: 190,
|
||||
child: PrimaryButton(
|
||||
label: failed ? 'Retry push' : 'Push & sign out',
|
||||
icon: Icons.cloud_upload_rounded,
|
||||
busy: pushing,
|
||||
onPressed: _pushThenFinish,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _row(String label, String value) => Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 13.5,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _Banner extends StatelessWidget {
|
||||
const _Banner({
|
||||
required this.icon,
|
||||
required this.color,
|
||||
required this.background,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final Color color;
|
||||
final Color background;
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: background,
|
||||
borderRadius: AppRadius.brSm,
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, size: 18, color: color),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
message,
|
||||
style: TextStyle(fontSize: 12.5, color: color, height: 1.45),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
337
lib/presentation/welcome/screens/welcome_screen.dart
Normal file
337
lib/presentation/welcome/screens/welcome_screen.dart
Normal file
@@ -0,0 +1,337 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../app/providers.dart';
|
||||
import '../../../core/constants/app_constants.dart';
|
||||
import '../../../core/router/app_router.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimens.dart';
|
||||
import '../../../core/utils/extensions.dart';
|
||||
import '../../../core/utils/formatters.dart';
|
||||
import '../../../core/widgets/glass_card.dart';
|
||||
import '../../pos/providers/cart_controller.dart';
|
||||
import '../widgets/welcome_illustration.dart';
|
||||
|
||||
/// Screen 1 — the terminal's resting state between sales.
|
||||
class WelcomeScreen extends ConsumerWidget {
|
||||
const WelcomeScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final session = ref.watch(cashierSessionProvider);
|
||||
final clock = ref.watch(clockProvider).value ?? DateTime.now();
|
||||
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(gradient: AppColors.primaryGradient),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
_TopBar(cashier: session.name, now: clock),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppSpacing.xxl),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 920),
|
||||
child: GlassCard(
|
||||
blur: 18,
|
||||
padding: EdgeInsets.all(
|
||||
context.responsive(
|
||||
compact: AppSpacing.xxl,
|
||||
expanded: AppSpacing.giant,
|
||||
),
|
||||
),
|
||||
radius: AppRadius.xxl,
|
||||
shadows: AppColors.shadowLg,
|
||||
child: context.isCompact
|
||||
? const _StackedLayout()
|
||||
: const _SideBySideLayout(),
|
||||
),
|
||||
),
|
||||
).animate().fadeIn(duration: 350.ms).slideY(
|
||||
begin: 0.04,
|
||||
end: 0,
|
||||
curve: Curves.easeOutCubic,
|
||||
),
|
||||
),
|
||||
),
|
||||
const _BottomHint(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SideBySideLayout extends StatelessWidget {
|
||||
const _SideBySideLayout();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: const [
|
||||
Expanded(flex: 4, child: WelcomeIllustration(size: 260)),
|
||||
SizedBox(width: AppSpacing.giant),
|
||||
Expanded(flex: 5, child: _WelcomeContent()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StackedLayout extends StatelessWidget {
|
||||
const _StackedLayout();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
WelcomeIllustration(size: 150),
|
||||
SizedBox(height: AppSpacing.xxl),
|
||||
_WelcomeContent(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WelcomeContent extends ConsumerWidget {
|
||||
const _WelcomeContent();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Welcome to',
|
||||
style: context.text.titleMedium?.copyWith(
|
||||
color: AppColors.textSecondary,
|
||||
letterSpacing: 1.4,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
'Nearle POS',
|
||||
style: context.text.displaySmall?.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Text(
|
||||
'Start a new sale by identifying the shopper, '
|
||||
'or skip straight to billing.',
|
||||
style: context.text.bodyMedium
|
||||
?.copyWith(color: AppColors.textSecondary),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xxxl),
|
||||
|
||||
_WelcomeAction(
|
||||
icon: Icons.person_add_alt_1_rounded,
|
||||
title: 'New Customer',
|
||||
subtitle: 'Register and start earning loyalty points',
|
||||
onTap: () => context.push(AppRoutes.registerCustomer),
|
||||
primary: true,
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_WelcomeAction(
|
||||
icon: Icons.badge_outlined,
|
||||
title: 'Existing Customer',
|
||||
subtitle: 'Look up by mobile number',
|
||||
onTap: () => context.push(AppRoutes.existingCustomer),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
_WelcomeAction(
|
||||
icon: Icons.directions_walk_rounded,
|
||||
title: 'Skip Customer',
|
||||
subtitle: 'Walk-in sale, no loyalty tracking',
|
||||
onTap: () {
|
||||
ref.read(cartControllerProvider.notifier).reset();
|
||||
context.go(AppRoutes.pos);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A tall, unmistakable target — the cashier taps this hundreds of times a day.
|
||||
class _WelcomeAction extends StatefulWidget {
|
||||
const _WelcomeAction({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.onTap,
|
||||
this.primary = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final VoidCallback onTap;
|
||||
final bool primary;
|
||||
|
||||
@override
|
||||
State<_WelcomeAction> createState() => _WelcomeActionState();
|
||||
}
|
||||
|
||||
class _WelcomeActionState extends State<_WelcomeAction> {
|
||||
bool _hovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bg = widget.primary
|
||||
? AppColors.primary
|
||||
: (_hovered ? AppColors.primarySurface : AppColors.surface);
|
||||
final fg =
|
||||
widget.primary ? AppColors.textOnPrimary : AppColors.textPrimary;
|
||||
final sub = widget.primary
|
||||
? AppColors.textOnPrimary.withValues(alpha: 0.78)
|
||||
: AppColors.textSecondary;
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: AnimatedContainer(
|
||||
duration: AppMotion.fast,
|
||||
transform: Matrix4.translationValues(0, _hovered ? -2 : 0, 0),
|
||||
child: Material(
|
||||
color: bg,
|
||||
borderRadius: AppRadius.brLg,
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
borderRadius: AppRadius.brLg,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xl,
|
||||
vertical: AppSpacing.lg,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: AppRadius.brLg,
|
||||
border: Border.all(
|
||||
color: widget.primary
|
||||
? Colors.transparent
|
||||
: AppColors.border,
|
||||
),
|
||||
boxShadow: widget.primary && _hovered
|
||||
? AppColors.shadowMd
|
||||
: null,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 46,
|
||||
height: 46,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.primary
|
||||
? Colors.white.withValues(alpha: 0.18)
|
||||
: AppColors.primarySurface,
|
||||
borderRadius: AppRadius.brMd,
|
||||
),
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
color: widget.primary
|
||||
? AppColors.textOnPrimary
|
||||
: AppColors.primary,
|
||||
size: 22,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.lg),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.title,
|
||||
style: context.text.titleMedium?.copyWith(color: fg),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
widget.subtitle,
|
||||
style: context.text.bodySmall?.copyWith(color: sub),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.arrow_forward_rounded, color: sub, size: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _TopBar extends StatelessWidget {
|
||||
const _TopBar({required this.cashier, required this.now});
|
||||
|
||||
final String cashier;
|
||||
final DateTime now;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: AppSpacing.xxl,
|
||||
vertical: AppSpacing.lg,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.storefront_rounded,
|
||||
color: Colors.white, size: 26),
|
||||
const SizedBox(width: AppSpacing.md),
|
||||
Text(
|
||||
AppConstants.storeName,
|
||||
style: context.text.titleLarge?.copyWith(color: Colors.white),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'${Formatters.date(now)} ${Formatters.time(now)}',
|
||||
style: context.text.bodyMedium
|
||||
?.copyWith(color: Colors.white.withValues(alpha: 0.85)),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.xxl),
|
||||
CircleAvatar(
|
||||
radius: 16,
|
||||
backgroundColor: Colors.white.withValues(alpha: 0.2),
|
||||
child: Text(
|
||||
Formatters.initials(cashier),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(cashier,
|
||||
style: context.text.bodyMedium?.copyWith(color: Colors.white)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _BottomHint extends StatelessWidget {
|
||||
const _BottomHint();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppSpacing.xl),
|
||||
child: Text(
|
||||
'Scan a barcode at any time to begin a walk-in sale',
|
||||
style: context.text.bodySmall
|
||||
?.copyWith(color: Colors.white.withValues(alpha: 0.7)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
156
lib/presentation/welcome/widgets/welcome_illustration.dart
Normal file
156
lib/presentation/welcome/widgets/welcome_illustration.dart
Normal file
@@ -0,0 +1,156 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
|
||||
/// Vector shopping-cart illustration drawn in code.
|
||||
///
|
||||
/// Painting it avoids shipping a raster asset and keeps it crisp on 4K desktop
|
||||
/// displays as well as tablet screens.
|
||||
class WelcomeIllustration extends StatelessWidget {
|
||||
const WelcomeIllustration({super.key, this.size = 240});
|
||||
|
||||
final double size;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: size,
|
||||
height: size,
|
||||
child: CustomPaint(painter: _CartPainter()),
|
||||
)
|
||||
.animate(onPlay: (c) => c.repeat(reverse: true))
|
||||
.moveY(begin: 0, end: -8, duration: 2400.ms, curve: Curves.easeInOut);
|
||||
}
|
||||
}
|
||||
|
||||
class _CartPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final w = size.width;
|
||||
final h = size.height;
|
||||
final unit = w / 100;
|
||||
|
||||
// Soft backdrop disc.
|
||||
canvas.drawCircle(
|
||||
Offset(w * 0.5, h * 0.5),
|
||||
w * 0.46,
|
||||
Paint()..color = AppColors.primarySurface,
|
||||
);
|
||||
|
||||
// Decorative arc.
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(center: Offset(w * 0.5, h * 0.5), radius: w * 0.46),
|
||||
-1.1,
|
||||
2.0,
|
||||
false,
|
||||
Paint()
|
||||
..color = AppColors.primaryBorder
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = unit * 1.6
|
||||
..strokeCap = StrokeCap.round,
|
||||
);
|
||||
|
||||
final stroke = Paint()
|
||||
..color = AppColors.primary
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = unit * 3
|
||||
..strokeCap = StrokeCap.round
|
||||
..strokeJoin = StrokeJoin.round;
|
||||
|
||||
final fill = Paint()..color = AppColors.primary.withValues(alpha: 0.16);
|
||||
|
||||
// Cart basket.
|
||||
final basket = Path()
|
||||
..moveTo(w * 0.30, h * 0.36)
|
||||
..lineTo(w * 0.78, h * 0.36)
|
||||
..lineTo(w * 0.70, h * 0.60)
|
||||
..lineTo(w * 0.37, h * 0.60)
|
||||
..close();
|
||||
canvas.drawPath(basket, fill);
|
||||
canvas.drawPath(basket, stroke);
|
||||
|
||||
// Handle running to the push bar.
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(w * 0.16, h * 0.26)
|
||||
..lineTo(w * 0.24, h * 0.26)
|
||||
..lineTo(w * 0.30, h * 0.36),
|
||||
stroke,
|
||||
);
|
||||
|
||||
// Basket ribs.
|
||||
for (var i = 1; i <= 2; i++) {
|
||||
final t = i / 3;
|
||||
canvas.drawLine(
|
||||
Offset(w * (0.30 + 0.48 * t), h * 0.36),
|
||||
Offset(w * (0.37 + 0.33 * t), h * 0.60),
|
||||
stroke..strokeWidth = unit * 1.6,
|
||||
);
|
||||
}
|
||||
stroke.strokeWidth = unit * 3;
|
||||
|
||||
// Wheels.
|
||||
for (final dx in [0.44, 0.66]) {
|
||||
canvas.drawCircle(
|
||||
Offset(w * dx, h * 0.70),
|
||||
unit * 5,
|
||||
Paint()..color = AppColors.surface,
|
||||
);
|
||||
canvas.drawCircle(Offset(w * dx, h * 0.70), unit * 5, stroke);
|
||||
}
|
||||
|
||||
// Groceries poking out of the basket.
|
||||
_item(canvas, Offset(w * 0.42, h * 0.30), unit * 5.5,
|
||||
AppColors.tierGold.withValues(alpha: 0.9));
|
||||
_item(canvas, Offset(w * 0.55, h * 0.27), unit * 6.5,
|
||||
AppColors.success.withValues(alpha: 0.85));
|
||||
_item(canvas, Offset(w * 0.67, h * 0.31), unit * 5,
|
||||
AppColors.danger.withValues(alpha: 0.75));
|
||||
|
||||
// Receipt tape drifting away from the terminal.
|
||||
final receipt = Path()
|
||||
..moveTo(w * 0.80, h * 0.20)
|
||||
..lineTo(w * 0.94, h * 0.20)
|
||||
..lineTo(w * 0.94, h * 0.44)
|
||||
..lineTo(w * 0.905, h * 0.40)
|
||||
..lineTo(w * 0.87, h * 0.44)
|
||||
..lineTo(w * 0.835, h * 0.40)
|
||||
..lineTo(w * 0.80, h * 0.44)
|
||||
..close();
|
||||
canvas.drawPath(receipt, Paint()..color = AppColors.surface);
|
||||
canvas.drawPath(
|
||||
receipt,
|
||||
Paint()
|
||||
..color = AppColors.primaryLight
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = unit * 1.4
|
||||
..strokeJoin = StrokeJoin.round,
|
||||
);
|
||||
|
||||
// Receipt lines.
|
||||
final line = Paint()
|
||||
..color = AppColors.primaryBorder
|
||||
..strokeWidth = unit * 1.2
|
||||
..strokeCap = StrokeCap.round;
|
||||
for (var i = 0; i < 3; i++) {
|
||||
final y = h * (0.25 + i * 0.05);
|
||||
canvas.drawLine(Offset(w * 0.835, y), Offset(w * 0.905, y), line);
|
||||
}
|
||||
}
|
||||
|
||||
void _item(Canvas canvas, Offset center, double radius, Color color) {
|
||||
canvas.drawCircle(center, radius, Paint()..color = color);
|
||||
canvas.drawCircle(
|
||||
center,
|
||||
radius,
|
||||
Paint()
|
||||
..color = Colors.white.withValues(alpha: 0.5)
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1.5,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
|
||||
}
|
||||
Reference in New Issue
Block a user