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
33e07cfe
Commit
33e07cfe
authored
Aug 07, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: member loan paging
parent
88a96c25
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
7 deletions
+85
-7
auth_provider.dart
lib/src/providers/auth_provider.dart
+20
-3
book_list.dart
lib/src/widgets/books/book_list.dart
+5
-0
loan_list.dart
lib/src/widgets/loans/loan_list.dart
+60
-4
No files found.
lib/src/providers/auth_provider.dart
View file @
33e07cfe
...
@@ -28,6 +28,11 @@ class AuthProvider with ChangeNotifier {
...
@@ -28,6 +28,11 @@ class AuthProvider with ChangeNotifier {
bool
changePasswordSucced
=
false
;
bool
changePasswordSucced
=
false
;
bool
loanBookSuccess
=
false
;
bool
loanBookSuccess
=
false
;
bool
hasNextPage
=
false
;
bool
hasPrevPage
=
false
;
int
pageNumber
=
1
;
int
?
totalPages
;
List
<
dynamic
>?
loans
;
List
<
dynamic
>?
loans
;
List
<
dynamic
>?
nearOutstandingLoans
;
List
<
dynamic
>?
nearOutstandingLoans
;
List
<
dynamic
>?
overduedLoans
;
List
<
dynamic
>?
overduedLoans
;
...
@@ -60,6 +65,7 @@ class AuthProvider with ChangeNotifier {
...
@@ -60,6 +65,7 @@ class AuthProvider with ChangeNotifier {
loans
=
null
;
loans
=
null
;
nearOutstandingLoans
=
null
;
nearOutstandingLoans
=
null
;
overduedLoans
=
null
;
overduedLoans
=
null
;
totalPages
=
null
;
isAuthenticated
=
false
;
isAuthenticated
=
false
;
invalidUsernameOrPassword
=
false
;
invalidUsernameOrPassword
=
false
;
...
@@ -70,6 +76,13 @@ class AuthProvider with ChangeNotifier {
...
@@ -70,6 +76,13 @@ class AuthProvider with ChangeNotifier {
resetPasswordSucced
=
false
;
resetPasswordSucced
=
false
;
changePasswordSucced
=
false
;
changePasswordSucced
=
false
;
loanBookSuccess
=
false
;
loanBookSuccess
=
false
;
hasNextPage
=
false
;
hasPrevPage
=
false
;
}
void
setPage
(
int
value
)
{
pageNumber
=
value
;
notifyListeners
();
}
}
Future
<
void
>
signIn
(
Future
<
void
>
signIn
(
...
@@ -376,8 +389,8 @@ class AuthProvider with ChangeNotifier {
...
@@ -376,8 +389,8 @@ class AuthProvider with ChangeNotifier {
url
+=
'?near_outstanding=True'
;
url
+=
'?near_outstanding=True'
;
}
else
if
(
filterByOverdued
)
{
}
else
if
(
filterByOverdued
)
{
url
+=
'?overdue=True'
;
url
+=
'?overdue=True'
;
}
else
{
}
else
if
(
pageNumber
>
1
)
{
null
;
url
+=
"?page=
$pageNumber
"
;
}
}
try
{
try
{
...
@@ -392,7 +405,11 @@ class AuthProvider with ChangeNotifier {
...
@@ -392,7 +405,11 @@ class AuthProvider with ChangeNotifier {
if
(
response
.
statusCode
==
200
)
{
if
(
response
.
statusCode
==
200
)
{
message
=
null
;
message
=
null
;
final
data
=
jsonDecode
(
response
.
body
);
final
data
=
jsonDecode
(
response
.
body
);
memberLoans
=
data
;
memberLoans
=
data
[
"data"
];
hasNextPage
=
data
[
"has_next"
];
hasPrevPage
=
data
[
"has_prev"
];
pageNumber
=
data
[
"page_number"
];
totalPages
=
data
[
"total_pages"
];
}
else
{
}
else
{
final
data
=
jsonDecode
(
response
.
body
);
final
data
=
jsonDecode
(
response
.
body
);
message
=
data
[
"message"
];
message
=
data
[
"message"
];
...
...
lib/src/widgets/books/book_list.dart
View file @
33e07cfe
...
@@ -64,6 +64,11 @@ class _BookList extends State<BookList> {
...
@@ -64,6 +64,11 @@ class _BookList extends State<BookList> {
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Consumer
<
BookProvider
>(
return
Consumer
<
BookProvider
>(
builder:
(
context
,
bookProvider
,
child
)
{
builder:
(
context
,
bookProvider
,
child
)
{
if
(
bookProvider
.
books
==
null
)
{
return
const
Center
(
child:
CircularProgressIndicator
(),
);
}
final
Iterable
<
Book
>
books
=
bookProvider
.
books
!.
map
((
book
)
{
final
Iterable
<
Book
>
books
=
bookProvider
.
books
!.
map
((
book
)
{
if
(
book
[
"category"
]
!=
null
)
{
if
(
book
[
"category"
]
!=
null
)
{
final
Category
category
=
Category
.
fromJson
(
final
Category
category
=
Category
.
fromJson
(
...
...
lib/src/widgets/loans/loan_list.dart
View file @
33e07cfe
...
@@ -26,6 +26,40 @@ class _LoanList extends State<LoanList> {
...
@@ -26,6 +26,40 @@ class _LoanList extends State<LoanList> {
super
.
initState
();
super
.
initState
();
}
}
ScrollController
listScrollController
=
ScrollController
();
void
scrollToTop
()
{
if
(
listScrollController
.
hasClients
)
{
final
position
=
listScrollController
.
position
.
minScrollExtent
;
listScrollController
.
jumpTo
(
position
);
}
}
Future
<
void
>
nextPage
()
async
{
if
(
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
hasNextPage
)
{
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
setPage
(
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
pageNumber
+
1
,
);
}
else
{
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
setPage
(
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
totalPages
!);
}
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
getMemberLoan
();
scrollToTop
();
}
Future
<
void
>
prevPage
()
async
{
if
(
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
hasPrevPage
)
{
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
setPage
(
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
pageNumber
-
1
,
);
}
else
{
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
setPage
(
1
);
}
Provider
.
of
<
AuthProvider
>(
context
,
listen:
false
).
getMemberLoan
();
scrollToTop
();
}
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
return
Consumer
<
AuthProvider
>(
builder:
(
context
,
authProvider
,
child
)
{
return
Consumer
<
AuthProvider
>(
builder:
(
context
,
authProvider
,
child
)
{
...
@@ -48,10 +82,32 @@ class _LoanList extends State<LoanList> {
...
@@ -48,10 +82,32 @@ class _LoanList extends State<LoanList> {
headerSliverBuilder:
(
BuildContext
context
,
bool
innerBoxIsScrolled
)
{
headerSliverBuilder:
(
BuildContext
context
,
bool
innerBoxIsScrolled
)
{
return
[
const
TopAppBar
(
title:
"Book Loans"
)];
return
[
const
TopAppBar
(
title:
"Book Loans"
)];
},
},
body:
ListView
(
body:
ListView
.
builder
(
children:
List
.
generate
(
loans
.
length
,
(
index
)
{
controller:
listScrollController
,
return
LoanItem
(
loans
.
elementAt
(
index
));
itemCount:
loans
.
length
+
1
,
}),
itemBuilder:
(
context
,
index
)
{
if
(
index
<
loans
.
length
)
{
return
LoanItem
(
loans
.
elementAt
(
index
));
}
else
{
return
Container
(
padding:
const
EdgeInsets
.
all
(
10
),
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceBetween
,
children:
[
ElevatedButton
(
onPressed:
prevPage
,
child:
const
Text
(
'Prev'
),
),
Text
(
authProvider
.
pageNumber
.
toString
()),
ElevatedButton
(
onPressed:
nextPage
,
child:
const
Text
(
'Next'
),
),
],
),
);
}
},
),
),
);
);
}
else
{
}
else
{
...
...
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