Skip to content

Commit 4312fd5

Browse files
author
Okanlawon Jamiu
committed
Bug Fix
1 parent c5192f3 commit 4312fd5

13 files changed

Lines changed: 54 additions & 36 deletions

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ App and Up Flutter Take Home Project
77
This project is the implementation of the App and Up Flutter Take Home Project.
88

99
### Requirements
10+
1011
- Authentication with Firebase Authentication (Email + at least one social), design of the required screens is up to you.
1112
- Show a list of books gotten from the Google Books API
1213
- Allow the user to search for books
@@ -17,6 +18,21 @@ This project is the implementation of the App and Up Flutter Take Home Project.
1718
- BONUS: handle App responsiveness on the Desktop/Web.
1819

1920
### Implementation
21+
2022
The project was implemented with custom architecture similar to MVVM where
21-
- ViewModels are known as modifiers and
23+
- ViewModels are known as notifiers
2224
- Class Dependencies are managed using the Riverpod Providers
25+
- There are usage of special providers such as StreamProvider, StateProviders that comes with riverpod
26+
- It uses the classic repository approach
27+
- Services for performing network requests, contextless navigation etc are grouped as well
28+
29+
### Build Limitations
30+
31+
- The project depends on an API Key (for calling the books api) which I gitignored so kindly generate an APIKey and place an apiKey constant in lib/src/services/base/api_credentials.dart
32+
- Google Signin will also not work until you add a valid SHA 1 key.
33+
34+
### When building for Web
35+
36+
run with PORT 5000 for Google Signin to Work i.e flutter run -d chrome --web-port=5000
37+
38+
### Find app screenshots here

lib/src/features/books/models/favorite_book.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ class FavoriteBook {
1111
final List<String>? categories;
1212
final String? publisher;
1313
final String? publishedDate;
14+
final String? userId;
1415

1516
FavoriteBook({
1617
required this.id,
1718
required this.title,
1819
this.image,
1920
this.averageRatings,
2021
required this.maturityRating,
21-
this.description = 'No Description',
22+
this.description,
2223
this.authors,
2324
this.categories,
2425
this.publisher,
2526
this.publishedDate,
27+
this.userId,
2628
});
2729

2830
factory FavoriteBook.fromDocumentSnapshot(
@@ -38,6 +40,7 @@ class FavoriteBook {
3840
categories: List<String>.from(snapshot.data()?['categories'] ?? []),
3941
publishedDate: snapshot.data()?['publishedDate'],
4042
publisher: snapshot.data()?['publisher'],
43+
userId: snapshot.data()?['userId'],
4144
);
4245

4346
Map<String, dynamic> toMap() {

lib/src/features/books/notifiers/favorite_books_notifier.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import '../../../repositories/favorite_books_repository.dart';
55
import '../models/favorite_book.dart';
66

77
class FavoriteBooksNotitier extends BaseChangeNotifier {
8-
FavoriteBooksNotitier(this._read);
8+
FavoriteBooksNotitier(this._read, {required this.bookId}) {
9+
checkIsFavorite(bookId);
10+
}
911

1012
final Reader _read;
1113

14+
final String bookId;
15+
1216
bool _isFavorite = false;
1317
bool get isFavorite => _isFavorite;
1418

@@ -38,6 +42,7 @@ class FavoriteBooksNotitier extends BaseChangeNotifier {
3842
}
3943
}
4044

41-
final favoriteBooksNotifierProvider = ChangeNotifierProvider(
42-
(ref) => FavoriteBooksNotitier(ref.read),
45+
final favoriteBooksNotifierProvider =
46+
ChangeNotifierProvider.family<FavoriteBooksNotitier, String>(
47+
(ref, bookId) => FavoriteBooksNotitier(ref.read, bookId: bookId),
4348
);

lib/src/features/books/providers/favorite_books_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
22

33
import '../../../repositories/favorite_books_repository.dart';
44

5-
final favoriteBooksProvider = StreamProvider((ref) {
5+
final favoriteBooksProvider = StreamProvider.autoDispose((ref) {
66
return ref.watch(favoriteBooksRepository).getFavoriteBooks();
77
});

lib/src/features/books/views/book_details_view.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ class BookDetailsView extends StatelessWidget {
3131
actions: [
3232
Consumer(
3333
builder: (context, watch, child) {
34-
final notifier = watch(favoriteBooksNotifierProvider)
35-
..checkIsFavorite(book.id);
34+
final notifier = watch(favoriteBooksNotifierProvider(book.id));
3635

3736
return IconButton(
3837
onPressed: () {
3938
final FavoriteBook fBook =
4039
ModelConverter.toFavoriteBook(book);
4140

4241
context
43-
.read(favoriteBooksNotifierProvider)
42+
.read(favoriteBooksNotifierProvider(book.id))
4443
.addOrRemoveFromFavorite(fBook);
4544
},
4645
icon: notifier.isFavorite

lib/src/features/books/views/favorite_books_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class BookListItem extends StatelessWidget {
193193
IconButton(
194194
onPressed: () {
195195
context
196-
.read(favoriteBooksNotifierProvider)
196+
.read(favoriteBooksNotifierProvider(book.id))
197197
.addOrRemoveFromFavorite(book);
198198
},
199199
icon: const Icon(Icons.delete),

lib/src/features/profile/notifiers/profile_notifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ class ProfileNotifier extends BaseChangeNotifier {
2323
}
2424
}
2525

26-
final profileNotifierProvider = ChangeNotifierProvider(
26+
final profileNotifierProvider = ChangeNotifierProvider.autoDispose(
2727
(ref) => ProfileNotifier(ref.read),
2828
);

lib/src/features/profile/notifiers/update_email_notifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ class UpdateEmailNotifier extends BaseChangeNotifier {
4848
}
4949
}
5050

51-
final updateEmailNotifierProvider = ChangeNotifierProvider(
51+
final updateEmailNotifierProvider = ChangeNotifierProvider.autoDispose(
5252
(ref) => UpdateEmailNotifier(ref.read),
5353
);

lib/src/features/profile/notifiers/update_password_notifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ class UpdatePasswordNotifier extends BaseChangeNotifier {
5151
}
5252
}
5353

54-
final updatePasswordNotifierProvider = ChangeNotifierProvider(
54+
final updatePasswordNotifierProvider = ChangeNotifierProvider.autoDispose(
5555
(ref) => UpdatePasswordNotifier(ref.read),
5656
);

lib/src/features/profile/notifiers/update_profile_notifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ class UpdateProfileNotifier extends BaseChangeNotifier {
3939
}
4040
}
4141

42-
final updateProfileNotifierProvider = ChangeNotifierProvider(
42+
final updateProfileNotifierProvider = ChangeNotifierProvider.autoDispose(
4343
(ref) => UpdateProfileNotifier(ref.read),
4444
);

0 commit comments

Comments
 (0)