From fb12ee7f2ae0407e5ff0dfa7f11f1c5b14f05831 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sat, 16 Mar 2024 21:55:03 +0800 Subject: [PATCH] fix loadLogo --- flutter/lib/common.dart | 37 ++++++++++--------- .../lib/desktop/pages/desktop_home_page.dart | 14 +++---- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/flutter/lib/common.dart b/flutter/lib/common.dart index 2ceee5262..22546e11c 100644 --- a/flutter/lib/common.dart +++ b/flutter/lib/common.dart @@ -3089,24 +3089,25 @@ Color? disabledTextColor(BuildContext context, bool enabled) { } // max 300 x 60 -Widget? loadLogo() { - bool isFound = true; - final image = Image.asset( - 'assets/logo.png', - fit: BoxFit.contain, - errorBuilder: (ctx, error, stackTrace) { - isFound = false; - return Container(); - }, - ); - if (isFound) { - return Container( - constraints: BoxConstraints(maxWidth: 300, maxHeight: 60), - child: image, - ).marginOnly(left: 12, right: 12, top: 12); - } else { - return null; - } +Widget loadLogo() { + return FutureBuilder( + future: rootBundle.load('assets/logo.png'), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + final image = Image.asset( + 'assets/logo.png', + fit: BoxFit.contain, + errorBuilder: (ctx, error, stackTrace) { + return Container(); + }, + ); + return Container( + constraints: BoxConstraints(maxWidth: 300, maxHeight: 60), + child: image, + ).marginOnly(left: 12, right: 12, top: 12); + } + return const Offstage(); + }); } Widget loadIcon(double size) { diff --git a/flutter/lib/desktop/pages/desktop_home_page.dart b/flutter/lib/desktop/pages/desktop_home_page.dart index 9ca609704..ac5e60028 100644 --- a/flutter/lib/desktop/pages/desktop_home_page.dart +++ b/flutter/lib/desktop/pages/desktop_home_page.dart @@ -110,7 +110,6 @@ class _DesktopHomePageState extends State Widget buildLeftPane(BuildContext context) { final isIncomingOnly = bind.isIncomingOnly(); final isOutgoingOnly = bind.isOutgoingOnly(); - final logo = loadLogo(); final children = [ if (!isOutgoingOnly) buildPresetPasswordWarning(), if (bind.isCustomClient()) @@ -133,12 +132,11 @@ class _DesktopHomePageState extends State ), ).marginOnly(top: 6), ), - if (logo != null) - Align( - alignment: Alignment.center, - child: logo.marginOnly(bottom: 0.0), - ), - buildTip(context, logo), + Align( + alignment: Alignment.center, + child: loadLogo(), + ), + buildTip(context), if (!isOutgoingOnly) buildIDBoard(context), if (!isOutgoingOnly) buildPasswordBoard(context), FutureBuilder( @@ -413,7 +411,7 @@ class _DesktopHomePageState extends State ); } - buildTip(BuildContext context, Widget? logo) { + buildTip(BuildContext context) { final isOutgoingOnly = bind.isOutgoingOnly(); return Padding( padding: