Skip to content

Commit

Permalink
refactor(url): Fix url access to use extensions (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
wizlif authored Apr 3, 2023
1 parent db8283d commit 09d5506
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
4 changes: 4 additions & 0 deletions lib/core/config/network_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
4 changes: 2 additions & 2 deletions lib/domain/crowdaction/crowdaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/participation/participation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ class Participation with _$Participation {
}) = _Participation;

// Participation avatar url
String get avatarUrl => '$baseStaticUrl/$avatar';
String get avatarUrl => avatar.imageUrl;
}
7 changes: 1 addition & 6 deletions lib/presentation/profile/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -121,11 +120,7 @@ class _UserProfilePageState extends State<UserProfilePage> {
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,
),
),
Expand Down
4 changes: 1 addition & 3 deletions lib/presentation/shared_widgets/crowdaction_card.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -71,7 +69,7 @@ class _CrowdActionCardState extends State<CrowdActionCard>
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(
'${dotenv.get('BASE_STATIC_ENDPOINT_URL')}/${widget.crowdAction.images.card}',
widget.crowdAction.cardUrl,
imageRenderMethodForWeb:
ImageRenderMethodForWeb.HttpGet,
errorListener: () {},
Expand Down
3 changes: 1 addition & 2 deletions lib/presentation/shared_widgets/participant_avatars.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: () {},
),
Expand Down

0 comments on commit 09d5506

Please sign in to comment.