@@ -9,7 +9,6 @@ import 'package:table_calendar/table_calendar.dart';
99import 'dart:async' ;
1010import 'cell_service/cell_service.dart' ;
1111import 'package:dartz/dartz.dart' ;
12- import 'package:fixnum/fixnum.dart' as $fixnum;
1312import 'package:protobuf/protobuf.dart' ;
1413part 'date_cal_bloc.freezed.dart' ;
1514
@@ -30,9 +29,13 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
3029 // await _loadDateTypeOption(emit);
3130 },
3231 selectDay: (_SelectDay value) {
33- if (! isSameDay (state.selectedDay, value.day)) {
34- _updateCellData (value.day);
35- emit (state.copyWith (selectedDay: value.day));
32+ if (state.dateData != null ) {
33+ if (! isSameDay (state.dateData! .date, value.day)) {
34+ final newDateData = state.dateData! .copyWith (date: value.day);
35+ emit (state.copyWith (dateData: newDateData));
36+ }
37+ } else {
38+ emit (state.copyWith (dateData: DateCellPersistenceData (date: value.day)));
3639 }
3740 },
3841 setCalFormat: (_CalendarFormat value) {
@@ -52,7 +55,12 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
5255 await _updateTypeOption (emit, timeFormat: value.timeFormat);
5356 },
5457 setTime: (_Time value) {
55- //
58+ if (state.dateData != null ) {
59+ final newDateData = state.dateData! .copyWith (time: value.time);
60+ emit (state.copyWith (dateData: newDateData));
61+ } else {
62+ emit (state.copyWith (dateData: DateCellPersistenceData (date: DateTime .now (), time: value.time)));
63+ }
5664 },
5765 );
5866 },
@@ -79,33 +87,6 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
7987 );
8088 }
8189
82- // ignore: unused_element
83- Future <void > _loadDateTypeOption (Emitter <DateCalState > emit) async {
84- final result = await cellContext.getTypeOptionData ();
85- result.fold (
86- (data) {
87- final typeOptionData = DateTypeOption .fromBuffer (data);
88- DateTime ? selectedDay;
89- final cellData = cellContext.getCellData ()? .data;
90-
91- if (cellData != null ) {
92- final timestamp = $fixnum.Int64 .parseInt (cellData).toInt ();
93- selectedDay = DateTime .fromMillisecondsSinceEpoch (timestamp * 1000 );
94- }
95-
96- emit (state.copyWith (
97- dateTypeOption: typeOptionData,
98- selectedDay: selectedDay,
99- ));
100- },
101- (err) => Log .error (err),
102- );
103- }
104-
105- void _updateCellData (DateTime day) {
106- cellContext.saveCellData (DateCellPersistenceData (date: day));
107- }
108-
10990 Future <void >? _updateTypeOption (
11091 Emitter <DateCalState > emit, {
11192 DateFormat ? dateFormat,
@@ -161,19 +142,25 @@ class DateCalState with _$DateCalState {
161142 required DateTime focusedDay,
162143 required String time,
163144 required Option <FlowyError > inputTimeError,
164- DateTime ? selectedDay ,
145+ DateCellPersistenceData ? dateData ,
165146 }) = _DateCalState ;
166147
167148 factory DateCalState .initial (
168149 DateTypeOption dateTypeOption,
169150 DateTime ? selectedDay,
170- ) =>
171- DateCalState (
172- dateTypeOption: dateTypeOption,
173- format: CalendarFormat .month,
174- focusedDay: DateTime .now (),
175- selectedDay: selectedDay,
176- time: "" ,
177- inputTimeError: none (),
178- );
151+ ) {
152+ DateCellPersistenceData ? dateData;
153+ if (selectedDay != null ) {
154+ dateData = DateCellPersistenceData (date: selectedDay);
155+ }
156+
157+ return DateCalState (
158+ dateTypeOption: dateTypeOption,
159+ format: CalendarFormat .month,
160+ focusedDay: DateTime .now (),
161+ dateData: dateData,
162+ time: "" ,
163+ inputTimeError: none (),
164+ );
165+ }
179166}
0 commit comments