Skip to content

Commit

Permalink
Merge pull request #41 from UniBond-jijijin/feature/#6-UpdatePost
Browse files Browse the repository at this point in the history
Feature/#6 update post
  • Loading branch information
Jinyshin authored Nov 19, 2023
2 parents 1654615 + 3f6ca05 commit 92313ff
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 61 deletions.
1 change: 0 additions & 1 deletion unibond/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/screens/user/join_screen.dart';
import 'package:unibond/screens/home_screen.dart';

void main() {
Expand Down
2 changes: 1 addition & 1 deletion unibond/lib/resources/app_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppColors {
static const Color contentColorOrange = Color(0xFFFF8080);
static const Color contentColorGreen = Color(0xFF3BD79D);
static const Color contentColorPurple = Color.fromARGB(255, 122, 69, 214);
static const Color contentColorPink = Color(0xFFFF3AF2);
static const Color contentColorPink = Color(0xFFFF6292);
static const Color contentColorRed = Color(0xFFE80054);
static const Color contentColorLightBlue = Color(0xFF7091CF);
}
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
56 changes: 56 additions & 0 deletions unibond/lib/screens/community/post_update_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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 {
final _formKey = GlobalKey<FormState>();
UpdateScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('게시물 수정'),
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
Get.back();
},
),
),
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();
}
},
),
],
),
),
),
);
}
}
48 changes: 48 additions & 0 deletions unibond/lib/screens/community/post_write_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/screens/home_screen.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 WriteScreen extends StatelessWidget {
final _formKey = GlobalKey<FormState>();
WriteScreen({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('게시물 작성'),
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
Get.back();
},
),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Form(
key: _formKey,
child: ListView(
children: [
CustomTextFormField(hint: "제목", funvalidator: validateTitle),
CustomTextArea(hint: "내용", funvalidator: validateContent),
CustomElevatedButton(
text: "작성 완료",
screenRoute: () {
if (isValid(_formKey)) {
Get.off(() => const HomeScreen());
}
},
),
],
),
),
),
);
}
}
127 changes: 71 additions & 56 deletions unibond/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:unibond/resources/app_colors.dart';
import 'package:unibond/screens/community/post_detail_screen.dart';
import 'package:unibond/screens/community/post_write_screen.dart';
import 'package:unibond/screens/letter/letter_box_screen.dart';
import 'package:unibond/screens/user/profile_screen.dart';
import 'package:unibond/widgets/navigator.dart';
Expand Down Expand Up @@ -35,71 +37,73 @@ class HomeScreen extends StatelessWidget {
end: Alignment.bottomCenter,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(height: 100),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 120,
width: 170,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF7A34AC), Color(0xFF87ADFF)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
border: Border.all(
width: 5,
color: Colors.white,
),
borderRadius: BorderRadius.circular(30),
),
child: const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"질문",
style: TextStyle(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const SizedBox(height: 100),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 120,
width: 170,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFF7A34AC), Color(0xFF87ADFF)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
border: Border.all(
width: 5,
color: Colors.white,
fontSize: 18,
),
borderRadius: BorderRadius.circular(30),
),
),
),
const SizedBox(width: 20),
Container(
height: 120,
width: 170,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFFFF6292), Color(0xFFFFF1DF)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
child: const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"질문",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
// border: Border.all(
// width: 0,
// ),
borderRadius: BorderRadius.circular(30),
),
child: const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"경험기록",
style: TextStyle(
color: Colors.white,
fontSize: 18,
const SizedBox(width: 20),
Container(
height: 120,
width: 170,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [Color(0xFFFF6292), Color(0xFFFFF1DF)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
// border: Border.all(
// width: 0,
// ),
borderRadius: BorderRadius.circular(30),
),
child: const Padding(
padding: EdgeInsets.all(12.0),
child: Text(
"경험기록",
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
),
),
),
],
],
),
),
),
],
],
),
),
),
),
Expand Down Expand Up @@ -160,6 +164,17 @@ class HomeScreen extends StatelessWidget {
}
},
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Get.to(() => WriteScreen());
},
elevation: 4,
label: const Text('글쓰기'),
icon: const Icon(Icons.mode_edit_outlined),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30)),
foregroundColor: Colors.white,
backgroundColor: AppColors.contentColorPink,
),
);
}
}
Expand Down
20 changes: 20 additions & 0 deletions unibond/lib/util/validator_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,23 @@ Function validatePassword = (String? value) {
return null;
}
};

Function validateTitle = (String? value) {
if (value == null || value.isEmpty) {
return "값을 입력해주세요.";
} else if (value.length > 30) {
return "제목은 30자 이하로 입력해주세요.";
} else {
return null;
}
};

Function validateContent = (String? value) {
if (value == null || value.isEmpty) {
return "값을 입력해주세요.";
} else if (value.length > 500) {
return "내용은 500자 이하로 입력해주세요.";
} else {
return null;
}
};
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
38 changes: 38 additions & 0 deletions unibond/lib/widgets/custom_textarea.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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, 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),
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),
),
),
),
);
}
}

0 comments on commit 92313ff

Please sign in to comment.