-
Notifications
You must be signed in to change notification settings - Fork 2
Miduo/224 optimize login latecy #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -178,10 +178,6 @@ class _SolidLoginState extends State<SolidLogin> with WidgetsBindingObserver { | |
|
|
||
| AssetImage? _resolvedLogo; | ||
|
|
||
| /// Whether asset resolution has completed. | ||
|
|
||
| bool _assetsResolved = false; | ||
|
|
||
| @override | ||
| void initState() { | ||
| super.initState(); | ||
|
|
@@ -233,7 +229,9 @@ class _SolidLoginState extends State<SolidLogin> with WidgetsBindingObserver { | |
| widget.logo, | ||
| 'app_icon', | ||
| ); | ||
| if (mounted) setState(() => _assetsResolved = true); | ||
| // Trigger a rebuild so the higher-quality resolved asset replaces the | ||
| // initial widget.image/widget.logo fallback. | ||
| if (mounted) setState(() {}); | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -269,18 +267,23 @@ class _SolidLoginState extends State<SolidLogin> with WidgetsBindingObserver { | |
|
|
||
| Future<void> _initPackageInfo() async { | ||
| if (!mounted) return; | ||
| // Start fetching app info immediately — it is independent of appDirName. | ||
| final appInfoFuture = getAppNameVersion(); | ||
| await setAppDirName(widget.appDirectory); | ||
| final folders = await generateDefaultFolders(); | ||
| final files = await generateDefaultFiles(); | ||
| // Now that appDirName is set, resolve folders/files in parallel with the | ||
| // already-running appInfo future. | ||
| final results = await Future.wait([ | ||
| generateDefaultFolders(), | ||
| generateDefaultFiles(), | ||
| appInfoFuture, | ||
| ]); | ||
| final customFolders = generateCustomFolders(widget.customFolderPathList); | ||
| if (!mounted) return; | ||
| // Single setState: avoids two separate widget rebuilds. | ||
| setState(() { | ||
| defaultFolders = folders + customFolders; | ||
| defaultFiles = files; | ||
| }); | ||
| final appInfo = await getAppNameVersion(); | ||
| if (!mounted) return; | ||
| setState(() { | ||
| defaultFolders = (results[0] as List<String>) + customFolders; | ||
| defaultFiles = results[1] as Map<dynamic, dynamic>; | ||
| final appInfo = results[2] as ({String name, String version}); | ||
| appName = appInfo.name; | ||
| appVersion = appInfo.version; | ||
| }); | ||
|
|
@@ -317,21 +320,17 @@ class _SolidLoginState extends State<SolidLogin> with WidgetsBindingObserver { | |
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| // Show a loading indicator whilst assets are being resolved. | ||
|
|
||
| if (!_assetsResolved) { | ||
| return const Scaffold(body: Center(child: CircularProgressIndicator())); | ||
| } | ||
|
|
||
| // Use the internal state for theme instead of system brightness. | ||
|
|
||
| final currentTheme = isDarkMode | ||
| ? widget.themeConfig.darkTheme | ||
| : widget.themeConfig.lightTheme; | ||
|
|
||
| // Use resolved image with fallback support. | ||
| // Use resolved image if available, otherwise fall back to the widget's | ||
| // own AssetImage immediately — this prevents the UI being blocked by a | ||
| // loading spinner while assets are resolving in the background. | ||
|
|
||
| final effectiveImage = _resolvedImage ?? SolidConfig.soliduiDefaultImage; | ||
| final effectiveImage = _resolvedImage ?? widget.image; | ||
|
|
||
| // The login box's default image Widget for the left/background panel | ||
| // depending on screen width. | ||
|
|
@@ -388,9 +387,9 @@ class _SolidLoginState extends State<SolidLogin> with WidgetsBindingObserver { | |
| focusNode: _infoFocusNode, | ||
| ); | ||
|
|
||
| // Use resolved logo with fallback support. | ||
| // Use resolved logo if available, otherwise fall back to widget's own logo. | ||
|
|
||
| final effectiveLogo = _resolvedLogo ?? SolidConfig.soliduiDefaultLogo; | ||
| final effectiveLogo = _resolvedLogo ?? widget.logo; | ||
|
|
||
|
Comment on lines
+390
to
393
|
||
| // Build the login panel content. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
Future.wait([...])with heterogeneous futures forces the results into a positionalListand requires runtime casts by index (results[0] as ...). This is brittle and can silently break if any return type changes. A more maintainable approach is to start the typed futures (final foldersFuture = ..., etc.),await Future.wait<void>([foldersFuture, filesFuture, appInfoFuture]), and then read the typed results from the original futures/variables.