mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-12-25 15:40:40 +00:00
show release notes dialog after update
This commit is contained in:
parent
4e76128e2b
commit
2b600b2b2d
5 changed files with 95 additions and 11 deletions
|
@ -32,6 +32,8 @@ class UserPreferencesService {
|
||||||
static const primaryColorKey = "primaryColor";
|
static const primaryColorKey = "primaryColor";
|
||||||
static const dynamicColorKey = "dynamicColor";
|
static const dynamicColorKey = "dynamicColor";
|
||||||
|
|
||||||
|
static const seenChangelogVersionKey = "seenChangelogVersion";
|
||||||
|
|
||||||
final SharedPreferences _sharedPreferences;
|
final SharedPreferences _sharedPreferences;
|
||||||
|
|
||||||
UserPreferencesService(this._sharedPreferences) {
|
UserPreferencesService(this._sharedPreferences) {
|
||||||
|
@ -157,4 +159,7 @@ class UserPreferencesService {
|
||||||
|
|
||||||
bool get dynamicColor => _sharedPreferences.getBool(dynamicColorKey) ?? false;
|
bool get dynamicColor => _sharedPreferences.getBool(dynamicColorKey) ?? false;
|
||||||
set dynamicColor(bool value) => _sharedPreferences.setBool(dynamicColorKey, value);
|
set dynamicColor(bool value) => _sharedPreferences.setBool(dynamicColorKey, value);
|
||||||
|
|
||||||
|
String get seenChangelogVersion => _sharedPreferences.getString(seenChangelogVersionKey) ?? '';
|
||||||
|
set seenChangelogVersion(String value) => _sharedPreferences.setString(seenChangelogVersionKey, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:lightmeter/data/shared_prefs_service.dart';
|
||||||
|
import 'package:lightmeter/screens/shared/release_notes_dialog/state_release_notes.dart';
|
||||||
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
|
||||||
|
class ReleaseNotesBloc extends Cubit<ReleaseNotesState> {
|
||||||
|
final UserPreferencesService _userPreferencesService;
|
||||||
|
|
||||||
|
ReleaseNotesBloc(this._userPreferencesService) : super(const HiddenReleaseNotesDialogState()) {
|
||||||
|
_showDialogIfNeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _showDialogIfNeeded() async {
|
||||||
|
PackageInfo.fromPlatform().then((value) {
|
||||||
|
emit(ShowReleaseNotesDialogState(value.version));
|
||||||
|
if (value.version != _userPreferencesService.seenChangelogVersion) {
|
||||||
|
emit(ShowReleaseNotesDialogState(value.version));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void setChangelogVersion() {
|
||||||
|
_userPreferencesService.seenChangelogVersion = (state as ShowReleaseNotesDialogState).version;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:lightmeter/providers/services_provider.dart';
|
||||||
|
import 'package:lightmeter/screens/shared/release_notes_dialog/bloc_release_notes.dart';
|
||||||
|
import 'package:lightmeter/screens/shared/release_notes_dialog/state_release_notes.dart';
|
||||||
|
import 'package:lightmeter/screens/shared/release_notes_dialog/widget_dialog_release_notes.dart';
|
||||||
|
|
||||||
|
class ReleaseNotesFlow extends StatelessWidget {
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
const ReleaseNotesFlow({required this.child, super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocProvider(
|
||||||
|
create: (context) => ReleaseNotesBloc(ServicesProvider.of(context).userPreferencesService),
|
||||||
|
child: BlocListener<ReleaseNotesBloc, ReleaseNotesState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state is ShowReleaseNotesDialogState) {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (_) => ReleaseNotesDialog(version: state.version),
|
||||||
|
).then((_) => context.read<ReleaseNotesBloc>().setChangelogVersion());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
sealed class ReleaseNotesState {
|
||||||
|
const ReleaseNotesState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class HiddenReleaseNotesDialogState extends ReleaseNotesState {
|
||||||
|
const HiddenReleaseNotesDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class ShowReleaseNotesDialogState extends ReleaseNotesState {
|
||||||
|
final String version;
|
||||||
|
|
||||||
|
const ShowReleaseNotesDialogState(this.version);
|
||||||
|
}
|
|
@ -1,12 +1,14 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart' show rootBundle;
|
import 'package:flutter/services.dart' show rootBundle;
|
||||||
|
import 'package:lightmeter/data/models/supported_locale.dart';
|
||||||
import 'package:lightmeter/generated/l10n.dart';
|
import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
import 'package:lightmeter/providers/user_preferences_provider.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
|
||||||
|
|
||||||
class ReleaseNotesDialog extends StatelessWidget {
|
class ReleaseNotesDialog extends StatelessWidget {
|
||||||
const ReleaseNotesDialog({super.key});
|
final String version;
|
||||||
|
|
||||||
|
const ReleaseNotesDialog({required this.version, super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -16,12 +18,9 @@ class ReleaseNotesDialog extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
FutureBuilder<PackageInfo>(
|
Text(
|
||||||
future: PackageInfo.fromPlatform(),
|
S.of(context).changesInVersion(version),
|
||||||
builder: (context, snapshot) => Text(
|
style: Theme.of(context).textTheme.titleSmall,
|
||||||
S.of(context).changesInVersion(snapshot.data?.version ?? ''),
|
|
||||||
style: Theme.of(context).textTheme.titleSmall,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: Dimens.grid8),
|
const SizedBox(height: Dimens.grid8),
|
||||||
FutureBuilder<String>(
|
FutureBuilder<String>(
|
||||||
|
@ -41,12 +40,19 @@ class ReleaseNotesDialog extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> loadReleaseNotes(BuildContext context) async {
|
Future<String> loadReleaseNotes(BuildContext context) async {
|
||||||
String path(String locale) => 'assets/release_notes/release_notes_$locale.md';
|
late final String localeName;
|
||||||
|
|
||||||
|
switch (UserPreferencesProvider.localeOf(context)) {
|
||||||
|
case SupportedLocale.ru:
|
||||||
|
localeName = SupportedLocale.ru.name;
|
||||||
|
default:
|
||||||
|
localeName = SupportedLocale.en.name;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return rootBundle.loadString(path(UserPreferencesProvider.localeOf(context).name));
|
return rootBundle.loadString('assets/release_notes/release_notes_${localeName}_$version.md');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return rootBundle.loadString(path('en'));
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue