opt.: replace first with firstOrNull

This commit is contained in:
lollipopkit
2024-03-06 15:33:00 +08:00
parent fc00b4b961
commit 602ef60bf0
7 changed files with 11 additions and 9 deletions

View File

@@ -148,7 +148,7 @@ class _PingPageState extends State<PingPage>
if (result.results == null || result.results!.isEmpty) {
return '$ip - ${l10n.noResult}';
}
final ttl = result.results?.first.ttl ?? unknown;
final ttl = result.results?.firstOrNull?.ttl ?? unknown;
final loss = result.statistic?.loss ?? unknown;
final min = result.statistic?.min ?? unknown;
final max = result.statistic?.max ?? unknown;

View File

@@ -287,7 +287,8 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
);
if (snippets == null || snippets.isEmpty) return;
final snippet = snippets.first;
final snippet = snippets.firstOrNull;
if (snippet == null) return;
_terminal.textInput(snippet.script);
_terminal.keyInput(TerminalKey.enter);
break;

View File

@@ -665,7 +665,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
/// Issue #97
/// In order to compatible with the Synology NAS
/// which not has '.' and '..' in listdir
if (fs.isNotEmpty && fs.first.filename == '.') {
if (fs.isNotEmpty && fs.firstOrNull?.filename == '.') {
fs.removeAt(0);
}
@@ -673,7 +673,7 @@ class _SftpPageState extends State<SftpPage> with AfterLayoutMixin {
/// Due to [WillPopScope] added in this page
/// There is no need to keep '..' folder in listdir
/// So remove it
if (fs.isNotEmpty && fs.first.filename == '..') {
if (fs.isNotEmpty && fs.firstOrNull?.filename == '..') {
fs.removeAt(0);
}
if (mounted) {