-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ImageUpload 수정 * made an email duplicate checker
- Loading branch information
1 parent
cac9484
commit f985e37
Showing
14 changed files
with
187 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
final emailDuplicateProvider = StateNotifierProvider<EmailDuplicateNotifier, EmailDuplicateState>((ref) { | ||
return EmailDuplicateNotifier(); | ||
}); | ||
|
||
class EmailDuplicateState { | ||
String? email; | ||
bool isDuplication = false; | ||
|
||
EmailDuplicateState({this.email, required this.isDuplication}); | ||
} | ||
|
||
class EmailDuplicateNotifier extends StateNotifier<EmailDuplicateState> { | ||
EmailDuplicateNotifier() : super(EmailDuplicateState(isDuplication: false)); | ||
|
||
final FirebaseFirestore _firestore = FirebaseFirestore.instance; | ||
|
||
Future<bool> isDuplication(String email) async { | ||
try { | ||
QuerySnapshot querySnapshot = await _firestore.collection('users') | ||
.where('email', isEqualTo: email) | ||
.get(); | ||
if (querySnapshot.docs.isNotEmpty) { | ||
// 이메일이 이미 존재하는 경우 | ||
state = EmailDuplicateState(email: email, isDuplication: true); | ||
return true; | ||
} else { | ||
// 이메일이 존재하지 않는 경우 | ||
state = EmailDuplicateState(email: email, isDuplication: false); | ||
return false; | ||
} | ||
} catch(e){ | ||
print('$e'); | ||
state = EmailDuplicateState(email: email, isDuplication: false); | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,3 +324,4 @@ Widget _uploadProfileImageButtons(FirestoreService firestoreService, | |
icon: const Icon(Icons.settings), | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:blueberry_flutter_template/widgets/signup/EmailDuplicateWidget.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class EmailInputScreen extends StatelessWidget { | ||
final VoidCallback onNext; | ||
const EmailInputScreen({super.key, required this.onNext}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return EmailDuplicateWidget(onNext: onNext); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:blueberry_flutter_template/providers/user/SignUpEmailDuplicationProvider.dart'; | ||
import 'package:blueberry_flutter_template/screens/mypage/SignUpScreen.dart'; | ||
import 'package:blueberry_flutter_template/screens/mypage/signup/EmailInputPage.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class EmailDuplicateWidget extends ConsumerStatefulWidget { | ||
final VoidCallback onNext; | ||
|
||
EmailDuplicateWidget({required this.onNext}); | ||
|
||
@override | ||
_EmailDuplicateWidgetState createState() => _EmailDuplicateWidgetState(); | ||
} | ||
|
||
class _EmailDuplicateWidgetState extends ConsumerState<EmailDuplicateWidget> { | ||
final TextEditingController _emailController = TextEditingController(); | ||
bool isEmailAvailable = false; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final email = ref.read(emailProvider.notifier); | ||
final emailVerification = ref.read(emailVerificationProvider.notifier); | ||
final emailDuplicate = ref.watch(emailDuplicateProvider.notifier); | ||
|
||
return Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
TextField( | ||
controller: _emailController, | ||
onChanged: (value) => email.state = value, | ||
decoration: InputDecoration(labelText: '이메일 입력'), | ||
), | ||
const SizedBox(height: 20), | ||
|
||
_duplicationBtn(emailDuplicate, context), | ||
|
||
const SizedBox(height: 20), | ||
|
||
_verifyBtn(emailVerification, email), | ||
], | ||
), | ||
); | ||
} | ||
|
||
ElevatedButton _verifyBtn(EmailVerificationNotifier emailVerification, StateController<String> email) { | ||
return ElevatedButton( | ||
onPressed: () async { | ||
await emailVerification.sendVerificationCode(email.state); | ||
widget.onNext(); | ||
}, | ||
child: Text('인증번호 전송'), | ||
); | ||
} | ||
|
||
ElevatedButton _duplicationBtn(EmailDuplicateNotifier emailDuplicate, BuildContext context) { | ||
return ElevatedButton( | ||
onPressed: () async { | ||
String email = _emailController.text; | ||
bool isDuplicate = await emailDuplicate.isDuplication(email); | ||
if (isDuplicate) { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text('중복된 이메일입니다.')), | ||
); | ||
setState(() { | ||
isEmailAvailable = false; | ||
}); | ||
} else { | ||
ScaffoldMessenger.of(context).showSnackBar( | ||
SnackBar(content: Text('사용 가능한 이메일입니다.')), | ||
); | ||
setState(() { | ||
isEmailAvailable = true; | ||
}); | ||
} | ||
}, | ||
child: Text('중복 확인'), | ||
); | ||
} | ||
} | ||
|