Skip to content

Commit

Permalink
feat(routing): add route path params in playerDetail, matchDetail, pl…
Browse files Browse the repository at this point in the history
…ayerChampions
  • Loading branch information
tusharlock10 committed May 11, 2022
1 parent df4f65f commit b473b2c
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 143 deletions.
6 changes: 1 addition & 5 deletions lib/data_classes/loadout/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export './loadout.dart'
show
LoadoutValidationResult,
DraftLoadout,
ShowLoadoutDetailsOptions,
LoadoutScreenArguments;
show LoadoutValidationResult, DraftLoadout, ShowLoadoutDetailsOptions;
12 changes: 1 addition & 11 deletions lib/data_classes/loadout/loadout.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart' hide Card;
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:paladinsedge/models/index.dart'
show Champion, Loadout, LoadoutCard, Card, Player;
show Champion, Loadout, LoadoutCard, Card;

part 'loadout.freezed.dart';

Expand Down Expand Up @@ -46,16 +46,6 @@ class DraftLoadout with _$DraftLoadout {
}
}

class LoadoutScreenArguments {
final Champion champion;
final Player? player;

LoadoutScreenArguments({
required this.champion,
this.player,
});
}

class ShowLoadoutDetailsOptions {
final BuildContext context;
final Champion champion;
Expand Down
1 change: 1 addition & 0 deletions lib/providers/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class _AuthNotifier extends ChangeNotifier {
await utilities.Database.clear();

// providers to clear data from
clearData();
ref.read(champions_provider.champions).clearData();
ref.read(loadout_provider.loadout).clearData();
ref.read(matches_provider.matches).clearData();
Expand Down
24 changes: 8 additions & 16 deletions lib/providers/players.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:paladinsedge/utilities/index.dart' as utilities;
class _PlayersNotifier extends ChangeNotifier {
bool isLoadingPlayerData = false;
bool isLoadingPlayerStatus = false;
String? playerId;
String? playerStatusPlayerId;
models.Player? playerData;
api.PlayerStatusResponse? playerStatus;
Expand Down Expand Up @@ -116,13 +115,12 @@ class _PlayersNotifier extends ChangeNotifier {
}

if (response.exactMatch) {
playerId = response.playerData!.playerId;
playerData = response.playerData;

if (addInSearchHistory) {
if (addInSearchHistory && playerData != null) {
await insertSearchHistory(
playerName: playerData!.name,
playerId: playerId!,
playerId: playerData!.playerId,
);
}
} else {
Expand All @@ -141,14 +139,6 @@ class _PlayersNotifier extends ChangeNotifier {
notifyListeners();
}

/// The the playerId of the player to be shown in profile detail screen
void setPlayerId(String _playerId) {
playerData = null;
playerId = _playerId;

notifyListeners();
}

/// The the playerId of the player to be shown in active match screen
void setPlayerStatusPlayerId(String _playerStatusPlayerId) {
playerStatus = null;
Expand All @@ -158,11 +148,9 @@ class _PlayersNotifier extends ChangeNotifier {
}

void getPlayerData({
String? playerId, // TODO: Make this reqired
required String playerId,
required bool forceUpdate,
}) async {
if (playerId == null) return;

isLoadingPlayerData = true;
utilities.postFrameCallback(notifyListeners);

Expand All @@ -189,11 +177,15 @@ class _PlayersNotifier extends ChangeNotifier {
notifyListeners();
}

void resetPlayerData() {
playerData = null;
utilities.postFrameCallback(notifyListeners);
}

/// Clears all user sensitive data upon logout
void clearData() {
isLoadingPlayerData = false;
isLoadingPlayerStatus = false;
playerId = null;
playerStatusPlayerId = null;
playerData = null;
playerStatus = null;
Expand Down
9 changes: 6 additions & 3 deletions lib/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ final _championDetailRoutes = [
screens.Loadouts.goRouteBuilder(_loadoutsRoutes),
];

final _playerDetailRoutes = [
screens.PlayerChampions.goRoute,
];

final _mainRoutes = [
screens.Login.goRoute,
screens.ChampionDetail.goRouteBuilder(_championDetailRoutes),
screens.PlayerDetail.goRoute,
screens.PlayerDetail.goRouteBuilder(_playerDetailRoutes),
screens.ConnectProfile.goRoute,
screens.Friends.goRoute,
screens.MatchDetail.goRoute,
screens.ActiveMatch.goRoute,
screens.PlayerChampions.goRoute,
screens.Feedback.goRoute,
];

final router = GoRouter(
errorBuilder: screens.NotFound.routeBuilder,
debugLogDiagnostics: constants.isDebug,
initialLocation: screens.Main.routePath,
urlPathStrategy: UrlPathStrategy.hash,
urlPathStrategy: UrlPathStrategy.path,
routes: [screens.Main.goRouteBuilder(_mainRoutes)],
);
9 changes: 6 additions & 3 deletions lib/screens/active_match/active_match_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class ActiveMatchPlayer extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
// Providers
final champions = ref.read(providers.champions).champions;
final playersProvider = ref.read(providers.players);
final playerChampions =
ref.watch(providers.champions.select((_) => _.playerChampions));

Expand Down Expand Up @@ -102,8 +101,12 @@ class ActiveMatchPlayer extends HookConsumerWidget {
() {
if (isPrivatePlayer) return;

playersProvider.setPlayerId(playerInfo.player.playerId);
context.goNamed(screens.PlayerDetail.routeName);
context.goNamed(
screens.PlayerDetail.routeName,
params: {
'playerId': playerInfo.player.playerId,
},
);
},
[],
);
Expand Down
9 changes: 6 additions & 3 deletions lib/screens/app_drawer/app_drawer_player_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class AppDrawerPlayerProfile extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// Providers
final playersProvider = ref.read(providers.players);
final player = ref.watch(providers.auth.select((_) => _.player));

// Variables
Expand All @@ -23,8 +22,12 @@ class AppDrawerPlayerProfile extends HookConsumerWidget {
() {
if (player == null) return;

playersProvider.setPlayerId(player.playerId);
context.goNamed(screens.PlayerDetail.routeName);
context.goNamed(
screens.PlayerDetail.routeName,
params: {
'playerId': player.playerId,
},
);
},
[],
);
Expand Down
89 changes: 61 additions & 28 deletions lib/screens/champion_detail/champion_detail.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:dartx/dartx.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -40,15 +39,29 @@ class ChampionDetail extends HookConsumerWidget {
// Providers
final isGuest = ref.watch(providers.auth.select((_) => _.isGuest));
final player = ref.watch(providers.auth.select((_) => _.player));
final champions = ref.read(providers.champions).champions;
final championsProvider = ref.read(providers.champions);
final champions = ref.watch(providers.champions.select((_) => _.champions));
final isLoadingCombinedChampions = ref.watch(
providers.champions.select((_) => _.isLoadingCombinedChampions),
);

// State
final hideLoadoutFab = useState(false);

// Variables
final textTheme = Theme.of(context).textTheme;
final champion = champions.firstOrNullWhere(
(_) => _.championId == championId,
final champion = championsProvider.findChampion(championId);

// Effects
useEffect(
() {
if (champions.isEmpty) {
championsProvider.loadCombinedChampions(false);
}

return;
},
[champions],
);

// Methods
Expand Down Expand Up @@ -100,7 +113,15 @@ class ChampionDetail extends HookConsumerWidget {
);

return champion == null
? const screens.NotFound()
? isLoadingCombinedChampions
? const Scaffold(
body: widgets.LoadingIndicator(
lineWidth: 2,
size: 28,
label: Text('Getting champion'),
),
)
: const screens.NotFound()
: Scaffold(
floatingActionButton: SizedBox(
height: 40,
Expand All @@ -127,32 +148,44 @@ class ChampionDetail extends HookConsumerWidget {
),
),
),
body: NotificationListener<ScrollNotification>(
onNotification: onScrollNotification,
child: CustomScrollView(
slivers: [
ChampionDetailAppBar(champion: champion),
SliverList(
delegate: SliverChildListDelegate(
[
ChampionDetailHeading(champion: champion),
const ChampionDetailTitleLabel(label: 'Lore'),
ChampionDetailLore(champion: champion),
const ChampionDetailTitleLabel(label: 'Talents'),
ChampionDetailTalents(champion: champion),
const ChampionDetailTitleLabel(label: 'Abilities'),
ChampionDetailAbilities(champion: champion),
const ChampionDetailTitleLabel(label: 'Loadout Cards'),
ChampionDetailLoadoutCards(champion: champion),
const ChampionDetailTitleLabel(label: 'Your Stats'),
ChampionDetailPlayerStats(champion: champion),
const SizedBox(height: 50),
body: isLoadingCombinedChampions
? const widgets.LoadingIndicator(
lineWidth: 2,
size: 28,
label: Text('Getting champion'),
)
: NotificationListener<ScrollNotification>(
onNotification: onScrollNotification,
child: CustomScrollView(
slivers: [
ChampionDetailAppBar(champion: champion),
SliverList(
delegate: SliverChildListDelegate(
[
ChampionDetailHeading(champion: champion),
const ChampionDetailTitleLabel(label: 'Lore'),
ChampionDetailLore(champion: champion),
const ChampionDetailTitleLabel(label: 'Talents'),
ChampionDetailTalents(champion: champion),
const ChampionDetailTitleLabel(
label: 'Abilities',
),
ChampionDetailAbilities(champion: champion),
const ChampionDetailTitleLabel(
label: 'Loadout Cards',
),
ChampionDetailLoadoutCards(champion: champion),
const ChampionDetailTitleLabel(
label: 'Your Stats',
),
ChampionDetailPlayerStats(champion: champion),
const SizedBox(height: 50),
],
),
),
],
),
),
],
),
),
);
}

Expand Down
9 changes: 6 additions & 3 deletions lib/screens/friends/friend_selected.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class FriendSelected extends HookConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
// Providers
final playersProvider = ref.read(providers.players);
final playerStatus =
ref.watch(providers.players.select((_) => _.playerStatus));
final favouriteFriends =
Expand All @@ -38,8 +37,12 @@ class FriendSelected extends HookConsumerWidget {
() {
if (selectedFriend == null) return;

playersProvider.setPlayerId(selectedFriend!.playerId);
context.goNamed(screens.PlayerDetail.routeName);
context.goNamed(
screens.PlayerDetail.routeName,
params: {
'playerId': selectedFriend!.playerId,
},
);
},
[selectedFriend],
);
Expand Down
9 changes: 6 additions & 3 deletions lib/screens/home/home_favourite_friend_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ class HomeFavouriteFriendItem extends HookConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
// Providers
final authProvider = ref.read(providers.auth);
final playersProvider = ref.read(providers.players);

// Variables
final textTheme = Theme.of(context).textTheme;

// Methods
final onPressFriend = useCallback(
() {
playersProvider.setPlayerId(friend.playerId);
context.goNamed(screens.PlayerDetail.routeName);
context.goNamed(
screens.PlayerDetail.routeName,
params: {
'playerId': friend.playerId,
},
);
},
[friend],
);
Expand Down
16 changes: 12 additions & 4 deletions lib/screens/loadouts/loadouts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class Loadouts extends HookConsumerWidget {
],
),
),
loadouts != null && champion != null
loadouts != null && loadouts.isNotEmpty && champion != null
? SliverPadding(
padding: EdgeInsets.only(
right: horizontalPadding,
Expand Down Expand Up @@ -280,9 +280,17 @@ class Loadouts extends HookConsumerWidget {
size: 28,
label: Text('Getting loadouts'),
)
: const Center(
child: Text('Unable to fetch loadouts'),
),
: loadouts != null &&
champion != null &&
loadouts.isEmpty
? Center(
child: Text(
'No loadouts found for ${champion.name}',
),
)
: const Center(
child: Text('Unable to fetch loadouts'),
),
),
],
),
Expand Down
Loading

0 comments on commit b473b2c

Please sign in to comment.