1- import 'package:fl_chart/fl_chart.dart' ;
21import 'package:flutter/material.dart' ;
32import 'package:flutter_svg/svg.dart' ;
43import 'package:timefly/detail/detail_calender_view.dart' ;
@@ -7,7 +6,6 @@ import 'package:timefly/models/habit.dart';
76import 'package:timefly/models/habit_peroid.dart' ;
87import 'package:timefly/utils/date_util.dart' ;
98import 'package:timefly/utils/habit_util.dart' ;
10- import 'package:timefly/utils/hex_color.dart' ;
119import 'package:timefly/utils/pair.dart' ;
1210import 'package:timefly/widget/circle_progress_bar.dart' ;
1311
@@ -794,26 +792,17 @@ class HabitCheckInfoView extends StatelessWidget {
794792 }
795793}
796794
797- class HabitStreakInfoView extends StatefulWidget {
795+ class HabitStreakInfoView extends StatelessWidget {
798796 final Habit habit;
799797 final AnimationController animationController;
800798
801799 const HabitStreakInfoView ({Key key, this .habit, this .animationController})
802800 : super (key: key);
803801
804- @override
805- State <StatefulWidget > createState () {
806- return HabitStreakInfoViewState ();
807- }
808- }
809-
810- class HabitStreakInfoViewState extends State <HabitStreakInfoView > {
811- int touchedIndex;
812-
813802 @override
814803 Widget build (BuildContext context) {
815804 Map <String , List <HabitRecord >> records =
816- HabitUtil .combinationRecords (widget. habit.records);
805+ HabitUtil .combinationRecords (habit.records);
817806 Map <String , int > streaks = HabitUtil .getHabitStreaks (records);
818807 int maxCount = 0 ;
819808 if (streaks.length > 0 ) {
@@ -822,11 +811,11 @@ class HabitStreakInfoViewState extends State<HabitStreakInfoView> {
822811 return SlideTransition (
823812 position: Tween <Offset >(begin: Offset (0 , 0.3 ), end: Offset .zero)
824813 .animate (CurvedAnimation (
825- parent: widget. animationController,
814+ parent: animationController,
826815 curve: Interval (0.7 , 1 , curve: Curves .ease))),
827816 child: FadeTransition (
828817 opacity: Tween <double >(begin: 0 , end: 1 ).animate (CurvedAnimation (
829- parent: widget. animationController,
818+ parent: animationController,
830819 curve: Interval (0.7 , 1 , curve: Curves .ease))),
831820 child: Container (
832821 margin: EdgeInsets .only (top: 16 , right: 16 , left: 16 ),
@@ -856,105 +845,86 @@ class HabitStreakInfoViewState extends State<HabitStreakInfoView> {
856845 )
857846 ],
858847 ),
848+ Text (
849+ '历史连续' ,
850+ style: AppTheme .appTheme
851+ .headline1 (fontWeight: FontWeight .normal, fontSize: 14 ),
852+ ),
859853 streaks.length == 0
860854 ? SizedBox ()
861- : Container (
862- margin: EdgeInsets .only (top: 16 , bottom: 16 ),
863- height: 200 ,
864- child: BarChart (barData (streaks, maxCount.toDouble ())),
855+ : Column (
856+ children: streaks.keys
857+ .take (5 )
858+ .map ((e) => _checkInfo (e, streaks[e], maxCount))
859+ .toList (),
865860 ),
866861 ],
867862 ),
868863 ),
869864 ));
870865 }
871866
872- BarChartData barData (Map <String , int > streaks, double maxY) {
873- List <String > keys = streaks.keys.toList ();
874- return BarChartData (
875- maxY: maxY * 1.5 ,
876- barTouchData: BarTouchData (
877- touchTooltipData: BarTouchTooltipData (
878- fitInsideHorizontally: true ,
879- fitInsideVertically: true ,
880- tooltipRoundedRadius: 16 ,
881- tooltipPadding: EdgeInsets .symmetric (horizontal: 16 , vertical: 4 ),
882- tooltipBgColor: Color (widget.habit.mainColor).withOpacity (0.66 ),
883- getTooltipItem: (group, groupIndex, rod, rodIndex) {
884- return BarTooltipItem (
885- '${getTime (keys [groupIndex ])}\n ${rod .y .toInt ()}' ,
886- AppTheme .appTheme.numHeadline1 (
887- textColor: Colors .white,
888- fontSize: 20 ,
889- fontWeight: FontWeight .bold,
890- ));
891- }),
892- touchCallback: (event, barTouchResponse) {
893- setState (() {
894- if (barTouchResponse? .spot != null ) {
895- touchedIndex = barTouchResponse.spot.touchedBarGroupIndex;
896- } else {
897- touchedIndex = - 1 ;
898- }
899- });
900- },
901- ),
902- titlesData: FlTitlesData (
903- show: true ,
904- leftTitles: SideTitles (
905- showTitles: true ,
906- getTextStyles: (context, value) {
907- return AppTheme .appTheme.numHeadline1 (
908- textColor: AppTheme .appTheme.normalColor (),
909- fontSize: 13 ,
910- fontWeight: FontWeight .bold,
911- );
912- }),
913- topTitles: SideTitles (showTitles: false ),
914- bottomTitles: SideTitles (showTitles: false ),
915- rightTitles: SideTitles (showTitles: false )),
916- borderData: FlBorderData (show: false ),
917- gridData: FlGridData (show: false ),
918- barGroups: showingGroups (streaks, maxY),
919- );
920- }
921-
922- List <BarChartGroupData > showingGroups (Map <String , int > streaks, double maxY) {
923- List <int > valuse = streaks.values.toList ();
924- return List .generate (valuse.length, (i) {
925- return makeGroupData (i, valuse[i].toDouble (),
926- isTouched: i == touchedIndex);
927- });
928- }
929-
930- BarChartGroupData makeGroupData (
931- int x,
932- double currentY, {
933- bool isTouched = false ,
934- double width = 12 ,
935- List <int > showTooltips = const [],
936- }) {
937- return BarChartGroupData (
938- barsSpace: 6 ,
939- x: x,
940- barRods: [
941- BarChartRodData (
942- y: currentY,
943- colors: [Color (widget.habit.mainColor)],
944- width: width,
945- backDrawRodData: BackgroundBarChartRodData (
946- show: false ,
867+ Widget _checkInfo (String time, int count, int maxCount) {
868+ List <String > str = time.split (',' );
869+ return Row (
870+ children: [
871+ Container (
872+ width: 140 ,
873+ child: Stack (
874+ children: [
875+ Container (
876+ decoration: BoxDecoration (
877+ color: AppTheme .appTheme.containerBackgroundColor (),
878+ shape: BoxShape .rectangle,
879+ borderRadius: BorderRadius .all (Radius .circular (10 ))),
880+ height: 10 ,
881+ ),
882+ Row (
883+ children: [
884+ Expanded (
885+ flex: count,
886+ child: Container (
887+ decoration: BoxDecoration (
888+ color: Color (habit.mainColor).withOpacity (0.6 ),
889+ shape: BoxShape .rectangle,
890+ borderRadius: BorderRadius .all (Radius .circular (10 ))),
891+ height: 10 ,
892+ ),
893+ ),
894+ Expanded (
895+ flex: maxCount - count,
896+ child: SizedBox (),
897+ )
898+ ],
899+ )
900+ ],
947901 ),
902+ ),
903+ Expanded (
904+ child: SizedBox (),
905+ ),
906+ Row (
907+ mainAxisAlignment: MainAxisAlignment .end,
908+ children: [
909+ Text (
910+ '$count ' ,
911+ style: AppTheme .appTheme
912+ .numHeadline1 (fontWeight: FontWeight .bold, fontSize: 22 ),
913+ ),
914+ SizedBox (
915+ width: 10 ,
916+ ),
917+ Text (
918+ '${str [0 ].replaceAll ('-' , '.' )} - ${str [1 ].substring (str [1 ].indexOf ('-' ) + 1 ).replaceAll ('-' , '.' )}' ,
919+ maxLines: 2 ,
920+ style: AppTheme .appTheme
921+ .numHeadline1 (fontSize: 16 , fontWeight: FontWeight .w300),
922+ )
923+ ],
948924 )
949925 ],
950- showingTooltipIndicators: showTooltips,
951926 );
952927 }
953-
954- String getTime (String time) {
955- List <String > str = time.split (',' );
956- return ' ${str [0 ].replaceAll ('-' , '.' )} - ${str [1 ].substring (str [1 ].indexOf ('-' ) + 1 ).replaceAll ('-' , '.' )}' ;
957- }
958928}
959929
960930class HabitRecentRecordsView extends StatelessWidget {
0 commit comments