Flutter-Ernaehrungsapp/lib/pages/shared_components/secondary_text.dart

65 lines
1.6 KiB
Dart
Raw Normal View History

2023-05-29 12:08:46 +02:00
import 'package:flutter/material.dart';
class SecondaryTextComponent extends StatelessWidget {
final String title;
2023-06-16 11:44:42 +02:00
final int? rank;
2023-05-29 12:08:46 +02:00
2023-06-16 11:44:42 +02:00
const SecondaryTextComponent(this.title, this.rank,{Key? key,}) : super(key: key);
2023-05-29 12:08:46 +02:00
@override
Widget build(BuildContext context) {
2023-06-16 11:44:42 +02:00
final TextStyle textStyle = TextStyle(
color: Colors.grey.shade500,
fontSize: 14,
fontWeight: FontWeight.bold,
2023-05-29 12:08:46 +02:00
);
2023-06-16 11:44:42 +02:00
Widget textWidget;
if (rank != null) {
textWidget = Container(
decoration: BoxDecoration(
color: getRankColor(rank!),
borderRadius: BorderRadius.circular(15),
),
padding: const EdgeInsets.all(8),
child: Row(
children: [
Text(
'$rank.',
style: rank! <= 3 ? textStyle.copyWith(color: Colors.white) :textStyle.copyWith(color: Colors.grey),
),
const SizedBox(width: 4),
Text(
title.toString(),
style: rank! <= 3 ? textStyle.copyWith(color: Colors.white) :textStyle.copyWith(color: Colors.grey),
),
],
),
);
} else {
textWidget = Text(
title.toString(),
style: textStyle,
);
}
return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: textWidget,
);
}
Color getRankColor(int rank) {
if (rank == 1) {
return Colors.amber;
} else if (rank == 2) {
return Colors.grey;
} else if (rank == 3) {
return Colors.brown;
} else {
return Colors.transparent;
}
2023-05-29 12:08:46 +02:00
}
}