Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-flutter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ilham Maulana
library-app-flutter
Commits
eac237ca
Commit
eac237ca
authored
Aug 02, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: book list loading
parent
057213c1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
book_provider.dart
lib/src/providers/book_provider.dart
+8
-0
book_list.dart
lib/src/widgets/books/book_list.dart
+1
-1
search_form.dart
lib/src/widgets/forms/search_form.dart
+8
-3
No files found.
lib/src/providers/book_provider.dart
View file @
eac237ca
...
...
@@ -12,8 +12,15 @@ class BookProvider with ChangeNotifier {
String
?
searchKeyword
;
String
?
filterByCategory
;
bool
isLoading
=
false
;
void
setLoading
(
bool
value
)
{
isLoading
=
value
;
}
Future
<
void
>
getBooks
()
async
{
try
{
setLoading
(
true
);
String
url
=
'
$baseUrl
/books'
;
if
(
filterByCategory
!=
null
)
{
url
+=
'?category__name=
$filterByCategory
'
;
...
...
@@ -34,6 +41,7 @@ class BookProvider with ChangeNotifier {
debugPrint
(
"Error: Fetch books failed,
$code
"
);
}
setLoading
(
false
);
notifyListeners
();
}
catch
(
error
)
{
debugPrint
(
"Error: Fetch books failed,
$error
"
);
...
...
lib/src/widgets/books/book_list.dart
View file @
eac237ca
...
...
@@ -25,7 +25,7 @@ class _BookList extends State<BookList> {
Widget
build
(
BuildContext
context
)
{
return
Consumer
<
BookProvider
>(
builder:
(
context
,
bookProvider
,
child
)
{
if
(
bookProvider
.
books
!=
null
)
{
if
(
!
bookProvider
.
isLoading
)
{
final
Iterable
<
Book
>
books
=
bookProvider
.
books
!.
map
((
book
)
{
if
(
book
[
"category_detail"
]
!=
null
)
{
final
Category
category
=
Category
.
fromJson
(
...
...
lib/src/widgets/forms/search_form.dart
View file @
eac237ca
...
...
@@ -27,9 +27,14 @@ class _SearchForm extends State<SearchForm> {
hintText:
"Enter keywords..."
,
elevation:
WidgetStateProperty
.
all
(
0
),
onChanged:
(
value
)
{
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
)
.
setSearchKeyword
(
value
);
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
).
getBooks
();
Future
.
delayed
(
Duration
.
zero
,
()
{
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
)
.
setSearchKeyword
(
value
);
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
).
getBooks
();
},
);
},
leading:
const
Icon
(
Icons
.
search
),
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment