Skip to content
Open
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
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:suwon/viewmodels/AccountRecoveryVM.dart';
import 'package:suwon/viewmodels/ChattingVM.dart';
import 'package:suwon/viewmodels/LoginVM.dart';
import 'package:suwon/viewmodels/SignupVM.dart'; // 추가: SignupViewModel 임포트
import 'package:suwon/views/LoginScreen.dart';
Expand All @@ -21,6 +22,7 @@ class MyApp extends StatelessWidget {
ChangeNotifierProvider(
create: (context) => SignupVM()), // 추가: SignupViewModel 제공
ChangeNotifierProvider(create: (context) => AccountRecoveryVM()),
ChangeNotifierProvider(create: (context) => ChatViewModel()),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
Expand Down
23 changes: 23 additions & 0 deletions lib/models/chat_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Message {
final String roomId;
final String sender;
final String contents;

Message({required this.roomId, required this.sender, required this.contents});

factory Message.fromJson(Map<String, dynamic> json) {
return Message(
roomId: json['roomId'],
sender: json['sender'],
contents: json['contents'],
);
}

Map<String, dynamic> toJson() {
return {
'roomId': roomId,
'sender': sender,
'contents': contents,
};
}
}
4 changes: 2 additions & 2 deletions lib/models/user_model.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class UserModel {
final String memberId, password, email, nickname;
final String account, password, email, nickname;

UserModel.fromJson(Map<String, dynamic> json)
: memberId = json["memberId"],
: account = json["account"],
password = json["password"],
email = json["email"],
nickname = json["nickname"];
Expand Down
50 changes: 50 additions & 0 deletions lib/viewmodels/ChattingVM.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:stomp_dart_client/stomp.dart';
import 'package:stomp_dart_client/stomp_config.dart';
import 'package:stomp_dart_client/stomp_frame.dart';
import 'dart:convert';
import 'package:suwon/models/chat_model.dart';

class ChatViewModel extends ChangeNotifier {
StompClient? client;
String serverUrl = 'ws://3.35.83.91:8080/stomp';
String sendEndpoint = '/pub/chat/message/1234';
List<Message> chatMessages = [];

ChatViewModel() {
client = StompClient(
config: StompConfig(
url: serverUrl,
onConnect: onConnect,
onWebSocketError: (dynamic error) => print(error.toString()),
),
);
}

void initialize() {
client!.activate();
}

void onConnect(StompFrame frame) {
client!.subscribe(
destination: '/sub/chat/room/1234',
callback: (StompFrame frame) {
if (frame.body != null) {
Map<String, dynamic> jsonData = json.decode(frame.body!);
Message message = Message.fromJson(jsonData);
chatMessages.add(message);
notifyListeners(); // 새로운 메시지가 추가될 때마다 호출
}
},
);
}

void sendMessage(String message) {
client!.send(
destination: sendEndpoint,
body: json.encode(
Message(roomId: '1234', sender: 'your_name', contents: message)
.toJson()),
);
}
}
12 changes: 0 additions & 12 deletions lib/viewmodels/Chatting_Viewmodel.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/viewmodels/LoginVM.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoginVM extends ChangeNotifier {
try {
final apiUrl = Uri.parse('http://3.35.83.91:8080/member/sign-in');
final requestBody = {
"memberId": _userid,
"account": _userid,
"password": _userpw,
};

Expand Down
49 changes: 31 additions & 18 deletions lib/viewmodels/SignupVM.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import 'package:suwon/models/user_model.dart';
import 'dart:convert';

class SignupVM extends ChangeNotifier {
String _id = '';
String _password = '';
String _email = '';
String _nickname = '';
String _mbti = '';
String _self = ''; //자기소개
String id = '';
String password = '';
String email = '';
String nickname = '';

bool btActivation = true;
bool _idError = false;
bool _pwError = false;
bool _emailError = false;
Expand Down Expand Up @@ -40,6 +39,7 @@ class SignupVM extends ChangeNotifier {
void validateIdInput(String value) {
if (value.length >= 4 && value.length <= 16) {
_idError = false;
btActivation = false;
} else {
_idError = true;
}
Expand All @@ -49,24 +49,27 @@ class SignupVM extends ChangeNotifier {
void validatePwInput(String value) {
if (value.length >= 6 && value.length <= 20) {
_pwError = false;
btActivation = false;
} else {
_pwError = true;
}
notifyListeners();
}

void validatePwMatch(String value) {
if (pwController.text != value) {
_pwMatch = true;
} else {
if (pwController.text == value) {
_pwMatch = false;
btActivation = false;
} else {
_pwMatch = true;
}
notifyListeners();
}

void validateNickNameInput(String value) {
if (value.length < 9) {
_nicknameError = false;
btActivation = false;
} else {
_nicknameError = true;
}
Expand All @@ -83,6 +86,14 @@ class SignupVM extends ChangeNotifier {
notifyListeners();
}

void truebt(btActivation) {
if (_idError && _pwError && _pwMatch && _nicknameError == false) {
btActivation = false;
} else {
btActivation = true;
}
}

bool validateEmail(String value) {
final RegExp emailRegExp =
RegExp(r'^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$');
Expand All @@ -93,26 +104,28 @@ class SignupVM extends ChangeNotifier {

Future<void> signup(UserModel userModel) async {
try {
// Convert UserModel to JSON
Map<String, dynamic> userJson = {
"id1": userModel.memberId,
"password1!": userModel.password,
"valent9": userModel.email,
"n1": userModel.nickname,
// Convert UserModel to Map
Map<String, dynamic> userMap = {
"account": userModel.account,
"password": userModel.password,
"email": userModel.email,
"nickname": userModel.nickname,
};

// Encode JSON to String
String body = json.encode(userJson);
// Encode Map to JSON String
String signupData = json.encode(userMap);

// Make a POST request to your backend API
final response = await http.post(
Uri.parse("http://3.35.83.91:8080/member/sign-up"),
headers: {
'Content-Type': 'application/json',
},
body: body,
body: signupData,
);

print(userMap);

// 응답 상태 확인
if (response.statusCode == 200) {
// 회원가입 성공 시, 필요한 경우 응답을 처리
Expand Down
Loading