Skip to content

Commit

Permalink
improve caching images
Browse files Browse the repository at this point in the history
e reader experience
  • Loading branch information
d-reader-luka committed May 17, 2024
1 parent 150c0fa commit c103ca5
Show file tree
Hide file tree
Showing 53 changed files with 1,137 additions and 690 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ build-prod:
build-prod-apk:
flutter clean && \
flutter build apk --split-per-abi --release --dart-define=apiUrl=$(API_URL_PROD) --dart-define=apiUrlDevnet=$(API_URL_PROD) --dart-define=sentryDsn=${sentryDsn} --flavor prod --target lib/main_prod.dart && \
mv ./build/app/outputs/flutter-apk/app-armeabi-v7a-prod-release.apk ./apks/dReader.apk
mv ./build/app/outputs/flutter-apk/app-arm64-v8a-prod-release.apk ./apks/dReader.apk

start-saga-release:
pre-saga-release create-saga-release publish-saga-update
Expand Down
1 change: 0 additions & 1 deletion lib/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ abstract class Config {
static const String privacyPolicyUrl = "https://dreader.app/privacy-policy";
static const String twitterUrl = 'https://twitter.com/dReaderApp';
static const String discordUrl = 'https://discord.gg/rrZsRvC9mh';
static const String localStoreName = 'local_store';
static String rpcUrlMainnet =
dotenv.get('rpcMainnet', fallback: 'https://api.mainnet-beta.solana.com');
static String rpcUrlDevnet =
Expand Down
8 changes: 8 additions & 0 deletions lib/constants/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const String publicGroupLabel = 'public';
const double comicIssueAspectRatio = 690 / 1000;
const double comicAspectRatio = 1000 / 900;
const double creatorBannerAspectratio = 1920 / 900;
const double comicLogoAspectRatio = 800 / 450;

const String walkthroughAssetsPath = 'assets/images/walkthrough';
const String missingWalletAppText = 'Missing wallet application.';
Expand All @@ -18,3 +19,10 @@ const String usernameCriteriaText =
const int splTokenHighestPriority = 1;
const int chainStatusTimeoutInSeconds = 25;
const int paginatedDataCacheInSeconds = 30;

const String localStoreName = 'local_store';
const String eReaderLocalStoreName = 'eReader_store';

const String eReaderListPositionKey = 'eReader_list_position';
const String eReaderPagePositionKey = 'eReader_page_position';
const String eReaderReadingModeKey = 'reading_mode';
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import 'package:d_reader_flutter/shared/theme/app_colors.dart';
import 'package:d_reader_flutter/shared/utils/screen_navigation.dart';
import 'package:d_reader_flutter/shared/utils/show_snackbar.dart';
import 'package:d_reader_flutter/shared/widgets/buttons/custom_text_button.dart';
import 'package:d_reader_flutter/shared/widgets/icons/secure_password_icon.dart';
import 'package:d_reader_flutter/shared/widgets/textfields/text_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

Expand Down Expand Up @@ -134,23 +134,7 @@ class _SignInScreenState extends ConsumerState<SignInScreen> {
}
return null;
},
suffix: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
ref
.read(obscureTextProvider.notifier)
.update((state) => !state);
},
child: Icon(
ref.watch(obscureTextProvider)
? FontAwesomeIcons.solidEye
: FontAwesomeIcons.solidEyeSlash,
color: ColorPalette.greyscale300,
size: 20,
),
),
),
suffix: const SecurePasswordIcon(),
),
GestureDetector(
onTap: () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import 'package:d_reader_flutter/shared/presentations/providers/global/global_no
import 'package:d_reader_flutter/shared/presentations/providers/global/global_providers.dart';
import 'package:d_reader_flutter/shared/theme/app_colors.dart';
import 'package:d_reader_flutter/shared/widgets/buttons/custom_text_button.dart';
import 'package:d_reader_flutter/shared/widgets/icons/secure_password_icon.dart';
import 'package:d_reader_flutter/shared/widgets/textfields/text_field.dart';
import 'package:email_validator/email_validator.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class SignUpEmailAndPasswordStep extends ConsumerStatefulWidget {
Expand Down Expand Up @@ -110,23 +110,7 @@ class _SignUpEmailAndPasswordStepState
}
return null;
},
suffix: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
ref
.read(obscureTextProvider.notifier)
.update((state) => !state);
},
child: Icon(
ref.watch(obscureTextProvider)
? FontAwesomeIcons.solidEye
: FontAwesomeIcons.solidEyeSlash,
color: ColorPalette.greyscale300,
size: 20,
),
),
),
suffix: const SecurePasswordIcon(),
),
const SizedBox(
height: 8,
Expand Down
45 changes: 30 additions & 15 deletions lib/features/comic/presentation/widgets/cards/comic_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,24 @@ class ComicCard extends ConsumerWidget {
children: [
AspectRatio(
aspectRatio: comicAspectRatio,
child: CachedImageBgPlaceholder(
imageUrl: comic.cover,
opacity: .4,
padding: EdgeInsets.zero,
overrideBorderRadius: const BorderRadius.only(
topLeft: Radius.circular(
8,
child: LayoutBuilder(builder: (context, constraint) {
return CachedImageBgPlaceholder(
width: constraint.maxWidth.toDouble(),
cacheHeight: constraint.maxHeight.cacheSize(context),
cacheWidth: constraint.maxWidth.cacheSize(context),
imageUrl: comic.cover,
opacity: .4,
padding: EdgeInsets.zero,
overrideBorderRadius: const BorderRadius.only(
topLeft: Radius.circular(
8,
),
topRight: Radius.circular(
8,
),
),
topRight: Radius.circular(
8,
),
),
),
);
}),
),
Positioned.fill(
top: 0,
Expand All @@ -67,11 +72,21 @@ class ComicCard extends ConsumerWidget {
? Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(
horizontal: 12,
horizontal: 8,
vertical: 4,
),
child: CachedNetworkImage(
imageUrl: comic.logo,
child: AspectRatio(
aspectRatio: comicLogoAspectRatio,
child: LayoutBuilder(
builder: (context, constraint) {
return CachedNetworkImage(
imageUrl: comic.logo,
memCacheWidth: constraint.maxWidth
.cacheSize(context),
memCacheHeight: constraint.maxHeight
.cacheSize(context),
);
}),
),
)
: const SizedBox(),
Expand Down
53 changes: 33 additions & 20 deletions lib/features/comic/presentation/widgets/details/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,31 +115,45 @@ class _ComicDetailsScaffoldState extends State<ComicDetailsScaffold>
children: [
AspectRatio(
aspectRatio: comicAspectRatio,
child: CachedImageBgPlaceholder(
imageUrl: widget.comic.cover,
overrideBorderRadius: BorderRadius.circular(0),
foregroundDecoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
ColorPalette.appBackgroundColor,
Colors.transparent,
ColorPalette.appBackgroundColor,
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [0.0, .6406, 1],
child: LayoutBuilder(builder: (context, constraints) {
return CachedImageBgPlaceholder(
imageUrl: widget.comic.cover,
cacheHeight: constraints.maxHeight.cacheSize(context),
cacheWidth: constraints.maxWidth.cacheSize(context),
overrideBorderRadius: BorderRadius.circular(0),
foregroundDecoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
ColorPalette.appBackgroundColor,
Colors.transparent,
ColorPalette.appBackgroundColor,
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
stops: [0.0, .6406, 1],
),
),
),
),
);
}),
),
Positioned.fill(
child: Container(
alignment: Alignment.center,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 4,
),
child: AspectRatio(
aspectRatio: .6,
child: CachedNetworkImage(
imageUrl: widget.comic.logo,
),
aspectRatio: comicLogoAspectRatio,
child: LayoutBuilder(builder: (context, constraint) {
return CachedNetworkImage(
imageUrl: widget.comic.logo,
memCacheWidth:
constraint.maxWidth.cacheSize(context),
memCacheHeight:
constraint.maxHeight.cacheSize(context),
);
}),
),
),
),
Expand Down Expand Up @@ -256,7 +270,6 @@ class _ComicDetailsScaffoldState extends State<ComicDetailsScaffold>
radius: 24,
height: 32,
width: 32,
slug: widget.comic.creator?.slug ?? '',
),
const SizedBox(width: 12),
Expanded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ class ComicIssueCoverScreen extends StatelessWidget {
maxScale: 5,
child: AspectRatio(
aspectRatio: comicIssueAspectRatio,
child: CachedImageBgPlaceholder(
imageUrl: imageUrl,
),
child: LayoutBuilder(builder: (context, constraints) {
return CachedImageBgPlaceholder(
imageUrl: imageUrl,
cacheHeight: constraints.maxHeight.cacheSize(context),
cacheWidth: constraints.maxWidth.cacheSize(context),
);
}),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:d_reader_flutter/config/config.dart';
import 'package:d_reader_flutter/constants/constants.dart';
import 'package:d_reader_flutter/constants/routes.dart';
Expand All @@ -8,6 +7,7 @@ import 'package:d_reader_flutter/features/comic_issue/domain/models/comic_issue.
import 'package:d_reader_flutter/features/comic_issue/presentation/providers/comic_issue_providers.dart';
import 'package:d_reader_flutter/features/comic_issue/presentation/providers/controller/comic_issue_controller.dart';
import 'package:d_reader_flutter/features/comic_issue/presentation/widgets/tabs/about/mint_info_container.dart';
import 'package:d_reader_flutter/features/creator/presentation/utils/utils.dart';
import 'package:d_reader_flutter/shared/domain/providers/solana/solana_providers.dart';
import 'package:d_reader_flutter/shared/exceptions/exceptions.dart';
import 'package:d_reader_flutter/features/wallet/presentation/providers/wallet_providers.dart';
Expand All @@ -27,7 +27,6 @@ import 'package:d_reader_flutter/shared/widgets/icons/favorite_icon_count.dart';
import 'package:d_reader_flutter/shared/widgets/icons/rating_icon.dart';
import 'package:d_reader_flutter/shared/widgets/unsorted/mint_price_widget.dart';
import 'package:d_reader_flutter/shared/widgets/unsorted/solana_price.dart';
import 'package:d_reader_flutter/features/creator/presentation/widgets/avatar.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -153,6 +152,11 @@ class _ComicIssueDetailsState extends ConsumerState<ComicIssueDetails>
? 431
: 460,
imageUrl: issue.cover,
cacheHeight:
(MediaQuery.sizeOf(context).height > 780
? 431
: 460)
.cacheSize(context),
overrideBorderRadius: BorderRadius.circular(0),
foregroundDecoration: BoxDecoration(
gradient: LinearGradient(
Expand Down Expand Up @@ -185,19 +189,20 @@ class _ComicIssueDetailsState extends ConsumerState<ComicIssueDetails>
bottom: 16,
),
constraints: const BoxConstraints(
maxWidth: 210,
maxHeight: 304,
maxWidth: 220,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(
8,
),
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(
issue.cover,
),
),
child: AspectRatio(
aspectRatio: comicIssueAspectRatio,
child: LayoutBuilder(
builder: (context, constraints) {
return CachedImageBgPlaceholder(
imageUrl: issue.cover,
cacheWidth: constraints.maxWidth
.cacheSize(context),
cacheHeight: constraints.maxHeight
.cacheSize(context),
);
}),
),
),
],
Expand Down Expand Up @@ -315,13 +320,18 @@ class _ComicIssueDetailsState extends ConsumerState<ComicIssueDetails>
},
child: Row(
children: [
CreatorAvatar(
avatar: issue.creator.avatar,
radius: 24,
height: 32,
width: 32,
slug: issue.creator.slug,
renderAvatar(
context: context,
creator: issue.creator,
height: 24,
width: 24,
),
// CreatorAvatar(
// avatar: issue.creator.avatar,
// radius: 24,
// height: 32,
// width: 32,
// ),
const SizedBox(width: 12),
Expanded(
child: Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,20 @@ class IssueAbout extends ConsumerWidget {
.future,
),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting ||
snapshot.hasError) {
if (snapshot.connectionState == ConnectionState.waiting) {
final currentCandyMachine =
ref.read(candyMachineStateProvider);
if (currentCandyMachine != null &&
currentCandyMachine.address ==
issue.activeCandyMachineAddress) {
return MintInfoContainer(
candyMachineGroups: currentCandyMachine.groups,
totalSupply: currentCandyMachine.supply,
);
}
return const SizedBox();
}
if (snapshot.hasError) {
return const SizedBox();
}
return MintInfoContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class RaritiesWidget extends StatelessWidget {
},
child: CachedImageBgPlaceholder(
imageUrl: covers[index].image,
cacheHeight: 197.cacheSize(context),
cacheWidth: 137.cacheSize(context),
width: 137,
height: 197,
),
Expand Down
Loading

0 comments on commit c103ca5

Please sign in to comment.