mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-30 16:29:30 +01:00
refactor: Make user device list item null safe
This commit is contained in:
parent
55394c21e3
commit
2c4e1332e5
@ -1,3 +1,5 @@
|
|||||||
|
//@dart=2.12
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||||
@ -26,12 +28,12 @@ class UserDeviceListItem extends StatelessWidget {
|
|||||||
|
|
||||||
const UserDeviceListItem(
|
const UserDeviceListItem(
|
||||||
this.userDevice, {
|
this.userDevice, {
|
||||||
@required this.remove,
|
required this.remove,
|
||||||
@required this.rename,
|
required this.rename,
|
||||||
@required this.verify,
|
required this.verify,
|
||||||
@required this.block,
|
required this.block,
|
||||||
@required this.unblock,
|
required this.unblock,
|
||||||
Key key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -49,33 +51,34 @@ class UserDeviceListItem extends StatelessWidget {
|
|||||||
actions: [
|
actions: [
|
||||||
SheetAction(
|
SheetAction(
|
||||||
key: UserDeviceListItemAction.rename,
|
key: UserDeviceListItemAction.rename,
|
||||||
label: L10n.of(context).changeDeviceName,
|
label: L10n.of(context)!.changeDeviceName,
|
||||||
),
|
),
|
||||||
if (keys != null) ...{
|
if (keys != null) ...{
|
||||||
SheetAction(
|
SheetAction(
|
||||||
key: UserDeviceListItemAction.verify,
|
key: UserDeviceListItemAction.verify,
|
||||||
label: L10n.of(context).verifyStart,
|
label: L10n.of(context)!.verifyStart,
|
||||||
),
|
),
|
||||||
if (!keys.blocked)
|
if (!keys.blocked)
|
||||||
SheetAction(
|
SheetAction(
|
||||||
key: UserDeviceListItemAction.block,
|
key: UserDeviceListItemAction.block,
|
||||||
label: L10n.of(context).blockDevice,
|
label: L10n.of(context)!.blockDevice,
|
||||||
isDestructiveAction: true,
|
isDestructiveAction: true,
|
||||||
),
|
),
|
||||||
if (keys.blocked)
|
if (keys.blocked)
|
||||||
SheetAction(
|
SheetAction(
|
||||||
key: UserDeviceListItemAction.unblock,
|
key: UserDeviceListItemAction.unblock,
|
||||||
label: L10n.of(context).unblockDevice,
|
label: L10n.of(context)!.unblockDevice,
|
||||||
isDestructiveAction: true,
|
isDestructiveAction: true,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
SheetAction(
|
SheetAction(
|
||||||
key: UserDeviceListItemAction.remove,
|
key: UserDeviceListItemAction.remove,
|
||||||
label: L10n.of(context).delete,
|
label: L10n.of(context)!.delete,
|
||||||
isDestructiveAction: true,
|
isDestructiveAction: true,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
if (action == null) return;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case UserDeviceListItemAction.rename:
|
case UserDeviceListItemAction.rename:
|
||||||
rename(userDevice);
|
rename(userDevice);
|
||||||
@ -116,10 +119,10 @@ class UserDeviceListItem extends StatelessWidget {
|
|||||||
if (keys != null)
|
if (keys != null)
|
||||||
Text(
|
Text(
|
||||||
keys.blocked
|
keys.blocked
|
||||||
? L10n.of(context).blocked
|
? L10n.of(context)!.blocked
|
||||||
: keys.verified
|
: keys.verified
|
||||||
? L10n.of(context).verified
|
? L10n.of(context)!.verified
|
||||||
: L10n.of(context).unverified,
|
: L10n.of(context)!.unverified,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: keys.blocked
|
color: keys.blocked
|
||||||
? Colors.red
|
? Colors.red
|
||||||
@ -131,8 +134,8 @@ class UserDeviceListItem extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
L10n.of(context).lastActiveAgo(
|
L10n.of(context)!.lastActiveAgo(
|
||||||
DateTime.fromMillisecondsSinceEpoch(userDevice.lastSeenTs)
|
DateTime.fromMillisecondsSinceEpoch(userDevice.lastSeenTs ?? 0)
|
||||||
.localizedTimeShort(context)),
|
.localizedTimeShort(context)),
|
||||||
style: const TextStyle(fontWeight: FontWeight.w300),
|
style: const TextStyle(fontWeight: FontWeight.w300),
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user