Skip to content

Commit

Permalink
Make progress bar width dynamic based on digit count and shorten larg…
Browse files Browse the repository at this point in the history
…e numbers

- Adjusted progress bar width to dynamically scale based on the number of digits in total points, achievements, etc., providing better visual alignment.
- Implemented formatting to shorten large numbers (e.g., 1500 becomes 1.5K) for improved readability.
  • Loading branch information
Jcheng777 committed Nov 6, 2024
1 parent 5e0fdf6 commit dfaa272
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions game/lib/widget/progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,33 @@ class LoadingBar extends StatelessWidget {
this.totalTasks,
);

String formatNumber(int number) {
if (number < 1000) {
return number.toString();
} else {
return (number / 1000).toStringAsFixed(1) + 'K';
}
}

double calculateWidthMultiplier(int number) {
int length = number.toString().length;
if (length == 1) {
return 0.5;
} else if (length == 2) {
return 0.47;
} else {
return 0.43;
}
}

@override
Widget build(BuildContext context) {
double widthMultiplier = calculateWidthMultiplier(totalTasks);

return Row(
children: [
Container(
width: MediaQuery.sizeOf(context).width * 0.5,
width: MediaQuery.sizeOf(context).width * widthMultiplier,
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Stack(children: [
Expand Down Expand Up @@ -66,7 +87,7 @@ class LoadingBar extends StatelessWidget {
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
tasksFinished.toString() + "/" + totalTasks.toString(),
"${formatNumber(tasksFinished)}/${formatNumber(totalTasks)}",
),
),
],
Expand Down

0 comments on commit dfaa272

Please sign in to comment.