Skip to content

Commit

Permalink
Show tutorial on first enter
Browse files Browse the repository at this point in the history
  • Loading branch information
Carapacik committed Dec 3, 2023
1 parent f25676a commit 0451a9c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/feature/components/widget/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class CustomDrawer extends StatelessWidget {
await navigator.push(
MaterialPageRoute<void>(
builder: (context) => const TutorialPage(),
fullscreenDialog: true,
),
);
},
Expand Down Expand Up @@ -92,6 +93,7 @@ class CustomDrawer extends StatelessWidget {
await navigator.push(
MaterialPageRoute<void>(
builder: (context) => const AboutPage(),
fullscreenDialog: true,
),
);
},
Expand Down
11 changes: 11 additions & 0 deletions lib/src/feature/game/data/game_datasource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ abstract interface class GameDataSource {
GameResult? loadDailyFromCache(String dictionary, String date);

GameResult? loadLvlFromCache(String dictionary);

bool get isFirstEnter;

Future<void> saveFirstEnter();
}

final class GameDataSourceImpl implements GameDataSource {
Expand All @@ -22,6 +26,13 @@ final class GameDataSourceImpl implements GameDataSource {
final SharedPreferences _sharedPreferences;

static const _boardPrefix = 'board';
static const _firstEnterPrefix = 'is_first_enter';

@override
bool get isFirstEnter => _sharedPreferences.getBool(_firstEnterPrefix) ?? true;

@override
Future<void> saveFirstEnter() => _sharedPreferences.setBool(_firstEnterPrefix, false);

@override
Future<void> saveDailyBoard(String dictionary, String date, GameResult savedResult) async {
Expand Down
10 changes: 10 additions & 0 deletions lib/src/feature/game/data/game_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import 'package:wordly/src/feature/game/model/game_result.dart';
abstract interface class IGameRepository {
Future<void> init();

bool get isFirstEnter;

Future<void> saveFirstEnter();

Map<String, String> currentDictionary(Locale dictionary);

String generateSecretWord(Locale dictionary, {int levelNumber = 0});
Expand Down Expand Up @@ -82,4 +86,10 @@ final class GameRepository implements IGameRepository {
@override
Future<void> saveLvlBoard(Locale dictionary, GameResult savedResult) =>
_gameDataSource.saveLvlBoard(dictionary.languageCode, savedResult);

@override
bool get isFirstEnter => _gameDataSource.isFirstEnter;

@override
Future<void> saveFirstEnter() => _gameDataSource.saveFirstEnter();
}
13 changes: 13 additions & 0 deletions lib/src/feature/game/widget/game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:wordly/src/feature/game/widget/words_grid.dart';
import 'package:wordly/src/feature/level/widget/level_page.dart';
import 'package:wordly/src/feature/settings/widget/settings_scope.dart';
import 'package:wordly/src/feature/statistic/widget/statistic_page.dart';
import 'package:wordly/src/feature/tutorial/widget/tutorial_page.dart';

class GamePage extends StatefulWidget {
const GamePage({super.key});
Expand All @@ -31,6 +32,18 @@ class _GamePageState extends State<GamePage> {
super.initState();
_focusNode = FocusNode();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (context.dependencies.gameRepository.isFirstEnter) {
unawaited(context.dependencies.gameRepository.saveFirstEnter());
unawaited(
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => const TutorialPage(),
fullscreenDialog: true,
),
),
);
return;
}
final bloc = context.read<GameBloc>();
final state = bloc.state;
if (state.isResultState) {
Expand Down

0 comments on commit 0451a9c

Please sign in to comment.