e_receipt_mobile/lib/presentation/home/home_screen.dart

84 lines
3.2 KiB
Dart
Raw Normal View History

2026-02-14 10:16:13 +00:00
import 'package:e_receipt_mobile/domain/entities/login_user.dart';
2026-02-14 10:46:58 +00:00
import 'package:e_receipt_mobile/presentation/home/home_view_model.dart';
2026-02-13 19:46:02 +00:00
import 'package:flutter/material.dart';
2026-02-14 10:46:58 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2026-02-13 19:46:02 +00:00
2026-02-14 10:46:58 +00:00
class HomeScreen extends ConsumerWidget {
2026-02-14 10:16:13 +00:00
const HomeScreen({required this.user, super.key});
final LoginUser user;
2026-02-13 19:46:02 +00:00
@override
2026-02-14 10:46:58 +00:00
Widget build(BuildContext context, WidgetRef ref) {
2026-02-14 10:16:13 +00:00
final role = user.role.toLowerCase();
2026-02-14 10:46:58 +00:00
final merchantsAsync = ref.watch(merchantListProvider);
2026-02-13 19:46:02 +00:00
return Scaffold(
appBar: AppBar(
2026-02-14 10:46:58 +00:00
title: Text("Merchants"),
2026-02-13 19:46:02 +00:00
centerTitle: true,
),
2026-02-14 10:46:58 +00:00
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,
),
],
),
),
);
},
),
),
],
);
},
2026-02-14 10:16:13 +00:00
),
2026-02-13 19:46:02 +00:00
),
);
}
}