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
d5a3c225
Commit
d5a3c225
authored
Aug 09, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: refactoring custom button with loading
parent
36d06822
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
43 deletions
+67
-43
auth_provider.dart
lib/src/providers/auth_provider.dart
+1
-1
book_loan_form.dart
lib/src/widgets/forms/book_loan_form.dart
+8
-8
change_password_form.dart
lib/src/widgets/forms/change_password_form.dart
+6
-6
login_form.dart
lib/src/widgets/forms/login_form.dart
+5
-6
profile_edit_form.dart
lib/src/widgets/forms/profile_edit_form.dart
+5
-3
reset_password_form.dart
lib/src/widgets/forms/reset_password_form.dart
+7
-9
search_form.dart
lib/src/widgets/forms/search_form.dart
+3
-8
sign_up_form.dart
lib/src/widgets/forms/sign_up_form.dart
+5
-2
button_custom.dart
lib/src/widgets/ui/button_custom.dart
+27
-0
No files found.
lib/src/providers/auth_provider.dart
View file @
d5a3c225
...
@@ -226,11 +226,11 @@ class AuthProvider with ChangeNotifier {
...
@@ -226,11 +226,11 @@ class AuthProvider with ChangeNotifier {
String
?
lastName
,
String
?
lastName
,
bool
isStaff
,
bool
isStaff
,
)
async
{
)
async
{
setLoading
(
true
);
final
token
=
await
getAccessToken
();
final
token
=
await
getAccessToken
();
if
(
token
!=
null
)
{
if
(
token
!=
null
)
{
try
{
try
{
setLoading
(
true
);
final
data
=
{
final
data
=
{
"username"
:
username
,
"username"
:
username
,
"email"
:
email
,
"email"
:
email
,
...
...
lib/src/widgets/forms/book_loan_form.dart
View file @
d5a3c225
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/ui/button_custom.dart'
;
import
'package:provider/provider.dart'
;
import
'package:provider/provider.dart'
;
class
LoanBookForm
extends
StatefulWidget
{
class
LoanBookForm
extends
StatefulWidget
{
...
@@ -86,17 +87,16 @@ class _LoanBookForm extends State<LoanBookForm> {
...
@@ -86,17 +87,16 @@ class _LoanBookForm extends State<LoanBookForm> {
},
},
child:
const
Text
(
'Cancel'
),
child:
const
Text
(
'Cancel'
),
),
),
FilledButton
(
ButtonCustom
(
onPressed:
()
{
onPressed:
()
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
authProvider
.
createMemberLoan
(
.
createMemberLoan
(
authProvider
.
user
!.
id
,
authProvider
.
user
!.
id
,
widget
.
bookId
,
widget
.
bookId
,
int
.
parse
(
loanDayController
.
text
),
int
.
parse
(
loanDayController
.
text
),
)
);
.
then
((
_
)
=>
Navigator
.
of
(
context
).
pop
());
},
},
isLoading:
authProvider
.
isLoading
,
child:
const
Text
(
'Submit'
),
child:
const
Text
(
'Submit'
),
),
),
],
],
...
...
lib/src/widgets/forms/change_password_form.dart
View file @
d5a3c225
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_svg/svg.dart'
;
import
'package:flutter_svg/svg.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/loading.dart'
;
import
'package:provider/provider.dart'
;
import
'package:provider/provider.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/ui/button_custom.dart'
;
class
ChangePasswordForm
extends
StatefulWidget
{
class
ChangePasswordForm
extends
StatefulWidget
{
const
ChangePasswordForm
({
super
.
key
});
const
ChangePasswordForm
({
super
.
key
});
...
@@ -140,7 +141,7 @@ class _ChangePasswordForm extends State<ChangePasswordForm> {
...
@@ -140,7 +141,7 @@ class _ChangePasswordForm extends State<ChangePasswordForm> {
),
),
SizedBox
(
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
ButtonCustom
(
onPressed:
()
async
{
onPressed:
()
async
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
changePassword
(
authProvider
.
changePassword
(
...
@@ -150,9 +151,8 @@ class _ChangePasswordForm extends State<ChangePasswordForm> {
...
@@ -150,9 +151,8 @@ class _ChangePasswordForm extends State<ChangePasswordForm> {
newPasswordController2
.
text
,
newPasswordController2
.
text
,
);
);
},
},
child:
authProvider
.
isLoading
isLoading:
authProvider
.
isLoading
,
?
const
Loading
()
child:
const
Text
(
"Submit"
),
:
const
Text
(
"Submit"
),
),
),
),
),
],
],
...
...
lib/src/widgets/forms/login_form.dart
View file @
d5a3c225
import
'package:provider/provider.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_svg/flutter_svg.dart'
;
import
'package:flutter_svg/flutter_svg.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/loading.dart'
;
import
'package:library_app/src/widgets/ui/button_custom.dart'
;
import
'package:provider/provider.dart'
;
class
LoginForm
extends
StatefulWidget
{
class
LoginForm
extends
StatefulWidget
{
const
LoginForm
({
super
.
key
});
const
LoginForm
({
super
.
key
});
...
@@ -120,7 +120,7 @@ class _LoginForm extends State<LoginForm> {
...
@@ -120,7 +120,7 @@ class _LoginForm extends State<LoginForm> {
children:
[
children:
[
SizedBox
(
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
ButtonCustom
(
onPressed:
()
async
{
onPressed:
()
async
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
signIn
(
authProvider
.
signIn
(
...
@@ -129,9 +129,8 @@ class _LoginForm extends State<LoginForm> {
...
@@ -129,9 +129,8 @@ class _LoginForm extends State<LoginForm> {
passwordController
.
text
,
passwordController
.
text
,
);
);
},
},
child:
authProvider
.
isLoading
isLoading:
authProvider
.
isLoading
,
?
const
Loading
()
child:
const
Text
(
"Submit"
),
:
const
Text
(
"Submit"
),
),
),
),
),
SizedBox
(
SizedBox
(
...
...
lib/src/widgets/forms/profile_edit_form.dart
View file @
d5a3c225
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/ui/button_custom.dart'
;
import
'package:provider/provider.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/models/user.dart'
;
import
'package:library_app/src/models/user.dart'
;
import
'package:provider/provider.dart'
;
class
ProfileEditForm
extends
StatefulWidget
{
class
ProfileEditForm
extends
StatefulWidget
{
final
User
?
user
;
final
User
?
user
;
...
@@ -102,7 +103,7 @@ class _ProfileEditForm extends State<ProfileEditForm> {
...
@@ -102,7 +103,7 @@ class _ProfileEditForm extends State<ProfileEditForm> {
padding:
const
EdgeInsets
.
only
(
top:
40.0
),
padding:
const
EdgeInsets
.
only
(
top:
40.0
),
child:
SizedBox
(
child:
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
ButtonCustom
(
onPressed:
()
{
onPressed:
()
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
updateUserDetail
(
authProvider
.
updateUserDetail
(
...
@@ -115,6 +116,7 @@ class _ProfileEditForm extends State<ProfileEditForm> {
...
@@ -115,6 +116,7 @@ class _ProfileEditForm extends State<ProfileEditForm> {
authProvider
.
user
!.
isStaff
,
authProvider
.
user
!.
isStaff
,
);
);
},
},
isLoading:
authProvider
.
isLoading
,
child:
const
Text
(
"Submit"
),
child:
const
Text
(
"Submit"
),
),
),
),
),
...
...
lib/src/widgets/forms/reset_password_form.dart
View file @
d5a3c225
...
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
...
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import
'package:flutter/services.dart'
;
import
'package:flutter/services.dart'
;
import
'package:flutter_svg/flutter_svg.dart'
;
import
'package:flutter_svg/flutter_svg.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
import
'package:library_app/src/widgets/
loading
.dart'
;
import
'package:library_app/src/widgets/
ui/button_custom
.dart'
;
import
'package:provider/provider.dart'
;
import
'package:provider/provider.dart'
;
class
ResetPasswordForm
extends
StatefulWidget
{
class
ResetPasswordForm
extends
StatefulWidget
{
...
@@ -85,15 +85,14 @@ class _ResetPasswordForm extends State<ResetPasswordForm> {
...
@@ -85,15 +85,14 @@ class _ResetPasswordForm extends State<ResetPasswordForm> {
children:
[
children:
[
SizedBox
(
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
ButtonCustom
(
onPressed:
()
{
onPressed:
()
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
resetPassword
(
authProvider
.
resetPassword
(
context
,
emailController
.
text
);
context
,
emailController
.
text
);
},
},
child:
authProvider
.
isLoading
isLoading:
authProvider
.
isLoading
,
?
const
Loading
()
child:
const
Text
(
"Submit"
),
:
const
Text
(
"Submit"
),
),
),
),
),
],
],
...
@@ -254,7 +253,7 @@ class _ConfirmResetPasswordForm extends State<ConfirmResetPasswordForm> {
...
@@ -254,7 +253,7 @@ class _ConfirmResetPasswordForm extends State<ConfirmResetPasswordForm> {
children:
[
children:
[
SizedBox
(
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
ButtonCustom
(
onPressed:
()
{
onPressed:
()
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
confirmResetPassword
(
authProvider
.
confirmResetPassword
(
...
@@ -264,9 +263,8 @@ class _ConfirmResetPasswordForm extends State<ConfirmResetPasswordForm> {
...
@@ -264,9 +263,8 @@ class _ConfirmResetPasswordForm extends State<ConfirmResetPasswordForm> {
password2Controller
.
text
,
password2Controller
.
text
,
);
);
},
},
child:
authProvider
.
isLoading
isLoading:
authProvider
.
isLoading
,
?
const
Loading
()
child:
const
Text
(
"Submit"
),
:
const
Text
(
"Submit"
),
),
),
),
),
],
],
...
...
lib/src/widgets/forms/search_form.dart
View file @
d5a3c225
...
@@ -28,14 +28,9 @@ class _SearchForm extends State<SearchForm> {
...
@@ -28,14 +28,9 @@ class _SearchForm extends State<SearchForm> {
elevation:
WidgetStateProperty
.
all
(
0
),
elevation:
WidgetStateProperty
.
all
(
0
),
onChanged:
(
value
)
{
onChanged:
(
value
)
{
if
(
value
.
length
>=
3
)
{
if
(
value
.
length
>=
3
)
{
Future
.
delayed
(
Duration
.
zero
,
()
{
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
)
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
)
.
setSearchKeyword
(
value
);
.
setSearchKeyword
(
value
);
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
).
getBooks
();
Provider
.
of
<
BookProvider
>(
context
,
listen:
false
).
getBooks
();
},
);
}
}
},
},
leading:
const
Icon
(
Icons
.
search
),
leading:
const
Icon
(
Icons
.
search
),
...
...
lib/src/widgets/forms/sign_up_form.dart
View file @
d5a3c225
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_svg/flutter_svg.dart'
;
import
'package:flutter_svg/flutter_svg.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:go_router/go_router.dart'
;
import
'package:library_app/src/
providers/auth_provider
.dart'
;
import
'package:library_app/src/
widgets/ui/button_custom
.dart'
;
import
'package:provider/provider.dart'
;
import
'package:provider/provider.dart'
;
import
'package:library_app/src/providers/auth_provider.dart'
;
class
SignUpForm
extends
StatefulWidget
{
class
SignUpForm
extends
StatefulWidget
{
const
SignUpForm
({
super
.
key
});
const
SignUpForm
({
super
.
key
});
...
@@ -131,7 +133,7 @@ class _SignUpForm extends State<SignUpForm> {
...
@@ -131,7 +133,7 @@ class _SignUpForm extends State<SignUpForm> {
children:
[
children:
[
SizedBox
(
SizedBox
(
width:
double
.
infinity
,
width:
double
.
infinity
,
child:
FilledButton
(
child:
ButtonCustom
(
onPressed:
()
{
onPressed:
()
{
if
(
_formKey
.
currentState
!.
validate
())
{}
if
(
_formKey
.
currentState
!.
validate
())
{}
authProvider
.
signUp
(
authProvider
.
signUp
(
...
@@ -141,6 +143,7 @@ class _SignUpForm extends State<SignUpForm> {
...
@@ -141,6 +143,7 @@ class _SignUpForm extends State<SignUpForm> {
passwordController
.
text
,
passwordController
.
text
,
);
);
},
},
isLoading:
authProvider
.
isLoading
,
child:
const
Text
(
"Submit"
),
child:
const
Text
(
"Submit"
),
),
),
),
),
...
...
lib/src/widgets/ui/button_custom.dart
0 → 100644
View file @
d5a3c225
import
'package:flutter/material.dart'
;
import
'package:library_app/src/widgets/loading.dart'
;
class
ButtonCustom
extends
StatefulWidget
{
final
Widget
?
child
;
final
bool
?
isLoading
;
final
void
Function
()?
onPressed
;
const
ButtonCustom
({
super
.
key
,
this
.
onPressed
,
this
.
child
,
this
.
isLoading
});
@override
State
<
StatefulWidget
>
createState
()
=>
_ButtonCustom
();
}
class
_ButtonCustom
extends
State
<
ButtonCustom
>
{
get
onPressed
=>
widget
.
onPressed
;
get
child
=>
widget
.
child
;
get
isLoading
=>
widget
.
isLoading
;
@override
Widget
build
(
BuildContext
context
)
{
return
FilledButton
(
onPressed:
onPressed
,
child:
isLoading
?
const
Loading
()
:
child
,
);
}
}
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