84 lines
3.2 KiB
Dart
84 lines
3.2 KiB
Dart
import 'package:e_receipt_mobile/domain/entities/login_user.dart';
|
|
import 'package:e_receipt_mobile/presentation/home/home_view_model.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
class HomeScreen extends ConsumerWidget {
|
|
const HomeScreen({required this.user, super.key});
|
|
|
|
final LoginUser user;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final role = user.role.toLowerCase();
|
|
final merchantsAsync = ref.watch(merchantListProvider);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("Merchants"),
|
|
centerTitle: true,
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: merchantsAsync.when(
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (error, _) => Center(
|
|
child: Text('Failed to load merchants: $error'),
|
|
),
|
|
data: (merchants) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Total (${merchants.length})',
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Expanded(
|
|
child: merchants.isEmpty
|
|
? const Center(child: Text('No merchants found'))
|
|
: ListView.separated(
|
|
itemCount: merchants.length,
|
|
separatorBuilder: (_, __) =>
|
|
const SizedBox(height: 10),
|
|
itemBuilder: (context, index) {
|
|
final merchant = merchants[index];
|
|
return Card(
|
|
elevation: 2,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'${index + 1}. ${merchant.name ?? '-'}',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.titleMedium,
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
merchant.address ?? '-',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.bodyMedium,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|