Skip to content

Commit

Permalink
폰인증 위젯 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
silver3800 committed Jul 23, 2024
1 parent 65f509e commit 6c7b78e
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 271 deletions.
4 changes: 4 additions & 0 deletions lib/providers/signup/PhoneNumberProvider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

// 폰인증 provider
final phoneNumberProvider = StateProvider<String>((ref) => '');
36 changes: 17 additions & 19 deletions lib/providers/signup/PhoneVerificationProvider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// 휴대폰인증 provider
import 'package:flutter_riverpod/flutter_riverpod.dart';

// 휴대폰인증 provider
final phoneNumberProvider = StateProvider<String>((ref) => '');
final verificationCodeProvider = StateProvider<String>((ref) => '');
final phoneVerificationProvider =
NotifierProvider<PhoneVerificationNotifier, PhoneVerificationState>(() {
return PhoneVerificationNotifier();
Expand All @@ -12,12 +8,20 @@ final phoneVerificationProvider =
class PhoneVerificationNotifier extends Notifier<PhoneVerificationState> {
@override
PhoneVerificationState build() {
return VerificationInitialize();
return _initializeState();
}

Future<bool> sendPhoneNumber(String phoneNumber) async {
void initialize() {
state = _initializeState();
}

PhoneVerificationState _initializeState() {
return VerificationInitialized();
}

Future<bool> sendVerificationRequest(String phoneNumber) async {
try {
final verificationId = await getVerificationId(phoneNumber);
final verificationId = await requestVerificationId(phoneNumber);
state = VerificationCodeSent(verificationId);
return true;
} catch (e) {
Expand All @@ -26,11 +30,11 @@ class PhoneVerificationNotifier extends Notifier<PhoneVerificationState> {
}
}

Future<bool> verifyCode(String code) async {
Future<bool> checkVerificationCode(String code) async {
if (state is VerificationCodeSent) {
final verificationId = (state as VerificationCodeSent).verificationId;
try {
await verifyPhoneVerificationCode(verificationId, code);
await validateVerificationCode(verificationId, code);
state = VerificationSuccess();
return true;
} catch (e) {
Expand All @@ -43,15 +47,9 @@ class PhoneVerificationNotifier extends Notifier<PhoneVerificationState> {
}
}

// 휴대폰인증 상태관리 클래스
abstract class PhoneVerificationState {}

class VerificationInitialize extends PhoneVerificationState {
final String phoneNumber;
final String verificationNumber;

VerificationInitialize({this.phoneNumber = '', this.verificationNumber = ''});
}
class VerificationInitialized extends PhoneVerificationState {}

class VerificationCodeSent extends PhoneVerificationState {
final String verificationId;
Expand All @@ -68,8 +66,8 @@ class VerificationError extends PhoneVerificationState {
}

// 휴대폰번호 전송 로직 (구현 필요)
Future<String> getVerificationId(String phoneNumber) async {
// 에러테스트
Future<String> requestVerificationId(String phoneNumber) async {

if (phoneNumber.length == 11) {
return 'verificationId';
}
Expand All @@ -78,7 +76,7 @@ Future<String> getVerificationId(String phoneNumber) async {
}

// 인증번호 전송 로직 (구현 필요)
Future<bool> verifyPhoneVerificationCode(
Future<bool> validateVerificationCode(
String verificationId, String code) async {
if (verificationId == 'verificationId' && code == "123456") {
return true;
Expand Down
3 changes: 3 additions & 0 deletions lib/providers/signup/VerificationCodeProvider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

final verificationCodeProvider = StateProvider<String>((ref) => '');
6 changes: 3 additions & 3 deletions lib/screens/mypage/PhoneVerificationScreen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:blueberry_flutter_template/screens/mypage/signup/PhoneInputPage.dart';
import 'package:blueberry_flutter_template/screens/mypage/signup/PhoneVerificationPage.dart';
import 'package:flutter/material.dart';

final PageController _pageController = PageController();
Expand All @@ -14,13 +14,13 @@ class PhoneVerificationScreen extends StatelessWidget {
controller: _pageController,
physics: const NeverScrollableScrollPhysics(),
children: [
PhoneInputPage(
PhoneNumberInputPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
),
),
PhoneVerificationNumberInputPage(
VerificationCodeInputPage(
onNext: () => _pageController.nextPage(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
Expand Down
249 changes: 0 additions & 249 deletions lib/screens/mypage/signup/PhoneInputPage.dart

This file was deleted.

Loading

0 comments on commit 6c7b78e

Please sign in to comment.