refactor: Make most of the utils null safe
This commit is contained in:
parent
110d0506aa
commit
265ef0ebb2
23 changed files with 140 additions and 112 deletions
|
|
@ -1,3 +1,5 @@
|
|||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -8,25 +10,27 @@ import '../date_time_extension.dart';
|
|||
extension PresenceExtension on Presence {
|
||||
String getLocalizedLastActiveAgo(BuildContext context) {
|
||||
if (presence.lastActiveAgo != null && presence.lastActiveAgo != 0) {
|
||||
return L10n.of(context).lastActiveAgo(DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch - presence.lastActiveAgo)
|
||||
.localizedTimeShort(context));
|
||||
return L10n.of(context)!.lastActiveAgo(
|
||||
DateTime.fromMillisecondsSinceEpoch(
|
||||
DateTime.now().millisecondsSinceEpoch -
|
||||
presence.lastActiveAgo!)
|
||||
.localizedTimeShort(context));
|
||||
}
|
||||
return L10n.of(context).lastSeenLongTimeAgo;
|
||||
return L10n.of(context)!.lastSeenLongTimeAgo;
|
||||
}
|
||||
|
||||
String getLocalizedStatusMessage(BuildContext context) {
|
||||
if (presence.statusMsg?.isNotEmpty ?? false) {
|
||||
return presence.statusMsg;
|
||||
return presence.statusMsg!;
|
||||
}
|
||||
if (presence.currentlyActive ?? false) {
|
||||
return L10n.of(context).currentlyActive;
|
||||
return L10n.of(context)!.currentlyActive;
|
||||
}
|
||||
return getLocalizedLastActiveAgo(context);
|
||||
}
|
||||
|
||||
Color get color {
|
||||
switch (presence?.presence ?? PresenceType.offline) {
|
||||
switch (presence.presence) {
|
||||
case PresenceType.online:
|
||||
return Colors.green;
|
||||
case PresenceType.offline:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue