Skip to content

Commit

Permalink
feat: Expand leaderboard a little with level and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-goldner committed Jun 19, 2024
1 parent 955221e commit a92f5c2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 59 deletions.
2 changes: 0 additions & 2 deletions lib/core/cubit/booster_item_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class BoosterItemCubit extends Cubit<BoosterItemState> {
}
final newItemsAmount = itemsAmount + amount;

print(state.items);

emit(
BoosterItemStateLoaded({
...state.items,
Expand Down
109 changes: 59 additions & 50 deletions lib/features/leaderboard/leaderboard.dart
Original file line number Diff line number Diff line change
@@ -1,65 +1,74 @@
import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pushup_bro/core/cubit/db_cubit.dart';
import 'package:pushup_bro/core/extensions/list_ext.dart';
import 'package:pushup_bro/core/model/user.dart';
import 'package:pushup_bro/features/leaderboard/widgets/leaderboard_profile.dart';

class Leaderboard extends StatelessWidget {
Leaderboard({super.key});
const Leaderboard({super.key});
static const routeName = '/leaderboard';

final List<User> leaderBoardUsers = [
...List.generate(
100,
(index) => User(
name: 'User $index',
image: '',
streak: 0,
longestStreak: 0,
level: 0,
xp: 0,
friends: [],
@override
Widget build(BuildContext context) {
final user = context.read<DBCubit>().state.user;

final leaderBoardUsers = <User>[
...List.generate(
100,
(index) => User(
name: 'User $index',
image: '',
streak: 0,
longestStreak: 0,
level: math.Random().nextInt(10),
xp: 0,
friends: [],
),
),
),
];
user.copyWith(name: 'YOU'),
]..sort((a, b) => b.level.compareTo(a.level));

@override
Widget build(BuildContext context) => SafeArea(
bottom: false,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: Column(
children: [
const SizedBox(height: 64),
const SearchBar(
hintText: 'Search',
),
Flexible(
child: ListView(
children: [
...leaderBoardUsers.mapIndexed(
(index, user) => Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: LeaderboardProfile(
user: user,
ranking: index + 1,
),
),
const Divider(
indent: 60,
endIndent: 16,
return SafeArea(
bottom: false,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
),
child: Column(
children: [
const SizedBox(height: 64),
const SearchBar(
hintText: 'Search',
),
Flexible(
child: ListView(
children: [
...leaderBoardUsers.mapIndexed(
(index, user) => Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 16),
child: LeaderboardProfile(
user: user,
ranking: index + 1,
),
],
),
),
const Divider(
indent: 60,
endIndent: 16,
),
],
),
],
),
),
],
),
],
),
),
],
),
);
),
);
}
}
16 changes: 13 additions & 3 deletions lib/features/leaderboard/widgets/leaderboard_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ class LeaderboardProfile extends StatelessWidget {
user.toMinimizedUser(),
leadingItem: Padding(
padding: const EdgeInsets.only(right: 8),
child: Text(
'#$ranking',
style: context.textTheme.bodyLarge,
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'#$ranking',
style: context.textTheme.bodyLarge,
),
Text(
context.l10n.level(user.level),
style: context.textTheme.bodyMedium
?.copyWith(fontWeight: FontWeight.bold),
),
],
),
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:carbon_icons/carbon_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pushup_bro/core/extensions/build_context_ext.dart';
import 'package:pushup_bro/features/pushup_tracking/cubit/news_cubit.dart';
import 'package:pushup_bro/features/pushup_tracking/cubit/news_state.dart';

class PushupTrackingTopRow extends StatelessWidget {
const PushupTrackingTopRow({
Expand Down Expand Up @@ -54,10 +57,12 @@ class PushupTrackingTopRow extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.all(4),
child: Center(
child: Text(
'1',
style: context.textTheme.labelLarge?.copyWith(
fontWeight: FontWeight.bold,
child: BlocBuilder<NewsCubit, NewsState>(
builder: (context, state) => Text(
state.news.length.toString(),
style: context.textTheme.labelLarge?.copyWith(
fontWeight: FontWeight.bold,
),
),
),
),
Expand Down

0 comments on commit a92f5c2

Please sign in to comment.