Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 회원가입, 로그인 페이지 생성 #3

Merged
merged 9 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
.history
.svn/
migrate_working_dir/
assets/.env

google-services.json
firebase.json
GoogleService-Info.plist
firebase_options.dart


# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Flutter related files
*.flutter-plugins
*.flutter-plugins-dependencies

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
Expand Down
4 changes: 4 additions & 0 deletions .idea/mapsee_front.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
plugins {
id "com.android.application"
// START: FlutterFire Configuration
id 'com.google.gms.google-services'
// END: FlutterFire Configuration
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
Expand Down
3 changes: 3 additions & 0 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
// START: FlutterFire Configuration
id "com.google.gms.google-services" version "4.3.15" apply false
// END: FlutterFire Configuration
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

Expand Down
Binary file added assets/images/mapsee_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions lib/auth/auth_gate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:mapsee/auth/login_or_register.dart';
import 'package:mapsee/pages/home_page.dart';

class AuthGate extends StatelessWidget {
const AuthGate({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
body: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
// user is logged in
if (snapshot.hasData) {
return const HomePage();
}
//user is not logged in
else {
return const LoginOrRegister();
}
}),
);
}
}
34 changes: 34 additions & 0 deletions lib/auth/auth_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:firebase_auth/firebase_auth.dart';

class AuthService {
// instance of auth
final FirebaseAuth _auth = FirebaseAuth.instance;

// sign in
Future<UserCredential> signInWithEmailAndPassword(
String email, String password) async {
try {
UserCredential userCredential = await _auth.signInWithEmailAndPassword(
email: email, password: password);
return userCredential;
} on FirebaseException catch (e) {
throw Exception(e.code);
}
}
// sign up
Future<UserCredential> signUpWithEmailPassword(String email, String password) async{
try{
UserCredential userCredential = await _auth.createUserWithEmailAndPassword(email: email, password: password);
return userCredential;
}on FirebaseException catch(e){
throw Exception(e.code);
}
}

// sign out
Future<void> signOut()async{
return await _auth.signOut();
}

//errors
}
35 changes: 35 additions & 0 deletions lib/auth/login_or_register.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';
import 'package:mapsee/pages/login_page.dart';
import 'package:mapsee/pages/register_page.dart';

class LoginOrRegister extends StatefulWidget {
const LoginOrRegister({super.key});

@override
State<LoginOrRegister> createState() => _LoginOrRegisterState();
}

class _LoginOrRegisterState extends State<LoginOrRegister> {
// initially show login page
bool showLoginPage = true;

// toggle between login and register page
void togglePages() {
setState(() {
showLoginPage = !showLoginPage;
});
}

@override
Widget build(BuildContext context) {
if (showLoginPage) {
return LoginPage(
onTap: togglePages,
);
} else {
return RegisterPage(
onTap: togglePages,
);
}
}
}
106 changes: 106 additions & 0 deletions lib/components/date_input_form.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import 'package:flutter/material.dart';

class DateInputForm extends StatelessWidget {
final TextEditingController yearController;
final TextEditingController monthController;
final TextEditingController dayController;

const DateInputForm({
Key? key,
required this.yearController,
required this.monthController,
required this.dayController,
}) : super(key: key);


@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// YYYY 필드
Flexible(
child: Row(
children: [
Expanded(
child: TextField(
controller: yearController,
decoration: InputDecoration(
hintText: 'YYYY',
hintStyle: TextStyle(
color: Theme.of(context).colorScheme.outline),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.secondary),
),
),
keyboardType: TextInputType.number,
),
),
SizedBox(width: 4), // 여백
Text('년'),
],
),
),
SizedBox(width: 8),
// MM 필드
Flexible(
child: Row(
children: [
Expanded(
child: TextField(
controller: monthController,
decoration: InputDecoration(
hintText: 'MM',
hintStyle: TextStyle(
color: Theme.of(context).colorScheme.outline),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.secondary),
),
),
keyboardType: TextInputType.number,
),
),
SizedBox(width: 4), // 여백
Text('월'),
],
),
),
SizedBox(width: 8),
// DD 필드
Flexible(
child: Row(
children: [
Expanded(
child: TextField(
controller: dayController,
decoration: InputDecoration(
hintText: 'DD',
hintStyle: TextStyle(
color: Theme.of(context).colorScheme.outline),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.secondary),
),
),
keyboardType: TextInputType.number,
),
),
SizedBox(width: 4), // 여백
Text(
'일',
),
],
),
),
],
),
);
}
}
86 changes: 86 additions & 0 deletions lib/components/gender_selection_form.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import 'package:flutter/material.dart';

class GenderSelectionForm extends StatefulWidget {
final ValueChanged<String?> onGenderChanged;
GenderSelectionForm({required this.onGenderChanged});

@override
_GenderSelectionFormState createState() => _GenderSelectionFormState();
}

class _GenderSelectionFormState extends State<GenderSelectionForm> {
String? _selectedGender;

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(0.0),
child: GenderSelection(
selectedGender: _selectedGender,
onGenderChanged: (value) {
setState(() {
_selectedGender = value;
});
widget.onGenderChanged(value);
},
),
);
}
}

class GenderSelection extends StatelessWidget {
final String? selectedGender;
final ValueChanged<String?> onGenderChanged;

const GenderSelection({
Key? key,
required this.selectedGender,
required this.onGenderChanged,
}) : super(key: key);

@override
Widget build(BuildContext context) {
final genderOptions = [
{'label': '남성', 'value': '남성'},
{'label': '여성', 'value': '여성'},
{'label': '선택하지 않음', 'value': '선택하지 않음'},
];

return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: genderOptions.map((option) {
return Expanded(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2.0),
child: SizedBox(
height: 40,
child: ChoiceChip(
label: Container(
alignment: Alignment.topCenter,
child: Text(
option['label']!,
textAlign: TextAlign.center,
style: TextStyle(
color: selectedGender == option['value']
? Colors.white
: Colors.black,
),
),
),
selected: selectedGender == option['value'],
selectedColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.background,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4)),
onSelected: (selected) {
if (selected) onGenderChanged(option['value']);
},
showCheckmark: false,
),
),
),
);
}).toList(),
);
}
}
28 changes: 28 additions & 0 deletions lib/components/my_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';

class MyButton extends StatelessWidget {
final void Function()? onTap;
final String text;

const MyButton({super.key, required this.text, required this.onTap});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.all(15),
margin: const EdgeInsets.symmetric(horizontal: 0),
child: Center(
child: Text(
text,
style: TextStyle(color: Theme.of(context).colorScheme.background),
),
)),
);
}
}
Loading