didvan-app/lib/views/home/statistic/widgets/statistic_overview.dart

165 lines
5.3 KiB
Dart

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 == 'low'
? 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.bodyText1,
),
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.bodyText1,
)
],
),
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.caption,
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.caption,
color: Theme.of(context).colorScheme.hint,
),
const Spacer(),
if (_hasDiff)
Icon(
statistic.data.dt == 'low'
? 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.toString() + '%',
style: Theme.of(context).textTheme.caption,
color: _diffColor(context),
),
],
),
],
),
);
}
static Widget get placeHolder => Column(
children: [
DidvanCard(
child: Column(
children: [
const SizedBox(height: 4),
Row(
children: const [
ShimmerPlaceholder(width: 80, height: 16),
Spacer(),
ShimmerPlaceholder(width: 50, height: 14),
SizedBox(width: 8),
ShimmerPlaceholder(width: 50, height: 16),
],
),
const SizedBox(height: 16),
Row(
children: const [
ShimmerPlaceholder(width: 150, height: 12),
Spacer(),
ShimmerPlaceholder(width: 80, height: 12),
],
),
],
),
),
const SizedBox(height: 20),
DidvanCard(
child: Column(
children: [
const SizedBox(height: 4),
Row(
children: const [
ShimmerPlaceholder(width: 80, height: 16),
Spacer(),
ShimmerPlaceholder(width: 50, height: 14),
SizedBox(width: 8),
ShimmerPlaceholder(width: 50, height: 16),
],
),
const SizedBox(height: 16),
Row(
children: const [
ShimmerPlaceholder(width: 150, height: 12),
Spacer(),
ShimmerPlaceholder(width: 80, height: 12),
],
),
],
),
),
],
);
}