-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(status): add online/offline status in player detail
User can now see the player status and active match button will lit up if player is online resolves #275
- Loading branch information
1 parent
ee9419c
commit 9280cc5
Showing
6 changed files
with
204 additions
and
64 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
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
109 changes: 109 additions & 0 deletions
109
lib/screens/player_detail/player_detail_status_indicator.dart
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:jiffy/jiffy.dart'; | ||
import 'package:paladinsedge/providers/index.dart' as providers; | ||
import 'package:paladinsedge/widgets/index.dart' as widgets; | ||
|
||
class PlayerDetailStatusIndicator extends HookConsumerWidget { | ||
const PlayerDetailStatusIndicator({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
// Providers | ||
final player = ref.watch(providers.players.select((_) => _.playerData)); | ||
final isLoadingPlayerStatus = | ||
ref.watch(providers.players.select((_) => _.isLoadingPlayerStatus)); | ||
final playerStatus = | ||
ref.watch(providers.players.select((_) => _.playerStatus)); | ||
|
||
// Variables | ||
final status = playerStatus?.status; | ||
final isOnline = status?.toLowerCase() != "offline" && | ||
status?.toLowerCase() != "unknown" && | ||
status != null; | ||
final isUnknown = status?.toLowerCase() == "unknown" || status == null; | ||
final textTheme = Theme.of(context).textTheme; | ||
|
||
// Methods | ||
final getLastSeen = useCallback( | ||
() { | ||
if (player == null) return ''; | ||
|
||
final lastLoginDate = player.lastLoginDate; | ||
final duration = DateTime.now().difference(lastLoginDate); | ||
if (duration > const Duration(days: 1)) { | ||
return Jiffy(lastLoginDate).yMMMd; | ||
} | ||
|
||
return Jiffy(lastLoginDate).fromNow(); | ||
}, | ||
[player], | ||
); | ||
|
||
return Expanded( | ||
child: Align( | ||
alignment: Alignment.centerRight, | ||
child: Padding( | ||
padding: const EdgeInsets.only(right: 10), | ||
child: isLoadingPlayerStatus || status == null | ||
? Row( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
widgets.LoadingIndicator( | ||
size: 12, | ||
lineWidth: 1.2, | ||
color: textTheme.bodyText1?.color, | ||
), | ||
const SizedBox(width: 5), | ||
Text( | ||
'Status', | ||
style: textTheme.bodyText1?.copyWith(fontSize: 14), | ||
), | ||
], | ||
) | ||
: Column( | ||
crossAxisAlignment: CrossAxisAlignment.end, | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
SizedBox( | ||
height: 10, | ||
width: 10, | ||
child: DecoratedBox( | ||
decoration: BoxDecoration( | ||
borderRadius: const BorderRadius.all( | ||
Radius.circular( | ||
5, | ||
), | ||
), | ||
color: isOnline | ||
? Colors.green | ||
: isUnknown | ||
? Colors.orange | ||
: Colors.red, | ||
), | ||
), | ||
), | ||
const SizedBox(width: 5), | ||
Text( | ||
isOnline | ||
? 'Online' | ||
: isUnknown | ||
? 'Unknown' | ||
: 'Offline', | ||
), | ||
], | ||
), | ||
Text( | ||
isOnline ? status : getLastSeen(), | ||
style: textTheme.bodyText1?.copyWith(fontSize: 12), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
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