From 904fc4a9b798006c3bce6d53527d95e1a3555ad5 Mon Sep 17 00:00:00 2001 From: HuiChan Seo <78739194+seochan99@users.noreply.github.com> Date: Sun, 18 Feb 2024 20:12:00 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Feat:=20=EC=B9=B4=EB=93=9C=20type=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/models/word_card_model.dart | 8 ++- lib/viewModels/word/word_viewmodel.dart | 14 +++-- lib/views/word/widget/word_list_widget.dart | 16 ++--- lib/views/word/word_screen.dart | 67 ++++++++++++++++++--- 4 files changed, 82 insertions(+), 23 deletions(-) diff --git a/lib/models/word_card_model.dart b/lib/models/word_card_model.dart index aaaf5eb..b20e37d 100644 --- a/lib/models/word_card_model.dart +++ b/lib/models/word_card_model.dart @@ -3,12 +3,14 @@ class WordCard { final String word; final String speaker; final String video; + final int type; WordCard({ required this.id, required this.word, required this.speaker, required this.video, + required this.type, }); Map toMap() { @@ -17,6 +19,7 @@ class WordCard { 'word': word, 'speaker': speaker, 'video': video, + 'type': type, }; } @@ -26,6 +29,7 @@ class WordCard { word: doc['word'], speaker: doc['speaker'], video: doc['video'], + type: doc['type'], ); } @@ -33,15 +37,15 @@ class WordCard { int? id, String? word, String? speaker, - bool? isDone, - String? doneDate, String? video, + int? type, }) { return WordCard( id: id ?? this.id, word: word ?? this.word, speaker: speaker ?? this.speaker, video: video ?? this.video, + type: type ?? this.type, ); } } diff --git a/lib/viewModels/word/word_viewmodel.dart b/lib/viewModels/word/word_viewmodel.dart index 17260c7..6e2f78c 100644 --- a/lib/viewModels/word/word_viewmodel.dart +++ b/lib/viewModels/word/word_viewmodel.dart @@ -9,15 +9,17 @@ import 'package:intl/intl.dart'; class WordViewModel extends GetxController { final FirebaseFirestore _firestore = FirebaseFirestore.instance; final FirebaseAuth _auth = FirebaseAuth.instance; + final int type; RxList wordList = RxList([]); RxInt currentIndex = 0.obs; + WordViewModel({required this.type}); + @override void onInit() { super.onInit(); - fetchWords(); - fetchWords(); + fetchWords(type); wordList.refresh(); } @@ -26,11 +28,15 @@ class WordViewModel extends GetxController { } // 단어 데이터 가져오기 - Future fetchWords() async { + Future fetchWords(int type) async { final uid = _auth.currentUser?.uid; if (uid != null) { // 모든 단어 데이터 가져오기 - final wordsQuery = await _firestore.collection('words').get(); + final wordsQuery = await _firestore + .collection('words') + .where('type', isEqualTo: type) + .get(); + final allWords = wordsQuery.docs .map((doc) => WordCard.fromDocument(doc.data())) .toList(); diff --git a/lib/views/word/widget/word_list_widget.dart b/lib/views/word/widget/word_list_widget.dart index 1aa7311..724c2da 100644 --- a/lib/views/word/widget/word_list_widget.dart +++ b/lib/views/word/widget/word_list_widget.dart @@ -1,4 +1,3 @@ -import 'package:earlips/models/word_card_model.dart'; import 'package:earlips/models/word_data_model.dart'; import 'package:earlips/utilities/style/color_styles.dart'; import 'package:earlips/viewModels/word/word_viewmodel.dart'; @@ -7,11 +6,15 @@ import 'package:get/get.dart'; class WordList extends StatefulWidget { final List wordDataList; + final int type; PageController pageController; WordList( - {super.key, required this.wordDataList, required this.pageController}); + {super.key, + required this.wordDataList, + required this.pageController, + required this.type}); @override _WordListState createState() => _WordListState(); @@ -38,7 +41,6 @@ class _WordListState extends State { setState(() { wordViewModel.currentIndex.value = index; }); - print('currentIndex: ${wordViewModel.currentIndex.value}'); }, itemBuilder: (context, index) { final wordData = widget.wordDataList[index]; @@ -102,8 +104,8 @@ class _WordListState extends State { tileColor: Colors.white, title: Text( wordData.wordCard.word, - style: const TextStyle( - fontSize: 24, + style: TextStyle( + fontSize: widget.type == 2 ? 19 : 24, fontWeight: FontWeight.w600, color: ColorSystem.black, ), @@ -111,8 +113,8 @@ class _WordListState extends State { ), subtitle: Text( wordData.wordCard.speaker, - style: const TextStyle( - fontSize: 16, + style: TextStyle( + fontSize: widget.type == 2 ? 16 : 20, fontWeight: FontWeight.w600, color: ColorSystem.gray4, ), diff --git a/lib/views/word/word_screen.dart b/lib/views/word/word_screen.dart index d7167a8..d549863 100644 --- a/lib/views/word/word_screen.dart +++ b/lib/views/word/word_screen.dart @@ -14,7 +14,9 @@ class WordScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final wordViewModel = Get.put(WordViewModel()); + final wordViewModel = Get.put(WordViewModel( + type: type, + )); final PageController pageController = PageController(initialPage: wordViewModel.currentIndex.value); @@ -43,6 +45,7 @@ class WordScreen extends StatelessWidget { builder: (controller) => WordList( // viewmodel wordDataList: controller.wordList, + type: type, pageController: pageController, ), ), @@ -67,20 +70,40 @@ class WordScreen extends StatelessWidget { ], ), ), - + const Spacer(), + // wordViewModel final String video로 영상 유튜브 링크를 바로 볼 수 있게 하기 + // const Padding( + // padding: EdgeInsets.all(20.0), + // child: YoutubeWordPlayer(), + // ), const Spacer(), // wordViewModel final String video로 영상 유튜브 링크를 바로 볼 수 있게 하기 ElevatedButton( - onPressed: () { - Get.toNamed( - '/video', - arguments: wordViewModel - .wordList[wordViewModel.currentIndex.value] - .wordCard - .video, + onPressed: () async { + await wordViewModel.markWordAsDone(wordViewModel + .wordList[wordViewModel.currentIndex.value].wordCard); + + // YouTubePlayer 위젯 추가 + Get.dialog( + AlertDialog( + title: const Text('동영상 재생'), + content: Column( + children: [ + YoutubePlayer( + controller: YoutubePlayerController( + initialVideoId: wordViewModel + .wordList[wordViewModel.currentIndex.value] + .wordCard + .video + .split('v=')[1], + ), + ), + ], + ), + ), ); }, - child: const Text("영상 보기"), + child: const Text("므"), ), ElevatedButton( onPressed: () async { @@ -121,3 +144,27 @@ class WordScreen extends StatelessWidget { ); } } + +class YoutubeWordPlayer extends StatefulWidget { + const YoutubeWordPlayer({super.key}); + + @override + State createState() => _YoutubeWordPlayerState(); +} + +class _YoutubeWordPlayerState extends State { + final wordViewModel = Get.find(); + + @override + Widget build(BuildContext context) { + print( + 'video: ${wordViewModel.wordList[wordViewModel.currentIndex.value].wordCard.video}'); + return YoutubePlayer( + controller: YoutubePlayerController( + initialVideoId: wordViewModel + .wordList[wordViewModel.currentIndex.value].wordCard.video + .split('v=')[1], + ), + ); + } +}