@@ -535,11 +535,10 @@ class _VideoPlayerState extends State<VideoPlayer> {
535
535
// }
536
536
// }
537
537
// }
538
-
539
538
Widget buildDictionaryLoading (String clipboard) {
540
539
String lookupText;
541
540
if (globalSelectMode.value) {
542
- lookupText = "Looking up \" $clipboard \" ..." ;
541
+ lookupText = "Looking up『 $clipboard 』 ..." ;
543
542
} else {
544
543
lookupText = "Looking up definition..." ;
545
544
}
@@ -672,56 +671,141 @@ class _VideoPlayerState extends State<VideoPlayer> {
672
671
);
673
672
}
674
673
675
- Widget buildDictionaryMatch (DictionaryEntry results) {
674
+ Widget buildDictionaryMatch (List < DictionaryEntry > results) {
676
675
_subtitleFocusNode.unfocus ();
676
+ ValueNotifier <int > selectedIndex = ValueNotifier <int >(0 );
677
677
678
- return Column (
679
- children: [
680
- Padding (
681
- padding: EdgeInsets .all (16.0 ),
682
- child: GestureDetector (
683
- onTap: () {
684
- _clipboard.value = "" ;
685
- _currentDictionaryEntry.value = DictionaryEntry (
686
- word: "" ,
687
- reading: "" ,
688
- meaning: "" ,
689
- );
690
- },
691
- child: SingleChildScrollView (
692
- child: Container (
693
- padding: EdgeInsets .all (16.0 ),
694
- color: Colors .grey[800 ].withOpacity (0.6 ),
678
+ return ValueListenableBuilder (
679
+ valueListenable: selectedIndex,
680
+ builder: (BuildContext context, int _, Widget widget) {
681
+ _currentDictionaryEntry.value = results[selectedIndex.value];
682
+
683
+ return Container (
684
+ padding: EdgeInsets .all (16.0 ),
685
+ alignment: Alignment .topCenter,
686
+ child: Container (
687
+ padding: EdgeInsets .all (16 ),
688
+ margin: EdgeInsets .only (bottom: 84 ),
689
+ color: Colors .grey[800 ].withOpacity (0.6 ),
690
+ child: GestureDetector (
691
+ onHorizontalDragEnd: (details) {
692
+ if (details.primaryVelocity == 0 ) return ;
693
+
694
+ if (details.primaryVelocity.compareTo (0 ) == - 1 ) {
695
+ if (selectedIndex.value == results.length - 1 ) {
696
+ selectedIndex.value = 0 ;
697
+ } else {
698
+ selectedIndex.value += 1 ;
699
+ }
700
+ } else {
701
+ if (selectedIndex.value == 0 ) {
702
+ selectedIndex.value = results.length - 1 ;
703
+ } else {
704
+ selectedIndex.value -= 1 ;
705
+ }
706
+ }
707
+ },
708
+ onTap: () {
709
+ _clipboard.value = "" ;
710
+ _currentDictionaryEntry.value = DictionaryEntry (
711
+ word: "" ,
712
+ reading: "" ,
713
+ meaning: "" ,
714
+ );
715
+ },
695
716
child: Column (
717
+ mainAxisSize: MainAxisSize .min,
696
718
children: [
697
719
Text (
698
- results.word,
720
+ results[selectedIndex.value] .word,
699
721
style: TextStyle (
700
722
fontWeight: FontWeight .bold,
701
723
fontSize: 20 ,
702
724
),
703
725
),
704
- Text (results.reading),
705
- SelectableText ("\n ${results .meaning }\n " ),
726
+ Text (results[selectedIndex.value].reading),
727
+ Flexible (
728
+ child: SingleChildScrollView (
729
+ child:
730
+ Text ("\n ${results [selectedIndex .value ].meaning }\n " ),
731
+ ),
732
+ ),
733
+ Row (
734
+ mainAxisSize: MainAxisSize .min,
735
+ crossAxisAlignment: CrossAxisAlignment .end,
736
+ mainAxisAlignment: MainAxisAlignment .center,
737
+ children: [
738
+ Text (
739
+ "Showing search result " ,
740
+ style: TextStyle (
741
+ fontSize: 11 ,
742
+ ),
743
+ textAlign: TextAlign .center,
744
+ ),
745
+ Text (
746
+ "${selectedIndex .value + 1 } " ,
747
+ style: TextStyle (
748
+ fontWeight: FontWeight .bold,
749
+ fontSize: 11 ,
750
+ ),
751
+ textAlign: TextAlign .center,
752
+ ),
753
+ Text (
754
+ "out of " ,
755
+ style: TextStyle (
756
+ fontSize: 11 ,
757
+ ),
758
+ textAlign: TextAlign .center,
759
+ ),
760
+ Text (
761
+ "${results .length } " ,
762
+ style: TextStyle (
763
+ fontWeight: FontWeight .bold,
764
+ fontSize: 11 ,
765
+ ),
766
+ textAlign: TextAlign .center,
767
+ ),
768
+ Text (
769
+ "found for" ,
770
+ style: TextStyle (
771
+ fontSize: 11 ,
772
+ ),
773
+ textAlign: TextAlign .center,
774
+ ),
775
+ Text (
776
+ "『${results [selectedIndex .value ].searchTerm }』" ,
777
+ style: TextStyle (
778
+ fontWeight: FontWeight .bold,
779
+ fontSize: 11 ,
780
+ ),
781
+ textAlign: TextAlign .center,
782
+ ),
783
+ ],
784
+ )
706
785
],
707
786
),
708
787
),
709
788
),
710
- ),
711
- ),
712
- Expanded (child: Container ()),
713
- ],
714
- );
789
+ );
790
+ });
715
791
}
716
792
717
793
Widget buildDictionary () {
718
794
return ValueListenableBuilder (
719
795
valueListenable: _clipboard,
720
796
builder: (context, clipboard, widget) {
797
+ Future <List <DictionaryEntry >> getDictionaryFuture;
798
+ if (globalSelectMode.value) {
799
+ getDictionaryFuture = getWordDetails (clipboard);
800
+ } else {
801
+ getDictionaryFuture = getJishoSegmentAndSearch (
802
+ _clipboard.value, _currentSubtitle.value.text);
803
+ }
804
+
721
805
return FutureBuilder (
722
- future: getWordDetails (clipboard) ,
723
- builder:
724
- ( BuildContext context, AsyncSnapshot <DictionaryEntry > snapshot) {
806
+ future: getDictionaryFuture ,
807
+ builder: ( BuildContext context,
808
+ AsyncSnapshot <List < DictionaryEntry > > snapshot) {
725
809
if (_clipboard.value == "&<&>export&<&>" ) {
726
810
return buildDictionaryExporting (clipboard);
727
811
}
@@ -738,11 +822,11 @@ class _VideoPlayerState extends State<VideoPlayer> {
738
822
case ConnectionState .waiting:
739
823
return buildDictionaryLoading (clipboard);
740
824
default :
741
- DictionaryEntry entry = snapshot.data;
825
+ List < DictionaryEntry > entries = snapshot.data;
742
826
743
- if (snapshot.hasData) {
744
- _currentDictionaryEntry.value = entry ;
745
- return buildDictionaryMatch (entry );
827
+ if (snapshot.hasData && snapshot.data.isNotEmpty ) {
828
+ _currentDictionaryEntry.value = entries.first ;
829
+ return buildDictionaryMatch (entries );
746
830
} else {
747
831
return buildDictionaryNoMatch (clipboard);
748
832
}
0 commit comments