Skip to content

Commit

Permalink
feat: revamp puzzle page ui, remove sudoku page
Browse files Browse the repository at this point in the history
  • Loading branch information
thisissandipp committed Jul 20, 2024
1 parent 2a24f17 commit d202fe6
Show file tree
Hide file tree
Showing 38 changed files with 1,412 additions and 973 deletions.
Binary file added assets/icons/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sudoku/api/api.dart';
import 'package:sudoku/home/home.dart';
import 'package:sudoku/l10n/l10n.dart';
import 'package:sudoku/puzzle/puzzle.dart';
import 'package:sudoku/theme/theme.dart';

class App extends StatelessWidget {
const App({
required SudokuAPI apiClient,
required PuzzleRepository puzzleRepository,
super.key,
}) : _apiClient = apiClient;
}) : _apiClient = apiClient,
_puzzleRepository = puzzleRepository;

final SudokuAPI _apiClient;
final PuzzleRepository _puzzleRepository;

@override
Widget build(BuildContext context) {
return RepositoryProvider<SudokuAPI>.value(
value: _apiClient,
return MultiRepositoryProvider(
providers: [
RepositoryProvider<SudokuAPI>.value(
value: _apiClient,
),
RepositoryProvider<PuzzleRepository>.value(
value: _puzzleRepository,
),
],
child: const AppView(),
);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/assets/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ abstract class Assets {

/// Gemini icon.
static const geminiIcon = 'assets/icons/gemini.png';

/// Heart icon.
static const heartIcon = 'assets/icons/heart.png';
}
9 changes: 7 additions & 2 deletions lib/home/bloc/home_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,30 @@ import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:sudoku/api/api.dart';
import 'package:sudoku/models/models.dart';
import 'package:sudoku/puzzle/puzzle.dart';

part 'home_event.dart';
part 'home_state.dart';

class HomeBloc extends Bloc<HomeEvent, HomeState> {
HomeBloc({
required SudokuAPI apiClient,
required PuzzleRepository puzzleRepository,
}) : _apiClient = apiClient,
_puzzleRepository = puzzleRepository,
super(const HomeState()) {
on<SudokuCreationRequested>(_onSudokuCreationRequested);
}

final SudokuAPI _apiClient;
final PuzzleRepository _puzzleRepository;

FutureOr<void> _onSudokuCreationRequested(
SudokuCreationRequested event,
Emitter<HomeState> emit,
) async {
emit(
state.copyWith(
sudoku: () => null,
difficulty: () => event.difficulty,
sudokuCreationStatus: () => SudokuCreationStatus.inProgress,
sudokuCreationError: () => null,
Expand All @@ -35,9 +38,11 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
final sudoku = await _apiClient.createSudoku(
difficulty: event.difficulty,
);
_puzzleRepository.storePuzzle(
puzzle: Puzzle(sudoku: sudoku, difficulty: event.difficulty),
);
emit(
state.copyWith(
sudoku: () => sudoku,
sudokuCreationStatus: () => SudokuCreationStatus.completed,
),
);
Expand Down
5 changes: 0 additions & 5 deletions lib/home/bloc/home_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,28 @@ enum SudokuCreationErrorType { unexpected, invalidRawData, apiClient }

class HomeState extends Equatable {
const HomeState({
this.sudoku,
this.difficulty,
this.sudokuCreationStatus = SudokuCreationStatus.initial,
this.sudokuCreationError,
});

final Sudoku? sudoku;
final Difficulty? difficulty;
final SudokuCreationStatus sudokuCreationStatus;
final SudokuCreationErrorType? sudokuCreationError;

@override
List<Object?> get props => [
sudoku,
difficulty,
sudokuCreationStatus,
sudokuCreationError,
];

HomeState copyWith({
Sudoku? Function()? sudoku,
Difficulty? Function()? difficulty,
SudokuCreationStatus Function()? sudokuCreationStatus,
SudokuCreationErrorType? Function()? sudokuCreationError,
}) {
return HomeState(
sudoku: sudoku != null ? sudoku() : this.sudoku,
difficulty: difficulty != null ? difficulty() : this.difficulty,
sudokuCreationStatus: sudokuCreationStatus != null
? sudokuCreationStatus()
Expand Down
8 changes: 4 additions & 4 deletions lib/home/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:sudoku/home/home.dart';
import 'package:sudoku/l10n/l10n.dart';
import 'package:sudoku/layout/layout.dart';
import 'package:sudoku/models/models.dart';
import 'package:sudoku/sudoku/sudoku.dart';
import 'package:sudoku/puzzle/puzzle.dart';
import 'package:sudoku/typography/typography.dart';
import 'package:sudoku/widgets/widgets.dart';

Expand All @@ -25,6 +25,7 @@ class HomePage extends StatelessWidget {
return BlocProvider<HomeBloc>(
create: (context) => HomeBloc(
apiClient: context.read<SudokuAPI>(),
puzzleRepository: context.read<PuzzleRepository>(),
),
child: const HomeView(),
);
Expand Down Expand Up @@ -54,13 +55,12 @@ class HomeView extends StatelessWidget {
);
}

if (state.sudoku != null &&
state.sudokuCreationStatus == SudokuCreationStatus.completed) {
if (state.sudokuCreationStatus == SudokuCreationStatus.completed) {
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute<void>(
builder: (context) => SudokuPage(sudoku: state.sudoku!),
builder: (context) => const PuzzlePage(),
),
);
}
Expand Down
25 changes: 21 additions & 4 deletions lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
"@sudokuGameSubtitle": {
"description": "Text shown in Home Page for Medium and Large screen as the subtitle"
},
"sudokuAppBarTitle": "New Sudoku Game",
"@sudokuAppBarTitle": {
"description": "Text shown in the AppBar of the Sudoku Page"
},
"resumeTimerButtonText": "Resume the puzzle",
"@resumeTimerButtonText": {
"description": "Text shown in the FloatingActionButton of the Sudoku Board"
Expand Down Expand Up @@ -96,5 +92,26 @@
"errorClientDialogSubtitle": "There has been an error while communicating to the backend service. Please try again. If this issue persists, please try after some time.",
"@errorClientDialogSubtitle": {
"description": "Text shown as subtitle in the error due to client dialog in Home Page"
},
"puzzleAppBarDifficulty": "{difficulty, select, easy{Easy} medium{Medium} difficult{Difficult} expert{Expert} other{New}}",
"@puzzleAppBarDifficulty": {
"description": "Text shown in app bar of the Puzzle Page",
"placeholders": {
"difficulty": {
"type": "String"
}
}
},
"puzzleAppBarSudoku": "Sudoku",
"@puzzleAppBarSudoku": {
"description": "Text shown in app bar of the Puzzle Page"
},
"eraseInputButtonText": "Erase number",
"@eraseInputButtonText": {
"description": "Text shown in the input erase button in Puzzle Page"
},
"sudokuLoadingText": "Building your sudoku",
"@sudokuLoadingText": {
"description": "Text shown when sudoku is getting initialized in Puzzle Page"
}
}
11 changes: 10 additions & 1 deletion lib/main_development.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import 'package:sudoku/api/api.dart';
import 'package:sudoku/app/app.dart';
import 'package:sudoku/bootstrap.dart';
import 'package:sudoku/cache/cache.dart';
import 'package:sudoku/env/env.dart';
import 'package:sudoku/puzzle/puzzle.dart';

void main() {
bootstrap(() {
final apiClient = SudokuDioClient(baseUrl: Env.apiBaseUrl);
return App(apiClient: apiClient);

final cacheClient = CacheClient();
final puzzleRepository = PuzzleRepository(cacheClient: cacheClient);

return App(
apiClient: apiClient,
puzzleRepository: puzzleRepository,
);
});
}
11 changes: 10 additions & 1 deletion lib/main_production.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import 'package:sudoku/api/api.dart';
import 'package:sudoku/app/app.dart';
import 'package:sudoku/bootstrap.dart';
import 'package:sudoku/cache/cache.dart';
import 'package:sudoku/env/env.dart';
import 'package:sudoku/puzzle/puzzle.dart';

void main() {
bootstrap(() {
final apiClient = SudokuDioClient(baseUrl: Env.apiBaseUrl);
return App(apiClient: apiClient);

final cacheClient = CacheClient();
final puzzleRepository = PuzzleRepository(cacheClient: cacheClient);

return App(
apiClient: apiClient,
puzzleRepository: puzzleRepository,
);
});
}
11 changes: 10 additions & 1 deletion lib/main_staging.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import 'package:sudoku/api/api.dart';
import 'package:sudoku/app/app.dart';
import 'package:sudoku/bootstrap.dart';
import 'package:sudoku/cache/cache.dart';
import 'package:sudoku/env/env.dart';
import 'package:sudoku/puzzle/puzzle.dart';

void main() {
bootstrap(() {
final apiClient = SudokuDioClient(baseUrl: Env.apiBaseUrl);
return App(apiClient: apiClient);

final cacheClient = CacheClient();
final puzzleRepository = PuzzleRepository(cacheClient: cacheClient);

return App(
apiClient: apiClient,
puzzleRepository: puzzleRepository,
);
});
}
2 changes: 2 additions & 0 deletions lib/puzzle/puzzle.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export 'bloc/puzzle_bloc.dart';
export 'models/models.dart';
export 'repository/puzzle_repository.dart';
export 'view/view.dart';
export 'widgets/widgets.dart';
Loading

0 comments on commit d202fe6

Please sign in to comment.