import 'package:didvan/config/theme_data.dart'; import 'package:didvan/constants/app_icons.dart'; import 'package:didvan/models/statistic_data/statistic_data.dart'; import 'package:didvan/routes/routes.dart'; import 'package:didvan/views/widgets/didvan/card.dart'; import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:didvan/views/widgets/shimmer_placeholder.dart'; import 'package:flutter/material.dart'; class StatisticOverview extends StatelessWidget { final StatisticData statistic; final bool isMarked; final void Function(int id, bool value) onMarkChanged; const StatisticOverview({ Key? key, required this.statistic, required this.isMarked, required this.onMarkChanged, }) : super(key: key); Color _diffColor(context) => statistic.data.dt == 'high' ? Theme.of(context).colorScheme.success : Theme.of(context).colorScheme.error; bool get _hasDiff => statistic.data.d != '0'; @override Widget build(BuildContext context) { return DidvanCard( onTap: () => Navigator.of(context).pushNamed(Routes.statisticDetails, arguments: { 'onMarkChanged': (value) => onMarkChanged(statistic.id, value), 'label': statistic.label, 'title': statistic.title, 'marked': isMarked, }), child: Column( children: [ Row( children: [ if (isMarked) Icon( Icons.star, color: Theme.of(context).colorScheme.yellow, size: 18, ), DidvanText( statistic.title, style: Theme.of(context).textTheme.bodyLarge, ), const Spacer(), if (_hasDiff) DidvanText( '(${statistic.data.d})', color: _diffColor(context), ), if (_hasDiff) const SizedBox(width: 8), DidvanText( statistic.data.p, style: Theme.of(context).textTheme.bodyLarge, ) ], ), const SizedBox(height: 8), Row( children: [ Icon( Icons.trending_down, size: 18, color: Theme.of(context).colorScheme.hint, ), DidvanText( statistic.data.l, style: Theme.of(context).textTheme.bodySmall, color: Theme.of(context).colorScheme.hint, ), const SizedBox(width: 8), Icon( Icons.trending_up, size: 18, color: Theme.of(context).colorScheme.hint, ), DidvanText( statistic.data.h, style: Theme.of(context).textTheme.bodySmall, color: Theme.of(context).colorScheme.hint, ), const Spacer(), if (_hasDiff) Icon( statistic.data.dt == 'high' ? DidvanIcons.angle_up_regular : DidvanIcons.angle_down_regular, size: 18, color: _diffColor(context), ), if (_hasDiff) const SizedBox(width: 4), if (_hasDiff) DidvanText( '${statistic.data.dp}%', style: Theme.of(context).textTheme.bodySmall, color: _diffColor(context), ), ], ), ], ), ); } static Widget get placeHolder => const Column( children: [ DidvanCard( child: Column( children: [ SizedBox(height: 4), Row( children: [ ShimmerPlaceholder(width: 80, height: 16), Spacer(), ShimmerPlaceholder(width: 50, height: 14), SizedBox(width: 8), ShimmerPlaceholder(width: 50, height: 16), ], ), SizedBox(height: 16), Row( children: [ ShimmerPlaceholder(width: 150, height: 12), Spacer(), ShimmerPlaceholder(width: 80, height: 12), ], ), ], ), ), SizedBox(height: 20), DidvanCard( child: Column( children: [ SizedBox(height: 4), Row( children: [ ShimmerPlaceholder(width: 80, height: 16), Spacer(), ShimmerPlaceholder(width: 50, height: 14), SizedBox(width: 8), ShimmerPlaceholder(width: 50, height: 16), ], ), SizedBox(height: 16), Row( children: [ ShimmerPlaceholder(width: 150, height: 12), Spacer(), ShimmerPlaceholder(width: 80, height: 12), ], ), ], ), ), ], ); }