Skip to content
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

Fix Web app crash #110

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/ui/widget/user_profile_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:projectunity/data/core/extensions/context_extension.dart';

// ignore: depend_on_referenced_packages
import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart';

class ImageProfile extends StatelessWidget {
final String? imageUrl;
final double radius;
Expand All @@ -23,6 +20,9 @@ class ImageProfile extends StatelessWidget {
this.iconColor});

Widget setCachedImage(BuildContext context) {
if(kIsWeb){
return Image.network(imageUrl?? pickedImage??'',fit: BoxFit.cover,);
}
Comment on lines +23 to +25
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using CachedNetworkImage for web platform

The current implementation bypasses caching for web platform, which could lead to:

  1. Increased network usage
  2. Poor performance when the same image is loaded multiple times
  3. Inconsistent behavior between web and mobile platforms

Consider using CachedNetworkImage consistently across platforms:

 if(kIsWeb){
-  return Image.network(imageUrl?? pickedImage??'',fit: BoxFit.cover,);
+  return cachedNetworkImage(imageUrl ?? pickedImage ?? '');
 }

Committable suggestion skipped: line range outside the PR's diff.


⚠️ Potential issue

Add error handling and loading state for web platform

The current implementation for web platform lacks error handling and loading states, which could lead to poor user experience if images fail to load.

Consider applying this improvement:

 if(kIsWeb){
-  return Image.network(imageUrl?? pickedImage??'',fit: BoxFit.cover,);
+  return Image.network(
+    imageUrl ?? pickedImage ?? '',
+    fit: BoxFit.cover,
+    loadingBuilder: (context, child, loadingProgress) {
+      if (loadingProgress == null) return child;
+      return Icon(Icons.person,
+          size: radius, color: iconColor ?? context.colorScheme.textDisable);
+    },
+    errorBuilder: (context, error, stackTrace) {
+      return Icon(Icons.person,
+          size: radius, color: iconColor ?? context.colorScheme.textDisable);
+    },
+  );
 }

Committable suggestion skipped: line range outside the PR's diff.

if (imageUrl != null) {
return cachedNetworkImage(imageUrl!);
} else if (pickedImage != null) {
Expand All @@ -45,7 +45,6 @@ class ImageProfile extends StatelessWidget {
return CachedNetworkImage(
fit: BoxFit.cover,
imageUrl: imageUrl,
imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet,
placeholder: (context, string) {
return Icon(Icons.person,
size: radius, color: iconColor ?? context.colorScheme.textDisable);
Expand Down
Loading