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

Refactor/fe/#198 design refactor #200

Merged
merged 3 commits into from
May 14, 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
4 changes: 4 additions & 0 deletions front/capstone_front/assets/translations/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
"complete_signup": "회원가입 완료",
"ok": "확인"
},
"searchScreen": {
"more_than_two": "두 글자 이상 입력해주세요",
"enter_word": "검색어를 입력해주세요"
},
"mainScreen": {
"home": "홈",
"notice": "공지사항",
Expand Down
13 changes: 7 additions & 6 deletions front/capstone_front/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:capstone_front/screens/speech_practice/speech_practice_screen.da
import 'package:capstone_front/screens/speech_practice/speech_screen.dart';
import 'package:capstone_front/services/cafeteria_menu_service.dart';
import 'package:capstone_front/utils/page_animation.dart';
import 'package:capstone_front/utils/search_screen.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -97,17 +98,17 @@ Future<void> getMenus() async {

Future<void> getUserInfo() async {
const storage = FlutterSecureStorage();
String? _userName = (await storage.read(key: "userName"));
if (_userName == null) {
String? tmpUserName = (await storage.read(key: "userName"));
if (tmpUserName == null) {
userName = '';
} else {
userName = _userName;
userName = tmpUserName;
}
String? _userMajor = (await storage.read(key: "userMajor"));
if (_userMajor == null) {
String? tmpUserMajor = (await storage.read(key: "userMajor"));
if (tmpUserMajor == null) {
userMajor = '';
} else {
userMajor = _userMajor;
userMajor = tmpUserMajor;
}
}

Expand Down
95 changes: 95 additions & 0 deletions front/capstone_front/lib/screens/login/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:go_router/go_router.dart';
import 'package:restart_app/restart_app.dart';

class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
Expand Down Expand Up @@ -142,6 +143,71 @@ class _LoginScreenState extends State<LoginScreen> {
),
],
),
const SizedBox(height: 20),
InkWell(
onTap: () {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20.0),
topRight: Radius.circular(20.0),
),
),
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(tr('mainScreen.language_setting')),
const SizedBox(height: 5),
Row(
children: [
IconButton(
icon: const Text(
"\u{1f1f0}\u{1f1f7}"), // 한국어
onPressed: () async {
await storage.write(
key: 'language', value: 'KO');
restartDialog(context, "KO");
},
),
IconButton(
icon: const Text(
"\u{1f1fa}\u{1f1f8}"), // 영어
onPressed: () async {
await storage.write(
key: 'language', value: 'EN-US');
restartDialog(context, 'EN-US');
}),
IconButton(
icon: const Text(
"\u{1F1E8}\u{1F1F3}"), // 중국어
onPressed: () async {
await storage.write(
key: 'language', value: 'ZH');
restartDialog(context, 'ZH');
}),
],
),
const SizedBox(height: 5),
],
),
),
),
);
},
);
},
child: const Text(
"Change Language",
style: TextStyle(decoration: TextDecoration.underline),
),
)
],
),
),
Expand Down Expand Up @@ -189,4 +255,33 @@ class _LoginScreenState extends State<LoginScreen> {
fontSize: 20,
);
}

