Add friends leaderboard, reverse button in add page
All checks were successful
Release / meta (push) Successful in 8s
Release / linux-build (push) Successful in 7m11s
Release / web-build (push) Successful in 5m3s
Release / android-build (push) Successful in 18m23s
Release / release-master (push) Successful in 22s
Release / release-dev (push) Successful in 25s
All checks were successful
Release / meta (push) Successful in 8s
Release / linux-build (push) Successful in 7m11s
Release / web-build (push) Successful in 5m3s
Release / android-build (push) Successful in 18m23s
Release / release-master (push) Successful in 22s
Release / release-dev (push) Successful in 25s
This commit is contained in:
@@ -1,19 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mileograph_flutter/services/data_service.dart';
|
||||
import 'package:mileograph_flutter/services/distance_unit_service.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
enum _LeaderboardScope { global, friends }
|
||||
|
||||
class LeaderboardPanel extends StatelessWidget {
|
||||
class LeaderboardPanel extends StatefulWidget {
|
||||
const LeaderboardPanel({super.key});
|
||||
|
||||
@override
|
||||
State<LeaderboardPanel> createState() => _LeaderboardPanelState();
|
||||
}
|
||||
|
||||
class _LeaderboardPanelState extends State<LeaderboardPanel> {
|
||||
_LeaderboardScope _scope = _LeaderboardScope.global;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = context.watch<DataService>();
|
||||
final distanceUnits = context.watch<DistanceUnitService>();
|
||||
final leaderboard = data.homepageStats?.leaderboard ?? [];
|
||||
final leaderboard = _scope == _LeaderboardScope.global
|
||||
? (data.homepageStats?.leaderboard ?? [])
|
||||
: data.friendsLeaderboard;
|
||||
final loading = _scope == _LeaderboardScope.global
|
||||
? data.isHomepageLoading
|
||||
: data.isFriendsLeaderboardLoading;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
if (data.isHomepageLoading && leaderboard.isEmpty) {
|
||||
if (loading && leaderboard.isEmpty) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
@@ -51,6 +63,38 @@ class LeaderboardPanel extends StatelessWidget {
|
||||
style: textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
SegmentedButton<_LeaderboardScope>(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: _LeaderboardScope.global,
|
||||
label: Text('Global'),
|
||||
),
|
||||
ButtonSegment(
|
||||
value: _LeaderboardScope.friends,
|
||||
label: Text('Friends'),
|
||||
),
|
||||
],
|
||||
selected: {_scope},
|
||||
onSelectionChanged: (vals) async {
|
||||
if (vals.isEmpty) return;
|
||||
final selected = vals.first;
|
||||
setState(() => _scope = selected);
|
||||
if (selected == _LeaderboardScope.friends &&
|
||||
data.friendsLeaderboard.isEmpty &&
|
||||
!data.isFriendsLeaderboardLoading) {
|
||||
await data.fetchFriendsLeaderboard();
|
||||
} else if (selected == _LeaderboardScope.global &&
|
||||
(data.homepageStats?.leaderboard.isEmpty ?? true) &&
|
||||
!data.isHomepageLoading) {
|
||||
await data.fetchHomepageStats();
|
||||
}
|
||||
},
|
||||
style: SegmentedButton.styleFrom(
|
||||
visualDensity: VisualDensity.compact,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
Reference in New Issue
Block a user