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
ce45237a
Commit
ce45237a
authored
Jul 30, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: member loan selected book
parent
5d7d06d8
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
52 deletions
+94
-52
book.dart
lib/src/models/book.dart
+8
-1
auth_provider.dart
lib/src/providers/auth_provider.dart
+9
-5
detail_screen.dart
lib/src/screens/detail_screen.dart
+6
-3
book_detail.dart
lib/src/widgets/books/book_detail.dart
+1
-1
book_list.dart
lib/src/widgets/books/book_list.dart
+1
-0
book_loan_form.dart
lib/src/widgets/forms/book_loan_form.dart
+69
-42
No files found.
lib/src/models/book.dart
View file @
ce45237a
class
Book
{
int
id
;
String
title
;
String
author
;
String
description
;
String
?
coverUrl
;
String
?
category
;
Book
(
this
.
title
,
this
.
author
,
this
.
description
,
this
.
coverUrl
,
this
.
category
);
Book
(
this
.
id
,
this
.
title
,
this
.
author
,
this
.
description
,
this
.
coverUrl
,
this
.
category
);
factory
Book
.
fromJson
(
Map
<
String
,
dynamic
>
data
)
{
return
Book
(
data
[
'id'
]
as
int
,
data
[
'title'
]
as
String
,
data
[
'author'
]
as
String
,
data
[
'description'
]
as
String
,
...
...
@@ -20,6 +23,7 @@ class Book {
final
initialBooks
=
[
Book
(
1
,
'The Doe in the Forest'
,
'Laurel Toven'
,
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris ligula. Mauris nec elit ultrices, gravida tortor ac, faucibus velit.'
,
...
...
@@ -27,6 +31,7 @@ final initialBooks = [
'Children'
,
),
Book
(
1
,
'Norse Mythology'
,
'Neil Gaiman'
,
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris ligula. Mauris nec elit ultrices, gravida tortor ac, faucibus velit.'
,
...
...
@@ -34,6 +39,7 @@ final initialBooks = [
'Religion'
,
),
Book
(
1
,
'The Sun, the Moon, the Stars'
,
'Junot Diaz'
,
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris ligula. Mauris nec elit ultrices, gravida tortor ac, faucibus velit.'
,
...
...
@@ -41,6 +47,7 @@ final initialBooks = [
'Drama'
,
),
Book
(
1
,
'Harry Potter'
,
'JK Rowling'
,
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed id mauris ligula. Mauris nec elit ultrices, gravida tortor ac, faucibus velit.'
,
...
...
lib/src/providers/auth_provider.dart
View file @
ce45237a
...
...
@@ -188,14 +188,18 @@ class AuthProvider with ChangeNotifier {
final
body
=
{
"book"
:
bookId
,
"member"
:
memberId
,
"loan_date"
:
loanDate
,
"due_date"
:
dueDate
,
"loan_date"
:
loanDate
.
toString
()
,
"due_date"
:
dueDate
.
toString
()
,
};
try
{
final
response
=
await
http
.
post
(
Uri
.
parse
(
'
$baseUrl
/members/
$memberId
/loans/'
),
body:
jsonEncode
(
body
),
headers:
{
'Content-Type'
:
'application/json'
},
headers:
{
'Content-Type'
:
'application/json'
,
'Authorization'
:
'Bearer
${token?.key}
'
},
);
if
(
response
.
statusCode
==
200
)
{
...
...
@@ -203,12 +207,12 @@ class AuthProvider with ChangeNotifier {
memberLoans
=
data
[
"results"
];
}
else
{
debugPrint
(
"Failed to
get
member loan.
${response.statusCode}
:
${response.body}
"
);
"Failed to
create
member loan.
${response.statusCode}
:
${response.body}
"
);
}
notifyListeners
();
}
catch
(
error
)
{
debugPrint
(
"Failed to
get
member loan.
$error
"
);
debugPrint
(
"Failed to
create
member loan.
$error
"
);
}
}
}
lib/src/screens/detail_screen.dart
View file @
ce45237a
...
...
@@ -4,14 +4,14 @@ import 'package:library_app/src/widgets/forms/book_loan_form.dart';
class
DetailScreen
extends
StatefulWidget
{
final
String
?
textSubmitButton
;
final
String
title
;
final
String
confirmMessage
;
final
int
bookId
;
final
Widget
body
;
const
DetailScreen
({
super
.
key
,
required
this
.
title
,
required
this
.
body
,
required
this
.
confirmMessage
,
required
this
.
bookId
,
this
.
textSubmitButton
,
});
...
...
@@ -24,6 +24,7 @@ class _DetailScreen extends State<DetailScreen> {
Widget
build
(
BuildContext
context
)
{
final
String
title
=
widget
.
title
;
final
Widget
body
=
widget
.
body
;
final
int
bookId
=
widget
.
bookId
;
return
Scaffold
(
appBar:
AppBar
(
...
...
@@ -42,7 +43,9 @@ class _DetailScreen extends State<DetailScreen> {
)
],
),
bottomNavigationBar:
const
LoanBookForm
(),
bottomNavigationBar:
LoanBookForm
(
bookId:
bookId
,
),
);
}
}
lib/src/widgets/books/book_detail.dart
View file @
ce45237a
...
...
@@ -19,8 +19,8 @@ class _BookDetail extends State<BookDetail> {
final
screenSize
=
MediaQuery
.
of
(
context
).
size
;
return
DetailScreen
(
bookId:
book
.
id
,
title:
book
.
title
,
confirmMessage:
"Loans for how many days?"
,
textSubmitButton:
"Borrow"
,
body:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
center
,
...
...
lib/src/widgets/books/book_list.dart
View file @
ce45237a
...
...
@@ -27,6 +27,7 @@ class _BookList extends State<BookList> {
if
(
bookProvider
.
books
!=
null
)
{
final
Iterable
<
Book
>
books
=
bookProvider
.
books
!.
map
(
(
book
)
=>
Book
(
book
[
"id"
],
book
[
"title"
],
book
[
"author"
],
book
[
"description"
],
...
...
lib/src/widgets/forms/book_loan_form.dart
View file @
ce45237a
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:provider/provider.dart'
;
class
LoanBookForm
extends
StatelessWidget
{
const
LoanBookForm
({
super
.
key
});
class
LoanBookForm
extends
StatefulWidget
{
final
int
bookId
;
const
LoanBookForm
({
super
.
key
,
required
this
.
bookId
});
@override
State
<
LoanBookForm
>
createState
()
=>
_LoanBookForm
();
}
class
_LoanBookForm
extends
State
<
LoanBookForm
>
{
final
GlobalKey
<
FormState
>
_formKey
=
GlobalKey
<
FormState
>();
final
loanDayController
=
TextEditingController
();
@override
void
dispose
()
{
loanDayController
.
dispose
();
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Container
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20.0
,
vertical:
10.0
),
child:
FilledButton
(
onPressed:
()
{
showDialog
(
context:
context
,
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
title:
const
Text
(
'Loans for how many days?'
),
content:
Form
(
child:
TextFormField
(
decoration:
const
InputDecoration
(
hintText:
"Input number"
,
labelText:
"Days"
,
suffixIcon:
Icon
(
Icons
.
date_range
),
),
keyboardType:
TextInputType
.
number
,
inputFormatters:
[
FilteringTextInputFormatter
.
digitsOnly
],
),
),
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
},
child:
const
Text
(
'Cancel'
),
return
Consumer
<
AuthProvider
>(
builder:
(
context
,
authProvider
,
child
)
{
return
Container
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
20.0
,
vertical:
10.0
),
child:
FilledButton
(
onPressed:
()
{
showDialog
(
context:
context
,
builder:
(
BuildContext
context
)
{
return
AlertDialog
(
title:
const
Text
(
'Borrow for how many days?'
,
style:
TextStyle
(
fontSize:
20.0
),
),
ElevatedButton
(
onPressed:
()
{
// Submit form data
Navigator
.
of
(
context
).
pop
();
},
child:
const
Text
(
'Submit'
),
content:
Form
(
key:
_formKey
,
child:
TextFormField
(
controller:
loanDayController
,
decoration:
const
InputDecoration
(
hintText:
"Input day in number"
,
labelText:
"Days"
,
suffixIcon:
Icon
(
Icons
.
date_range
),
),
keyboardType:
TextInputType
.
number
,
inputFormatters:
[
FilteringTextInputFormatter
.
digitsOnly
],
),
),
],
);
},
);
},
child:
const
Text
(
'borrow'
),
),
);
actions:
[
TextButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
pop
();
},
child:
const
Text
(
'Cancel'
),
),
FilledButton
(
onPressed:
()
{
authProvider
.
createMemberLoan
(
authProvider
.
user
!.
accountId
,
widget
.
bookId
,
int
.
parse
(
loanDayController
.
text
),
);
},
child:
const
Text
(
'Submit'
),
),
],
);
},
);
},
child:
const
Text
(
'borrow'
),
),
);
});
}
}
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