Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hoàng Văn Đạt
mypoint_flutter_app
Commits
8ec716d3
Commit
8ec716d3
authored
Mar 05, 2025
by
DatHV
Browse files
update logic
parent
7d37c9c6
Changes
26
Show whitespace changes
Inline
Side-by-side
lib/screen/otp/otp_view
_
model.dart
→
lib/screen/otp/otp_viewmodel.dart
View file @
8ec716d3
import
'dart:async'
;
import
'package:get/get.dart'
;
import
'package:mypoint_flutter_app/base/base_response_model.dart'
;
import
'otp_verify_response_model.dart'
;
import
'package:mypoint_flutter_app/configs/constants.dart'
;
import
'package:mypoint_flutter_app/screen/create_pass/create_pass_screen.dart'
;
import
'package:mypoint_flutter_app/screen/login/login_screen.dart'
;
import
'../create_pass/signup_create_password_repository.dart'
;
import
'model/otp_verify_response_model.dart'
;
// i_otp_repository.dart
abstract
class
IOtpRepository
{
Future
<
void
>
sendOtp
();
Future
<
BaseResponseModel
<
OTPVerifyResponseModel
>>
verifyOtp
(
String
otpCode
);
Future
<
void
>
resendOtp
();
Future
<
int
?
>
resendOtp
();
late
String
phoneNumber
;
late
int
otpTtl
;
}
class
OtpViewModel
extends
GetxController
{
...
...
@@ -16,7 +21,7 @@ class OtpViewModel extends GetxController {
var
otpCode
=
""
.
obs
;
var
errorMessage
=
""
.
obs
;
var
currentCountdown
=
0
.
obs
;
final
int
_maxCountdown
=
150
;
// 2 phút 30 giây
int
_maxCountdown
=
Constants
.
otpTtl
;
Timer
?
_timer
;
OtpViewModel
(
this
.
repository
);
...
...
@@ -24,6 +29,7 @@ class OtpViewModel extends GetxController {
@override
void
onInit
()
{
super
.
onInit
();
_maxCountdown
=
repository
.
otpTtl
;
sendOtp
();
startCountdown
();
}
...
...
@@ -75,7 +81,15 @@ class OtpViewModel extends GetxController {
try
{
final
response
=
await
repository
.
verifyOtp
(
otpCode
.
value
);
if
(
response
.
isSuccess
)
{
errorMessage
.
value
=
"response.isSuccess"
;
errorMessage
.
value
=
""
;
if
(
response
.
data
?.
claim
?.
action
==
"signup"
)
{
Get
.
off
(()
=>
CreatePasswordScreen
(
repository:
SignUpCreatePasswordRepository
(
repository
.
phoneNumber
)));
return
;
}
if
(
response
.
data
?.
claim
?.
action
==
"login"
)
{
Get
.
off
(()
=>
LoginScreen
(
phoneNumber:
repository
.
phoneNumber
));
return
;
}
}
else
{
errorMessage
.
value
=
response
.
errorMessage
??
""
;
}
...
...
@@ -85,10 +99,11 @@ class OtpViewModel extends GetxController {
}
}
Future
<
void
>
onResendOtp
()
async
{
if
(
currentCountdown
.
value
>
0
)
return
;
Future
<
int
?
>
onResendOtp
()
async
{
if
(
currentCountdown
.
value
>
0
)
return
null
;
try
{
await
repository
.
resendOtp
();
final
response
=
await
repository
.
resendOtp
();
_maxCountdown
=
response
??
Constants
.
otpTtl
;
startCountdown
();
}
catch
(
e
)
{
errorMessage
.
value
=
"Gửi lại OTP thất bại. Thử lại."
;
...
...
lib/screen/otp/verify_otp_repository.dart
View file @
8ec716d3
...
...
@@ -4,15 +4,15 @@ import 'package:get/get.dart';
import
'package:mypoint_flutter_app/networking/restful_api_request.dart'
;
import
'../../base/base_response_model.dart'
;
import
'../../base/restful_api_viewmodel.dart'
;
import
'otp_verify_response_model.dart'
;
import
'otp_view
_
model.dart'
;
import
'
model/
otp_verify_response_model.dart'
;
import
'otp_viewmodel.dart'
;
class
VerifyOtpRepository
extends
RestfulApiViewModel
implements
IOtpRepository
{
int
otpTtl
;
final
String
mfaToken
;
var
otpVerifyResponse
=
BaseResponseModel
<
OTPVerifyResponseModel
>().
obs
;
VerifyOtpRepository
(
this
.
phoneNumber
,
this
.
otpTtl
,
this
.
mfaToken
);
@override
int
otpTtl
;
@override
String
phoneNumber
;
...
...
@@ -29,11 +29,11 @@ class VerifyOtpRepository extends RestfulApiViewModel implements IOtpRepository
}
@override
Future
<
void
>
resendOtp
()
async
{
Future
<
int
?
>
resendOtp
()
async
{
showLoading
();
return
client
.
resendOTP
(
mfaToken
).
then
((
value
)
{
otpTtl
=
value
.
data
?.
otpTtl
??
0
;
hideLoading
();
return
value
.
data
?.
otpTtl
;
});
}
}
lib/screen/splash/splash_screen.dart
View file @
8ec716d3
...
...
@@ -6,7 +6,7 @@ import 'package:get/get_core/src/get_main.dart';
import
'package:mypoint_flutter_app/configs/api_paths.dart'
;
import
'package:mypoint_flutter_app/dio_http_service/api_helper.dart'
;
import
'package:mypoint_flutter_app/networking/api_service.dart'
;
import
'package:mypoint_flutter_app/screen/splash/splash_screen_view
_
model.dart'
;
import
'package:mypoint_flutter_app/screen/splash/splash_screen_viewmodel.dart'
;
import
'../../model/check_update_response_model.dart'
;
import
'../onboarding/onboarding_screen.dart'
;
...
...
lib/screen/splash/splash_screen_view
_
model.dart
→
lib/screen/splash/splash_screen_viewmodel.dart
View file @
8ec716d3
File moved
lib/widgets/back_button.dart
0 → 100644
View file @
8ec716d3
import
'package:flutter/material.dart'
;
import
'package:mypoint_flutter_app/resouce/base_color.dart'
;
class
CustomBackButton
extends
StatelessWidget
{
final
VoidCallback
?
onPressed
;
final
Color
?
iconColor
;
final
double
?
iconSize
;
final
EdgeInsets
?
margin
;
const
CustomBackButton
({
super
.
key
,
this
.
onPressed
,
this
.
iconColor
,
this
.
iconSize
,
this
.
margin
});
@override
Widget
build
(
BuildContext
context
)
{
return
SizedBox
(
height:
48
,
width:
48
,
child:
Stack
(
children:
[
Center
(
child:
Container
(
height:
36
,
width:
36
,
decoration:
BoxDecoration
(
border:
Border
.
all
(
color:
BaseColor
.
second400
,
width:
1
),
borderRadius:
BorderRadius
.
circular
(
6
),
color:
Colors
.
white
,
),
),
),
Center
(
child:
IconButton
(
icon:
Icon
(
Icons
.
arrow_back_ios_rounded
,
color:
iconColor
??
BaseColor
.
second600
,
size:
iconSize
??
24
),
onPressed:
onPressed
??
()
{
Navigator
.
pop
(
context
);
},
),
),
],
),
);
}
}
lib/widgets/support_button.dart
0 → 100644
View file @
8ec716d3
import
'package:flutter/material.dart'
;
import
'package:get/get.dart'
;
import
'../resouce/base_color.dart'
;
class
SupportButton
extends
StatelessWidget
{
const
SupportButton
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
Container
(
margin:
const
EdgeInsets
.
only
(
right:
16
),
height:
36
,
decoration:
BoxDecoration
(
border:
Border
.
all
(
color:
BaseColor
.
second500
,
width:
1
,
),
borderRadius:
BorderRadius
.
circular
(
18
),
color:
Colors
.
white
,
),
child:
TextButton
.
icon
(
onPressed:
()
{
Get
.
to
(()
=>
const
SupportScreen
());
},
icon:
const
Icon
(
Icons
.
headset_mic
,
size:
18
,
color:
BaseColor
.
second600
,
),
label:
const
Text
(
"Hỗ trợ"
),
style:
TextButton
.
styleFrom
(
foregroundColor:
BaseColor
.
second600
,
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8
),
),
),
);
}
}
class
SupportScreen
extends
StatelessWidget
{
const
SupportScreen
({
super
.
key
});
@override
Widget
build
(
BuildContext
context
)
{
return
const
Placeholder
();
}
}
Prev
1
2
Next
Write
Preview
Supports
Markdown
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