Files
OnBudget/lib/src/features/home/presentation/widgets/transactions_section.dart
T
2026-05-27 10:10:38 +03:00

131 lines
4.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../app/theme/app_colors.dart';
import '../_mock_data.dart';
import '../month_summary.dart';
import '../state/selected_category_filter.dart';
class TransactionsSectionHeader extends ConsumerWidget {
const TransactionsSectionHeader({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final p = context.palette;
final count = ref.watch(filteredTransactionsProvider).length;
return Padding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
child: Row(
children: [
Text(
'Транзакции',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: p.ink,
),
),
const Spacer(),
Text(
'$count ${_opsWord(count)}',
style: TextStyle(fontSize: 11, color: p.ink2),
),
],
),
);
}
String _opsWord(int n) {
final mod10 = n % 10;
final mod100 = n % 100;
if (mod10 == 1 && mod100 != 11) return 'операция';
if (mod10 >= 2 && mod10 <= 4 && (mod100 < 10 || mod100 >= 20)) {
return 'операции';
}
return 'операций';
}
}
class CategoryFilterPill extends ConsumerWidget {
const CategoryFilterPill({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final p = context.palette;
final categories = ref.watch(mockCategoriesProvider);
final selectedId = ref.watch(selectedCategoryFilterProvider);
final activeCat = selectedId == null
? null
: categories.firstWhere((c) => c.id == selectedId,
orElse: () => categories.first);
final count = ref.watch(filteredTransactionsProvider).length;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: GestureDetector(
onTap: () =>
ref.read(selectedCategoryFilterProvider.notifier).state = null,
behavior: HitTestBehavior.opaque,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
decoration: BoxDecoration(
border: Border.all(color: p.line),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(Icons.tune, size: 18, color: p.ink2),
const SizedBox(width: 8),
Expanded(
child: activeCat == null
? Text(
'Все категории · все типы',
style: TextStyle(fontSize: 13, color: p.ink),
)
: Row(
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: colorFor(activeCat),
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 6),
Flexible(
child: Text(
activeCat.name,
style: TextStyle(fontSize: 13, color: p.ink),
overflow: TextOverflow.ellipsis,
),
),
],
),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: p.accentSoft,
borderRadius: BorderRadius.circular(99),
),
child: Text(
'$count',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: p.accent,
),
),
),
const SizedBox(width: 6),
Icon(Icons.keyboard_arrow_down, size: 18, color: p.ink2),
],
),
),
),
);
}
}