@@ -8,13 +8,15 @@ import 'package:flowy_infra/theme.dart';
88import 'package:flowy_infra_ui/flowy_infra_ui.dart' ;
99import 'package:flowy_infra_ui/style_widget/button.dart' ;
1010import 'package:flowy_infra_ui/style_widget/text.dart' ;
11+ import 'package:flowy_infra_ui/widget/rounded_input_field.dart' ;
1112import 'package:flowy_infra_ui/widget/spacing.dart' ;
13+ import 'package:flowy_sdk/log.dart' ;
1214import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart' ;
1315import 'package:flutter/material.dart' ;
1416import 'package:flutter_bloc/flutter_bloc.dart' ;
1517import 'package:table_calendar/table_calendar.dart' ;
1618import 'package:app_flowy/workspace/application/grid/prelude.dart' ;
17- import 'package:dartz/dartz .dart' show Option ;
19+ import 'package:fixnum/fixnum .dart' as $fixnum ;
1820
1921final kToday = DateTime .now ();
2022final kFirstDay = DateTime (kToday.year, kToday.month - 3 , kToday.day);
@@ -35,22 +37,38 @@ class CellCalendar with FlowyOverlayDelegate {
3537 }) async {
3638 CellCalendar .remove (context);
3739
38- final calendar = _CellCalendarWidget (
39- onSelected: onSelected,
40- includeTime: false ,
41- cellContext: cellContext,
42- );
40+ final result = await cellContext.getTypeOptionData ();
41+ result.fold (
42+ (data) {
43+ final typeOptionData = DateTypeOption .fromBuffer (data);
44+ DateTime ? selectedDay;
45+ final cellData = cellContext.getCellData ()? .data;
46+
47+ if (cellData != null ) {
48+ final timestamp = $fixnum.Int64 .parseInt (cellData).toInt ();
49+ selectedDay = DateTime .fromMillisecondsSinceEpoch (timestamp * 1000 );
50+ }
51+
52+ final calendar = _CellCalendarWidget (
53+ onSelected: onSelected,
54+ cellContext: cellContext,
55+ dateTypeOption: typeOptionData,
56+ selectedDay: selectedDay,
57+ );
4358
44- FlowyOverlay .of (context).insertWithAnchor (
45- widget: OverlayContainer (
46- child: calendar,
47- constraints: BoxConstraints .loose (const Size (320 , 500 )),
48- ),
49- identifier: CellCalendar .identifier (),
50- anchorContext: context,
51- anchorDirection: AnchorDirection .leftWithCenterAligned,
52- style: FlowyOverlayStyle (blur: false ),
53- delegate: this ,
59+ FlowyOverlay .of (context).insertWithAnchor (
60+ widget: OverlayContainer (
61+ child: calendar,
62+ constraints: BoxConstraints .loose (const Size (320 , 500 )),
63+ ),
64+ identifier: CellCalendar .identifier (),
65+ anchorContext: context,
66+ anchorDirection: AnchorDirection .leftWithCenterAligned,
67+ style: FlowyOverlayStyle (blur: false ),
68+ delegate: this ,
69+ );
70+ },
71+ (err) => Log .error (err),
5472 );
5573 }
5674
@@ -70,22 +88,28 @@ class CellCalendar with FlowyOverlayDelegate {
7088}
7189
7290class _CellCalendarWidget extends StatelessWidget {
73- final bool includeTime;
7491 final GridDefaultCellContext cellContext;
92+ final DateTypeOption dateTypeOption;
93+ final DateTime ? selectedDay;
7594 final void Function (DateTime ) onSelected;
7695
7796 const _CellCalendarWidget ({
7897 required this .onSelected,
79- required this .includeTime,
8098 required this .cellContext,
99+ required this .dateTypeOption,
100+ this .selectedDay,
81101 Key ? key,
82102 }) : super (key: key);
83103
84104 @override
85105 Widget build (BuildContext context) {
86106 final theme = context.watch <AppTheme >();
87107 return BlocProvider (
88- create: (context) => DateCalBloc (cellContext: cellContext)..add (const DateCalEvent .initial ()),
108+ create: (context) => DateCalBloc (
109+ dateTypeOption: dateTypeOption,
110+ selectedDay: selectedDay,
111+ cellContext: cellContext,
112+ )..add (const DateCalEvent .initial ()),
89113 child: BlocConsumer <DateCalBloc , DateCalState >(
90114 listener: (context, state) {
91115 if (state.selectedDay != null ) {
@@ -101,12 +125,11 @@ class _CellCalendarWidget extends StatelessWidget {
101125 const VSpace (10 ),
102126 ]);
103127
104- state.dateTypeOption.foldRight ( null , (dateTypeOption, _ ) {
128+ if ( state.dateTypeOption.includeTime ) {
105129 children.addAll ([
106130 const _TimeTextField (),
107- const VSpace (10 ),
108131 ]);
109- });
132+ }
110133
111134 children.addAll ([
112135 Divider (height: 1 , color: theme.shader5),
@@ -189,7 +212,7 @@ class _IncludeTimeButton extends StatelessWidget {
189212 Widget build (BuildContext context) {
190213 final theme = context.watch <AppTheme >();
191214 return BlocSelector <DateCalBloc , DateCalState , bool >(
192- selector: (state) => state.dateTypeOption.foldRight ( false , (option, _) => option. includeTime) ,
215+ selector: (state) => state.dateTypeOption.includeTime,
193216 builder: (context, includeTime) {
194217 return SizedBox (
195218 height: 50 ,
@@ -219,7 +242,19 @@ class _TimeTextField extends StatelessWidget {
219242
220243 @override
221244 Widget build (BuildContext context) {
222- return Container ();
245+ final theme = context.watch <AppTheme >();
246+ return Padding (
247+ padding: kMargin,
248+ child: RoundedInputField (
249+ height: 40 ,
250+ style: const TextStyle (fontSize: 14 , fontWeight: FontWeight .w500),
251+ normalBorderColor: theme.shader4,
252+ errorBorderColor: theme.red,
253+ cursorColor: theme.main1,
254+ errorText: context.read <DateCalBloc >().state.inputTimeError.fold (() => "" , (error) => error.toString ()),
255+ onEditingComplete: (value) => context.read <DateCalBloc >().add (DateCalEvent .setTime (value)),
256+ ),
257+ );
223258 }
224259}
225260
@@ -230,29 +265,33 @@ class _DateTypeOptionButton extends StatelessWidget {
230265 Widget build (BuildContext context) {
231266 final theme = context.watch <AppTheme >();
232267 final title = LocaleKeys .grid_field_dateFormat.tr () + " &" + LocaleKeys .grid_field_timeFormat.tr ();
233- return BlocSelector <DateCalBloc , DateCalState , Option < DateTypeOption > >(
268+ return BlocSelector <DateCalBloc , DateCalState , DateTypeOption >(
234269 selector: (state) => state.dateTypeOption,
235270 builder: (context, dateTypeOption) {
236271 return FlowyButton (
237272 text: FlowyText .medium (title, fontSize: 12 ),
238273 hoverColor: theme.hover,
239274 margin: kMargin,
240- onTap: () {
241- dateTypeOption.fold (() => null , (dateTypeOption) {
242- final setting = _CalDateTimeSetting (dateTypeOption: dateTypeOption);
243- setting.show (context);
244- });
245- },
275+ onTap: () => _showTimeSetting (dateTypeOption, context),
246276 rightIcon: svgWidget ("grid/more" , color: theme.iconColor),
247277 );
248278 },
249279 );
250280 }
281+
282+ void _showTimeSetting (DateTypeOption dateTypeOption, BuildContext context) {
283+ final setting = _CalDateTimeSetting (
284+ dateTypeOption: dateTypeOption,
285+ onEvent: (event) => context.read <DateCalBloc >().add (event),
286+ );
287+ setting.show (context);
288+ }
251289}
252290
253291class _CalDateTimeSetting extends StatefulWidget {
254292 final DateTypeOption dateTypeOption;
255- const _CalDateTimeSetting ({required this .dateTypeOption, Key ? key}) : super (key: key);
293+ final Function (DateCalEvent ) onEvent;
294+ const _CalDateTimeSetting ({required this .dateTypeOption, required this .onEvent, Key ? key}) : super (key: key);
256295
257296 @override
258297 State <_CalDateTimeSetting > createState () => _CalDateTimeSettingState ();
@@ -283,9 +322,7 @@ class _CalDateTimeSettingState extends State<_CalDateTimeSetting> {
283322 DateFormatButton (onTap: () {
284323 final list = DateFormatList (
285324 selectedFormat: widget.dateTypeOption.dateFormat,
286- onSelected: (format) {
287- context.read <DateCalBloc >().add (DateCalEvent .setDateFormat (format));
288- },
325+ onSelected: (format) => widget.onEvent (DateCalEvent .setDateFormat (format)),
289326 );
290327 _showOverlay (context, list);
291328 }),
@@ -294,9 +331,7 @@ class _CalDateTimeSettingState extends State<_CalDateTimeSetting> {
294331 onTap: () {
295332 final list = TimeFormatList (
296333 selectedFormat: widget.dateTypeOption.timeFormat,
297- onSelected: (format) {
298- context.read <DateCalBloc >().add (DateCalEvent .setTimeFormat (format));
299- },
334+ onSelected: (format) => widget.onEvent (DateCalEvent .setTimeFormat (format)),
300335 );
301336 _showOverlay (context, list);
302337 },
0 commit comments