-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feature/#12 send letter #59
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class LetterReqDto { | ||
String receiverId; | ||
String content; | ||
String title; | ||
|
||
LetterReqDto({ | ||
required this.receiverId, | ||
required this.title, | ||
required this.content, | ||
}); | ||
|
||
Map<String, dynamic> toJson() => { | ||
'receiverId': receiverId, | ||
'title': title, | ||
'content': content, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:unibond/controller/dto/letter_req_dto.dart'; | ||
import 'package:unibond/domain/letter/letter.dart'; | ||
import 'package:unibond/domain/letter/letter_provider.dart'; | ||
import 'package:unibond/domain/letter/letter_repository.dart'; | ||
|
||
class LetterController extends GetxController { | ||
final LetterRepository _letterRepository = LetterRepository(); | ||
|
||
Future<bool> sendLetter( | ||
String receiverId, | ||
String title, | ||
String content, | ||
) async { | ||
try { | ||
bool isSuccess = | ||
await _letterRepository.sendLetter(receiverId, title, content); | ||
return isSuccess; | ||
} catch (error) { | ||
print('sendLetter error: $error'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄λ° μμΌλ‘.. |
||
rethrow; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:unibond/controller/dto/letter_req_dto.dart'; | ||
import 'package:unibond/domain/letter/letter_provider.dart'; | ||
import 'package:unibond/util/userIdNum.dart'; | ||
|
||
const host = "http://3.35.110.214"; | ||
|
||
class LetterProvider extends GetConnect { | ||
Future<Response> sendLetter(Map data) => post( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. κ·Έλ¦¬κ³ λ§μ½μ μ΄λΆλΆμ λ§νλκ±°λΌλ©΄ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ΄ μ¬κΈ° λ°κΏμΌ νλμ§λ₯Ό λ¬Όμ΄λ³Έκ±° λ§λλ° λΉμ μλ¬λ¨λκ² μ λ¬λλ κ° μ€μ nullμ΄ μλ€κ³ ν΄μ Mapμ λ°μ΄ν°λ€μ΄ μ λ΄κ²¨μ κ·Έλ°κ° κ³ λ―Όνμμ΄. |
||
'$host/api/v1/letters', | ||
headers: {"Authorization": "26"}, // μ€μ userIdNumμ λ£μ΄μΌν¨ | ||
data); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μ½μμ°½ κ²°κ³Όλ₯Ό 보면 μ¬κΈ°μλΆν° catchλ¬Έμ λΉ μ§κ³ μμ. μ¬κΈ°μλΆν° ν΄κ²°ν΄μΌν¨. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μλ¬Έ 2 μ²λΌ μλ¬Έμ μ μ°λ €λ©΄ κ·Έλ κ² μκ°νλ μ΄μ λ μ λ° ν¬ν¨ν΄μ μ¨μ€.... |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:get/get.dart'; | ||
import 'package:unibond/controller/dto/letter_req_dto.dart'; | ||
import 'package:unibond/domain/letter/letter_provider.dart'; | ||
|
||
const host = "http://3.35.110.214"; | ||
|
||
class LetterRepository { | ||
final LetterProvider _letterProvider = LetterProvider(); | ||
|
||
Future<bool> sendLetter( | ||
String receiverId, String title, String content) async { | ||
try { | ||
final LetterReqDto letterReqDto = LetterReqDto( | ||
receiverId: receiverId, | ||
title: title, | ||
content: content, | ||
); | ||
|
||
print(letterReqDto.toJson()); | ||
Response response = | ||
await _letterProvider.sendLetter(letterReqDto.toJson()); | ||
|
||
bool isSuccess = response.body["isSuccess"]; | ||
return isSuccess; | ||
} catch (error) { | ||
print("Failed: $error"); | ||
rethrow; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:unibond/view/screens/community/post_detail_screen.dart'; | ||
import 'package:unibond/view/screens/user/login_screen.dart'; | ||
import 'package:unibond/controller/letter_controller.dart'; // LetterControllerλ₯Ό κ°μ Έμ΅λλ€. | ||
import 'package:unibond/view/screens/letter/letter_write_screen.dart'; | ||
|
||
void main() { | ||
runApp(const MaterialApp( | ||
home: MyApp(), | ||
)); | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GetMaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent), | ||
useMaterial3: true, | ||
), | ||
home: DetailScreen( | ||
id: 0, | ||
), // μμ μ€νλμνλ©΄ | ||
title: 'Your App Title', | ||
home: LetterWriteScreen(), // μ±μ μ΄κΈ° νλ©΄μ μ€μ ν©λλ€. | ||
initialBinding: InitialBinding(), // μ¬κΈ°μμ LetterControllerλ₯Ό μ΄κΈ°νν©λλ€. | ||
); | ||
} | ||
} | ||
|
||
class InitialBinding extends Bindings { | ||
@override | ||
void dependencies() { | ||
Get.put(LetterController()); // LetterControllerλ₯Ό λ±λ‘ν©λλ€. | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
String? userIdNum; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class CustomLetterArea extends StatelessWidget { | ||
final String hint; | ||
final TextEditingController controller; | ||
final funvalidator; | ||
final String? value; | ||
|
||
const CustomLetterArea({ | ||
super.key, | ||
required this.hint, | ||
required this.controller, | ||
required this.funvalidator, | ||
this.value, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 5.0), | ||
child: TextFormField( | ||
controller: controller, | ||
maxLines: null, | ||
expands: true, | ||
decoration: InputDecoration( | ||
hintText: "$hintμ(λ₯Ό) μ λ ₯νμΈμ", | ||
enabledBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
focusedBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
errorBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
focusedErrorBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class CustomLetterElevatedButton extends StatelessWidget { | ||
final String text; | ||
final Future<void> Function() funPageRoute; | ||
|
||
const CustomLetterElevatedButton({ | ||
Key? key, | ||
required this.text, | ||
required this.funPageRoute, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
style: ElevatedButton.styleFrom( | ||
minimumSize: const Size(double.infinity, 50), | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
backgroundColor: Colors.blue, | ||
foregroundColor: Colors.white, | ||
), | ||
onPressed: () async { | ||
await funPageRoute(); | ||
}, | ||
child: Text("$text"), | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class CustomLetterFormField extends StatelessWidget { | ||
final String hint; | ||
final TextEditingController controller; | ||
final funvalidator; | ||
final String? value; | ||
|
||
const CustomLetterFormField({ | ||
super.key, | ||
required this.hint, | ||
required this.controller, | ||
required this.funvalidator, | ||
this.value, | ||
required InputDecoration decoration, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 5.0), | ||
child: TextFormField( | ||
validator: funvalidator, | ||
controller: controller, | ||
decoration: InputDecoration( | ||
// ignore: unnecessary_string_interpolations | ||
hintText: hint == "μ΄λ©μΌ" ? "$hintμ μ λ ₯νμΈμ" : "$hintλ₯Ό μ λ ₯νμΈμ", | ||
enabledBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
focusedBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
errorBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
focusedErrorBorder: OutlineInputBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ½μμ°½μ μ΄λ κ² μ°νκ³ μμ
NoSuchMethodError: '[]'μ λν΄ κ²μν΄λ΄€λλ μ λ¬λλ κ°μ nullκ°μ΄ μλ κ²½μ°λ κ΄λ ¨ ν¨μκ° μ μλμ΄ μμ§ μμ λ μκΈ°λ μ€λ₯λΌκ³ ν¨.
<μλ¬Έ1> receiverIdλ₯Ό '2'λ‘ μμλ‘ μ€μ νλλ° κ·Έκ²μΌλ‘ μΈν΄ μκΈ΄ μ€λ₯μΌκΉ? Receiver: nullμ΄ error λ©μΈμ§μΈ κ² κ°μλ° νΉμ μ΄κ² λ¬Έμ μ΄λ €λ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μΌλ¨ μ΄κ²λ§ λ³΄κ³ λ μ΄λ€ μ½λλ‘μΈν΄μ λμ¨ κ²°κ΄κ°μΈμ§ μμκ°μμΌλκΉ μμΌλ‘λ μ½λ μ체μ μ½λ©νΈ λΆνν΄.....μ λ΄.. μ΄λ€κ±Έ printνμλ nullμΈμ§μ λ°λΌ ν΄κ²°λ°©λ²μ΄ μ²μ°¨λ§λ³μΌν λκΉ...!