import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; /// The tab strip under the top bar on every «Аналитика» screen. Each tab keeps its own /// top-level route (`/income`, `/rebalance`, …), so the screens stay deep-linkable; the strip /// only makes them read as the parts of one section. class AnalyticsTabs extends StatelessWidget { const AnalyticsTabs({required this.location, super.key}); final String location; static const tabs = [ (path: '/analytics', icon: Icons.work_outline, label: 'Общее'), (path: '/income', icon: Icons.bar_chart, label: 'Дивиденды'), (path: '/rebalance', icon: Icons.balance, label: 'Ребалансировка'), (path: '/goals', icon: Icons.flag_outlined, label: 'Цели'), (path: '/tax', icon: Icons.receipt_long_outlined, label: 'Налоги'), (path: '/portfolios', icon: Icons.pie_chart_outline, label: 'Портфели'), ]; /// Whether [location] belongs to the analytics section at all. static bool contains(String location) => tabs.any((t) => location.startsWith(t.path)); @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; return Container( decoration: BoxDecoration( color: scheme.surfaceContainer, borderRadius: BorderRadius.circular(12), ), padding: const EdgeInsets.symmetric(horizontal: 12), child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: [ for (final t in tabs) _Tab( icon: t.icon, label: t.label, selected: location.startsWith(t.path), onTap: () => context.go(t.path), ), ], ), ), ); } } class _Tab extends StatelessWidget { const _Tab({ required this.icon, required this.label, required this.selected, required this.onTap, }); final IconData icon; final String label; final bool selected; final VoidCallback onTap; @override Widget build(BuildContext context) { final scheme = Theme.of(context).colorScheme; final color = selected ? scheme.onSurface : scheme.onSurfaceVariant; return InkWell( onTap: onTap, child: Container( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 16), decoration: BoxDecoration( border: Border( bottom: BorderSide( color: selected ? scheme.primary : Colors.transparent, width: 2, ), ), ), child: Row( children: [ Icon( icon, size: 20, color: selected ? scheme.primary : scheme.onSurfaceVariant, ), const SizedBox(width: 8), Text( label, style: TextStyle( color: color, fontWeight: selected ? FontWeight.w600 : FontWeight.w500, ), ), ], ), ), ); } }