From 09d55068e54d9a36bd931c5cb9cebd349b4cb6ac Mon Sep 17 00:00:00 2001 From: Isaac Obella Date: Mon, 3 Apr 2023 13:06:57 +0300 Subject: [PATCH] refactor(`url`): Fix url access to use extensions (#390) --- lib/core/config/network_config.dart | 4 ++++ lib/domain/crowdaction/crowdaction.dart | 4 ++-- lib/domain/participation/participation.dart | 2 +- lib/presentation/profile/profile_screen.dart | 7 +------ lib/presentation/shared_widgets/crowdaction_card.dart | 4 +--- lib/presentation/shared_widgets/participant_avatars.dart | 3 +-- 6 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/core/config/network_config.dart b/lib/core/config/network_config.dart index a22f3128..479cc14b 100644 --- a/lib/core/config/network_config.dart +++ b/lib/core/config/network_config.dart @@ -5,3 +5,7 @@ part of '../core.dart'; final baseStaticUrl = dotenv.get('BASE_STATIC_ENDPOINT_URL'); final nullStaticUrl = '$baseStaticUrl/${null}'; + +extension ImageExtension on String { + String get imageUrl => '$baseStaticUrl/$this'; +} diff --git a/lib/domain/crowdaction/crowdaction.dart b/lib/domain/crowdaction/crowdaction.dart index bb75439c..d6a50be7 100644 --- a/lib/domain/crowdaction/crowdaction.dart +++ b/lib/domain/crowdaction/crowdaction.dart @@ -53,10 +53,10 @@ class CrowdAction with _$CrowdAction { : 'Finished'; // Crowdaction banner url - String get bannerUrl => '$baseStaticUrl/${images.banner}'; + String get bannerUrl => images.banner.imageUrl; // Crowdaction card url - String get cardUrl => '$baseStaticUrl/${images.card}'; + String get cardUrl => images.card.imageUrl; } @freezed diff --git a/lib/domain/participation/participation.dart b/lib/domain/participation/participation.dart index c0f88547..ccfcd0eb 100644 --- a/lib/domain/participation/participation.dart +++ b/lib/domain/participation/participation.dart @@ -20,5 +20,5 @@ class Participation with _$Participation { }) = _Participation; // Participation avatar url - String get avatarUrl => '$baseStaticUrl/$avatar'; + String get avatarUrl => avatar.imageUrl; } diff --git a/lib/presentation/profile/profile_screen.dart b/lib/presentation/profile/profile_screen.dart index ea260b62..4129265c 100644 --- a/lib/presentation/profile/profile_screen.dart +++ b/lib/presentation/profile/profile_screen.dart @@ -3,7 +3,6 @@ import 'dart:io'; import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:share_plus/share_plus.dart'; import '../../application/user/profile/profile_bloc.dart'; @@ -121,11 +120,7 @@ class _UserProfilePageState extends State { padding: const EdgeInsets.all(10.0), child: ProfilePicture( image: _image, - profileImage: state - .userProfile?.profile.avatar != - null - ? '${dotenv.get('BASE_STATIC_ENDPOINT_URL')}/${state.userProfile?.profile.avatar}' - : null, + profileImage: state.userProfile?.avatarUrl, maxRadius: 50, ), ), diff --git a/lib/presentation/shared_widgets/crowdaction_card.dart b/lib/presentation/shared_widgets/crowdaction_card.dart index b06f89f8..39e28ed7 100644 --- a/lib/presentation/shared_widgets/crowdaction_card.dart +++ b/lib/presentation/shared_widgets/crowdaction_card.dart @@ -1,10 +1,8 @@ import 'package:auto_route/auto_route.dart'; import 'package:cached_network_image/cached_network_image.dart'; - // ignore: depend_on_referenced_packages import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_dotenv/flutter_dotenv.dart'; import '../../domain/crowdaction/crowdaction.dart'; import '../core/collaction_icons.dart'; @@ -71,7 +69,7 @@ class _CrowdActionCardState extends State image: DecorationImage( fit: BoxFit.cover, image: CachedNetworkImageProvider( - '${dotenv.get('BASE_STATIC_ENDPOINT_URL')}/${widget.crowdAction.images.card}', + widget.crowdAction.cardUrl, imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet, errorListener: () {}, diff --git a/lib/presentation/shared_widgets/participant_avatars.dart b/lib/presentation/shared_widgets/participant_avatars.dart index a357f1cb..e3d614f3 100644 --- a/lib/presentation/shared_widgets/participant_avatars.dart +++ b/lib/presentation/shared_widgets/participant_avatars.dart @@ -3,7 +3,6 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image_platform_interface/cached_network_image_platform_interface.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:shimmer/shimmer.dart'; import '../../application/participation/top_participants/top_participants_bloc.dart'; @@ -78,7 +77,7 @@ class TopParticipantAvatars extends StatelessWidget { radius: 18, backgroundColor: Colors.grey[300], foregroundImage: CachedNetworkImageProvider( - '${dotenv.get('BASE_STATIC_ENDPOINT_URL')}/${participant.avatar}', + participant.avatarUrl, imageRenderMethodForWeb: ImageRenderMethodForWeb.HttpGet, errorListener: () {}, ),