Future<dynamic> restartDialog(BuildContext context, String language) {
return showDialog(
context: context,
builder: ((context) {
return AlertDialog(
content: Text(tr("mainScreen.language_setting_notice")),
actions: [
Container(
child: ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(tr("mainScreen.no")),
),
),
Container(
child: ElevatedButton(
onPressed: () {
Restart.restartApp(webOrigin: "/");
},
child: Text(tr("mainScreen.yes")),
),
),
],
);
}),
);
}
}
146 changes: 82 additions & 64 deletions front/capstone_front/lib/screens/notice/notice_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:capstone_front/main.dart';
import 'package:capstone_front/models/notice_model.dart';
import 'package:capstone_front/models/notice_response.dart';
import 'package:capstone_front/screens/notice/test_notice_data.dart';
import 'package:capstone_front/screens/notice/notice_detail_screen.dart';
import 'package:capstone_front/services/notice_service.dart';
import 'package:capstone_front/utils/search_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
Expand All @@ -16,14 +18,14 @@ class NoticeScreen extends StatefulWidget {

class _NoticeScreenState extends State<NoticeScreen> {
String selectedItem = 'all';
final _controller = TextEditingController();
// final _controller = TextEditingController();

List<NoticeModel> notices = [];
var cursor = 0;
var hasNext = true;
var itemCount = 0;
late String language;
bool isSearchMode = false;
String _word = '';

void loadNotices(int lastCursor, String language) async {
try {
Expand All @@ -45,6 +47,7 @@ class _NoticeScreenState extends State<NoticeScreen> {

void loadNoticesByWord(int lastCursor, String language, String word) async {
try {
word ??= '';
NoticesResponse res = await NoticeService.getNoticesByWord(
lastCursor, selectedItem, language, word);
setState(() {
Expand All @@ -62,19 +65,32 @@ class _NoticeScreenState extends State<NoticeScreen> {
}

void initLanguageAndLoadNotices() async {
const storage = FlutterSecureStorage();
String? storedLanguage = await storage.read(key: 'language');
var temp = '';
if (storedLanguage != "KO") {
temp = 'EN-US';
} else {
temp = 'KO';
}
// const storage = FlutterSecureStorage();
// String? storedLanguage = await storage.read(key: 'language');
// var temp = '';
// if (storedLanguage != "KO") {
// temp = 'EN-US';
// } else {
// temp = 'KO';
// }
// setState(() {
// language = temp;
// });

loadNotices(cursor, language);
}

void searchNotice(String searchWord) {
setState(() {
language = temp;
cursor = 0;
hasNext = true;
itemCount = 0;
notices = [];
isSearchMode = true;
_word = searchWord;
});

loadNotices(cursor, temp);
print(_word);
loadNoticesByWord(cursor, language, _word);
}

@override
Expand All @@ -88,63 +104,65 @@ class _NoticeScreenState extends State<NoticeScreen> {
return Scaffold(
appBar: AppBar(
scrolledUnderElevation: 0,
title: TextField(
controller: _controller,
onChanged: (text) {
if (text.trim() == "") {
setState(() {
isSearchMode = false;
});
}
},
decoration: InputDecoration(
hintText: "검색어를 입력하세요",
border: InputBorder.none,
hintStyle: const TextStyle(
color: Color(0XFFd7d7d7),
),
suffixIcon: _controller.text.isNotEmpty
? IconButton(
onPressed: () {
_controller.clear();
setState(() {
setState(() {
cursor = 0;
hasNext = true;
itemCount = 0;
notices = [];
isSearchMode = false;
});
loadNotices(cursor, language);
});
},
icon: const Icon(
Icons.cancel,
color: Colors.grey,
),
)
: null,
),
style: const TextStyle(
color: Colors.black,
fontSize: 18.0,
),
),
title: const Text("공지사항"),
// title: TextField(
// controller: _controller,
// onChanged: (text) {
// if (text.trim() == "") {
// setState(() {
// isSearchMode = false;
// });
// }
// },
// decoration: InputDecoration(
// hintText: "검색어를 입력하세요",
// border: InputBorder.none,
// hintStyle: const TextStyle(
// color: Color(0XFFd7d7d7),
// ),
// suffixIcon: _controller.text.isNotEmpty
// ? IconButton(
// onPressed: () {
// _controller.clear();
// setState(() {
// setState(() {
// cursor = 0;
// hasNext = true;
// itemCount = 0;
// notices = [];
// isSearchMode = false;
// });
// loadNotices(cursor, language);
// });
// },
// icon: const Icon(
// Icons.cancel,
// color: Colors.grey,
// ),
// )
// : null,
// ),
// style: const TextStyle(
// color: Colors.black,
// fontSize: 18.0,
// ),
// ),
actions: [
IconButton(
icon: Icon(
Icons.search,
color: Theme.of(context).primaryColor,
),
onPressed: () {
setState(() {
cursor = 0;
hasNext = true;
itemCount = 0;
notices = [];
isSearchMode = true;
});
loadNoticesByWord(cursor, language, _controller.text);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SearchScreen(
searchCallback: (text) {
searchNotice(text);
},
)),
);
},
),
],
Expand Down Expand Up @@ -235,7 +253,7 @@ class _NoticeScreenState extends State<NoticeScreen> {
notices = [];
});
isSearchMode
? loadNoticesByWord(0, language, _controller.text)
? loadNoticesByWord(0, language, _word)
: loadNotices(0, language);
},
child: ListView.separated(
Expand Down
Loading