Skip to content

Commit

Permalink
Use packageVersionProvider directly on Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
bannzai committed Sep 10, 2023
1 parent 6a05885 commit 4c72571
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:pilll/provider/package_info.dart';
import 'package:pilll/utils/analytics.dart';
import 'package:pilll/provider/pill_sheet_group.dart';
import 'package:pilll/provider/pilll_ads.dart';
Expand All @@ -20,6 +21,7 @@ import 'package:pilll/provider/typed_shared_preferences.dart';
import 'package:pilll/provider/auth.dart';
import 'package:pilll/utils/datetime/day.dart';
import 'package:pilll/utils/shared_preference/keys.dart';
import 'package:pilll/utils/version/version.dart';

class AnnouncementBar extends HookConsumerWidget {
const AnnouncementBar({Key? key}) : super(key: key);
Expand Down Expand Up @@ -47,13 +49,17 @@ class AnnouncementBar extends HookConsumerWidget {
final isOverDiscountDeadline = ref.watch(isOverDiscountDeadlineProvider(discountEntitlementDeadlineDate));
final isJaLocale = ref.watch(isJaLocaleProvider);
final pilllAds = ref.watch(pilllAdsProvider).asData?.value;
final packageVersion = ref.watch(packageVersionProvider).asData?.value;
final isAdsDisabled = () {
if (!kDebugMode) {
if (!isJaLocale) {
return true;
}
}
if (pilllAds == null) {
if (pilllAds == null || packageVersion == null) {
return true;
}
if (Version.parse(pilllAds.version).isLessThan(packageVersion)) {
return true;
}
return now().isBefore(pilllAds.startDateTime) || now().isAfter(pilllAds.endDateTime);
Expand Down
13 changes: 0 additions & 13 deletions lib/provider/pilll_ads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,3 @@ import 'package:pilll/provider/package_info.dart';
import 'package:pilll/utils/version/version.dart';

final pilllAdsProvider = StreamProvider((ref) => ref.watch(databaseProvider).pilllAds().snapshots().map((event) => event.data()));
final showsPillAdsProvider = StreamProvider((ref) {
final packageVersion = ref.watch(packageVersionProvider).asData?.value;
final pillAds = ref.watch(pilllAdsProvider).asData?.value;
if (packageVersion == null || pillAds == null) {
return const Stream.empty();
}
final pillAdsVersion = Version.parse(pillAds.version);
if (pillAdsVersion.isLessThan(packageVersion)) {
return Stream.value(false);
}

return Stream.value(true);
});

0 comments on commit 4c72571

Please sign in to comment.