Skip to content

Commit

Permalink
#6 Feat: 게시물 수정 시 기존 값 전달, 라우팅
Browse files Browse the repository at this point in the history
- Fix: 라우팅 수정
  • Loading branch information
Jinyshin committed Nov 19, 2023
1 parent e821c47 commit 3f6ca05
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions unibond/lib/screens/community/post_detail_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class DetailScreen extends StatelessWidget {
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
Get.back();
Get.offAll(() => const HomeScreen());
},
),
actions: [
Expand Down Expand Up @@ -54,7 +54,7 @@ class DetailScreen extends StatelessWidget {
),
onPressed: () {
Navigator.of(context).pop();
Get.to(const UpdateScreen());
Get.to(() => UpdateScreen());
}),
TextButton(
child: const Text(
Expand Down
36 changes: 35 additions & 1 deletion unibond/lib/screens/community/post_update_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/util/validator_util.dart';
import 'package:unibond/widgets/custom_text_form_field.dart';
import 'package:unibond/widgets/custom_textarea.dart';
import 'package:unibond/widgets/custon_elevated_button.dart';

class UpdateScreen extends StatelessWidget {
const UpdateScreen({super.key});
final _formKey = GlobalKey<FormState>();
UpdateScreen({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -17,6 +22,35 @@ class UpdateScreen extends StatelessWidget {
},
),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: ListView(
children: [
CustomTextFormField(
hint: "제목",
funvalidator: validateTitle,
value: "하하 이것은 나중에 서버에서 받아올 제목이야.",
),
CustomTextArea(
hint: "내용",
funvalidator: validateContent,
value: "나중에 서버에서 받아올 내용. 나는 배가 고파요. " * 10,
),
CustomElevatedButton(
text: "수정 완료",
screenRoute: () {
if (isValid(_formKey)) {
// TODO: 추후 GetX Obs 기능 사용해서 이전 화면 갱신하기
Get.back();
}
},
),
],
),
),
),
);
}
}
4 changes: 3 additions & 1 deletion unibond/lib/widgets/custom_text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import 'package:flutter/material.dart';
class CustomTextFormField extends StatelessWidget {
final String hint;
final funvalidator;
final String? value;

const CustomTextFormField(
{super.key, required this.hint, required this.funvalidator});
{super.key, required this.hint, required this.funvalidator, this.value});

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: TextFormField(
initialValue: value ?? "",
validator: funvalidator,
obscureText: hint == "비밀번호" ? true : false,
style: const TextStyle(fontSize: 14),
Expand Down
4 changes: 3 additions & 1 deletion unibond/lib/widgets/custom_textarea.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import 'package:flutter/material.dart';
class CustomTextArea extends StatelessWidget {
final String hint;
final funvalidator;
final String? value;

const CustomTextArea(
{super.key, required this.hint, required this.funvalidator});
{super.key, required this.hint, required this.funvalidator, this.value});

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 5.0),
child: TextFormField(
initialValue: value ?? "",
maxLines: 14,
validator: funvalidator,
style: const TextStyle(fontSize: 14),
Expand Down

0 comments on commit 3f6ca05

Please sign in to comment.