1
+ import 'dart:math' ;
2
+
1
3
import 'package:flood_mobile/Constants/theme_provider.dart' ;
2
4
import 'package:flutter/material.dart' ;
3
5
import 'package:provider/provider.dart' ;
4
- import '../Api/event_handler_api.dart' ;
5
6
import '../Provider/filter_provider.dart' ;
6
7
import '../Provider/home_provider.dart' ;
7
8
@@ -71,7 +72,7 @@ class _FilterByStatusState extends State<FilterByStatus> {
71
72
width: 18 ,
72
73
height: 18 ,
73
74
child: Center (
74
- child: Text (torrentLength ,
75
+ child: Text (model.torrentList.length. toString () ,
75
76
style: TextStyle (
76
77
color: ThemeProvider .theme.primaryColorLight,
77
78
fontFamily: 'Montserrat' ,
@@ -634,9 +635,9 @@ class _FilterByStatusState extends State<FilterByStatus> {
634
635
width: 18 ,
635
636
height: 18 ,
636
637
child: Center (
637
- child: Text (torrentLength ,
638
+ child: Text (model.torrentList.length. toString () ,
638
639
style: TextStyle (
639
- color: Colors .black45 ,
640
+ color: ThemeProvider .theme.primaryColorLight ,
640
641
fontFamily: 'Montserrat' ,
641
642
fontSize: 15 ,
642
643
fontWeight: FontWeight .bold)),
@@ -703,12 +704,12 @@ class _FilterByStatusState extends State<FilterByStatus> {
703
704
height: 18 ,
704
705
child: Center (
705
706
child: Text (
706
- filterModel.mapTags[filterModel
707
- .mapTags.keys
708
- .toList ()[index]]
707
+ filterModel.mapTags.values
708
+ .toList ()[index][0 ]
709
709
.toString (),
710
710
style: TextStyle (
711
- color: Colors .black45,
711
+ color: ThemeProvider
712
+ .theme.primaryColorLight,
712
713
fontFamily: 'Montserrat' ,
713
714
fontSize: 15 ,
714
715
fontWeight: FontWeight .bold)),
@@ -724,23 +725,50 @@ class _FilterByStatusState extends State<FilterByStatus> {
724
725
)
725
726
],
726
727
),
727
- trailing: Radio <String >(
728
- value: filterModel.mapTags.keys
729
- .toList ()[index]
730
- .toString (),
731
- groupValue: filterModel.tagSelected,
732
- onChanged: (value) {
733
- Provider .of <FilterProvider >(context,
734
- listen: false )
735
- .setFilterSelected (null );
736
- Provider .of <FilterProvider >(context,
737
- listen: false )
738
- .setTagSelected (value.toString ());
739
- Provider .of <FilterProvider >(context,
740
- listen: false )
741
- .settrackerURISelected ('null' );
742
- },
743
- activeColor: Colors .blue,
728
+ trailing: Row (
729
+ mainAxisSize: MainAxisSize .min,
730
+ children: [
731
+ filterModel.mapTags.values
732
+ .toList ()[index][1 ]
733
+ .toString ()
734
+ .contains ('0.0' )
735
+ ? Container ()
736
+ : Text (
737
+ humanReadableByteCountSI (filterModel
738
+ .mapTags.values
739
+ .toList ()[index][1 ]
740
+ .toString ()),
741
+ style: TextStyle (
742
+ color: filterModel.mapTags.keys
743
+ .toList ()[index] ==
744
+ filterModel.tagSelected
745
+ .toString ()
746
+ ? Colors .blue
747
+ : Colors .blueGrey,
748
+ fontFamily: 'Montserrat' ,
749
+ fontSize: 13 ,
750
+ fontWeight: FontWeight .bold,
751
+ ),
752
+ ),
753
+ Radio <String >(
754
+ value: filterModel.mapTags.keys
755
+ .toList ()[index]
756
+ .toString (),
757
+ groupValue: filterModel.tagSelected,
758
+ onChanged: (value) {
759
+ Provider .of <FilterProvider >(context,
760
+ listen: false )
761
+ .setFilterSelected (null );
762
+ Provider .of <FilterProvider >(context,
763
+ listen: false )
764
+ .setTagSelected (value.toString ());
765
+ Provider .of <FilterProvider >(context,
766
+ listen: false )
767
+ .settrackerURISelected ('null' );
768
+ },
769
+ activeColor: Colors .blue,
770
+ ),
771
+ ],
744
772
),
745
773
);
746
774
} else {
@@ -769,11 +797,11 @@ class _FilterByStatusState extends State<FilterByStatus> {
769
797
height: 18 ,
770
798
child: Center (
771
799
child: Text (
772
- Provider .of <FilterProvider >(context)
773
- .mapTags['Untagged' ]
800
+ filterModel.mapTags['Untagged' ][0 ]
774
801
.toString (),
775
802
style: TextStyle (
776
- color: Colors .black45,
803
+ color: ThemeProvider
804
+ .theme.primaryColorLight,
777
805
fontFamily: 'Montserrat' ,
778
806
fontSize: 15 ,
779
807
fontWeight: FontWeight .bold)),
@@ -843,7 +871,7 @@ class _FilterByStatusState extends State<FilterByStatus> {
843
871
width: 18 ,
844
872
height: 18 ,
845
873
child: Center (
846
- child: Text (torrentLength ,
874
+ child: Text (model.torrentList.length. toString () ,
847
875
style: TextStyle (
848
876
color: ThemeProvider .theme.primaryColorLight,
849
877
fontFamily: 'Montserrat' ,
@@ -907,9 +935,8 @@ class _FilterByStatusState extends State<FilterByStatus> {
907
935
height: 18 ,
908
936
child: Center (
909
937
child: Text (
910
- filterModel.maptrackerURIs[filterModel
911
- .maptrackerURIs.keys
912
- .toList ()[index]]
938
+ filterModel.maptrackerURIs.values
939
+ .toList ()[index][0 ]
913
940
.toString (),
914
941
style: TextStyle (
915
942
color: ThemeProvider
@@ -927,23 +954,53 @@ class _FilterByStatusState extends State<FilterByStatus> {
927
954
? Colors .blue
928
955
: Colors .blueGrey,
929
956
),
930
- )
957
+ ),
931
958
],
932
959
),
933
- trailing: Radio <String >(
934
- value: filterModel.maptrackerURIs.keys
935
- .toList ()[index]
936
- .toString (),
937
- groupValue: filterModel.trackerURISelected,
938
- onChanged: (value) {
939
- Provider .of <FilterProvider >(context, listen: false )
940
- .setTagSelected ('null' );
941
- Provider .of <FilterProvider >(context, listen: false )
942
- .setFilterSelected (null );
943
- Provider .of <FilterProvider >(context, listen: false )
944
- .settrackerURISelected (value.toString ());
945
- },
946
- activeColor: Colors .blue,
960
+ trailing: Row (
961
+ mainAxisSize: MainAxisSize .min,
962
+ children: [
963
+ filterModel.maptrackerURIs.values
964
+ .toList ()[index][1 ]
965
+ .toString ()
966
+ .contains ('0.0' )
967
+ ? Container ()
968
+ : Text (
969
+ humanReadableByteCountSI (filterModel
970
+ .maptrackerURIs.values
971
+ .toList ()[index][1 ]
972
+ .toString ()),
973
+ style: TextStyle (
974
+ color: filterModel.maptrackerURIs.keys
975
+ .toList ()[index] ==
976
+ filterModel.trackerURISelected
977
+ .toString ()
978
+ ? Colors .blue
979
+ : Colors .blueGrey,
980
+ fontFamily: 'Montserrat' ,
981
+ fontSize: 13 ,
982
+ fontWeight: FontWeight .bold,
983
+ ),
984
+ ),
985
+ Radio <String >(
986
+ value: filterModel.maptrackerURIs.keys
987
+ .toList ()[index]
988
+ .toString (),
989
+ groupValue: filterModel.trackerURISelected,
990
+ onChanged: (value) {
991
+ Provider .of <FilterProvider >(context,
992
+ listen: false )
993
+ .setTagSelected ('null' );
994
+ Provider .of <FilterProvider >(context,
995
+ listen: false )
996
+ .setFilterSelected (null );
997
+ Provider .of <FilterProvider >(context,
998
+ listen: false )
999
+ .settrackerURISelected (value.toString ());
1000
+ },
1001
+ activeColor: Colors .blue,
1002
+ ),
1003
+ ],
947
1004
),
948
1005
);
949
1006
}),
@@ -954,4 +1011,14 @@ class _FilterByStatusState extends State<FilterByStatus> {
954
1011
});
955
1012
});
956
1013
}
1014
+
1015
+ String humanReadableByteCountSI (String bytesStr) {
1016
+ // convert bytes to readable format from string
1017
+ double bytes = double .parse (bytesStr);
1018
+ int unit = 1024 ;
1019
+ if (bytes < unit) return bytes.toString () + " B" ;
1020
+ int exp = (log (bytes) / log (unit)).floor ();
1021
+ String pre = "kMGTPE" [exp - 1 ];
1022
+ return (bytes / pow (unit, exp)).toStringAsFixed (1 ) + " " + pre + "B" ;
1023
+ }
957
1024
}
0 commit comments