Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
whats_new: only show again on a major upgrade
Browse files Browse the repository at this point in the history
wfleischer committed Jan 18, 2025
1 parent a28dc01 commit 8fd254d
Showing 3 changed files with 95 additions and 72 deletions.
23 changes: 23 additions & 0 deletions lib/src/settings/stories/settings_story.dart
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:nwt_reading/src/base/entities/incomplete_notifier.dart';
import 'package:package_info_plus/package_info_plus.dart';

final settingsProvider = AsyncNotifierProvider<SettingsNotifier, Settings>(
SettingsNotifier.new,
@@ -25,6 +26,28 @@ class SettingsNotifier extends IncompleteNotifier<Settings> {

void updateSeenWhatsNewVersion(String seenWhatsNewVersion) =>
updateSettings(seenWhatsNewVersion: seenWhatsNewVersion);

void markWhatsNewAsSeen() async {
final version = (await PackageInfo.fromPlatform()).version;

updateSeenWhatsNewVersion(version);
}

Future<bool> shouldShowWhatsNew() async {
final version = (await PackageInfo.fromPlatform()).version;

while (state.isLoading) {
await Future<void>.delayed(Duration(milliseconds: 100));
}

return state.maybeWhen(
data: (state) {
return state.seenWhatsNewVersion?.split('.')[0] !=
version.split('.')[0];
},
orElse: () => false,
);
}
}

@immutable
142 changes: 71 additions & 71 deletions lib/src/whats_new/presentations/whats_new_dialog.dart
Original file line number Diff line number Diff line change
@@ -4,84 +4,84 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:nwt_reading/src/localization/app_localizations_getter.dart';
import 'package:nwt_reading/src/settings/stories/settings_story.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:url_launcher/url_launcher.dart';

void showWhatsNewDialog(
BuildContext context, WidgetRef ref, String? seenWhatsNewVersion) async {
final version = (await PackageInfo.fromPlatform()).version;
final settingsNotifier = ref.read(settingsProvider.notifier);

if (context.mounted && seenWhatsNewVersion != version) {
final whatsNewDialogOpenSourceText = context.loc.whatsNewDialogOpenSource;
if (await settingsNotifier.shouldShowWhatsNew()) {
// Must be on its own condition for linting.
if (context.mounted) {
final whatsNewDialogOpenSourceText = context.loc.whatsNewDialogOpenSource;

showDialog<String>(
context: context,
barrierDismissible: false,
barrierLabel: 'test',
builder: (BuildContext context) {
return AlertDialog(
key: const Key('whats-new-dialog'),
title: Text(context.loc.whatsNewDialogTitle),
content: SingleChildScrollView(
child: Column(children: [
Image(image: AssetImage('assets/images/whats_new/plans.png')),
SizedBox(height: 15),
Text.rich(TextSpan(
text: context.loc.whatsNewDialogPlans,
)),
SizedBox(height: 30),
SvgPicture.asset(
Theme.of(context).brightness == Brightness.dark
? 'assets/images/whats_new/github_mark_white.svg'
: 'assets/images/whats_new/github_mark.svg',
semanticsLabel: 'GitHub Logo',
width: 30,
height: 30,
),
SizedBox(height: 15),
Text.rich(
TextSpan(
text: whatsNewDialogOpenSourceText.split('GitHub')[0],
children: [
TextSpan(
text: 'GitHub',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
showDialog<String>(
context: context,
barrierDismissible: false,
barrierLabel: 'test',
builder: (BuildContext context) {
return AlertDialog(
key: const Key('whats-new-dialog'),
title: Text(context.loc.whatsNewDialogTitle),
content: SingleChildScrollView(
child: Column(children: [
Image(image: AssetImage('assets/images/whats_new/plans.png')),
SizedBox(height: 15),
Text.rich(TextSpan(
text: context.loc.whatsNewDialogPlans,
)),
SizedBox(height: 30),
SvgPicture.asset(
Theme.of(context).brightness == Brightness.dark
? 'assets/images/whats_new/github_mark_white.svg'
: 'assets/images/whats_new/github_mark.svg',
semanticsLabel: 'GitHub Logo',
width: 30,
height: 30,
),
SizedBox(height: 15),
Text.rich(
TextSpan(
text: whatsNewDialogOpenSourceText.split('GitHub')[0],
children: [
TextSpan(
text: 'GitHub',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
recognizer: TapGestureRecognizer()
..onTap = () {
final url = Uri.parse(
'https://github.com/searchwork/nwt-reading');
launchUrl(url);
},
),
TextSpan(
text: whatsNewDialogOpenSourceText.split('GitHub')[1],
),
recognizer: TapGestureRecognizer()
..onTap = () {
final url = Uri.parse(
'https://github.com/searchwork/nwt-reading');
launchUrl(url);
},
),
TextSpan(
text: whatsNewDialogOpenSourceText.split('GitHub')[1],
),
],
],
),
),
])),
actions: <Widget>[
OutlinedButton(
key: const Key('later'),
child: Text(context.loc.whatsNewDialogLaterButtonText),
onPressed: () => Navigator.pop(context, 'Later'),
),
FilledButton(
key: const Key('got-it'),
child: Text(context.loc.whatsNewDialogGotItButtonText),
onPressed: () {
settingsNotifier.markWhatsNewAsSeen();
Navigator.pop(context, 'Got It');
},
),
),
])),
actions: <Widget>[
OutlinedButton(
key: const Key('later'),
child: Text(context.loc.whatsNewDialogLaterButtonText),
onPressed: () => Navigator.pop(context, 'Later'),
),
FilledButton(
key: const Key('got-it'),
child: Text(context.loc.whatsNewDialogGotItButtonText),
onPressed: () {
ref
.read(settingsProvider.notifier)
.updateSeenWhatsNewVersion(version);
Navigator.pop(context, 'Got It');
},
),
],
);
},
);
],
);
},
);
}
}
}
2 changes: 1 addition & 1 deletion test/test_data.dart
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ const plansPreferenceKey = 'plans';

Future<Map<String, String>> getWhatsNewSeenPreference() async => {
seenWhatsNewVersionPreferenceKey:
(await PackageInfo.fromPlatform()).version
'${(await PackageInfo.fromPlatform()).version.split('.')[0]}.ignored'
};

final Plans testPlans = Plans([

0 comments on commit 8fd254d

Please sign in to comment.