-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expand leaderboard a little with level and sorting
- Loading branch information
1 parent
955221e
commit a92f5c2
Showing
4 changed files
with
81 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters