dylanwuzh / flutter-cupertino-date-picker

Flutter cupertino style date picker.
Apache License 2.0
363 stars 414 forks source link

Rendering error. setState() was called from a layout or paint call back #158

Open jonathandvu opened 1 year ago

jonathandvu commented 1 year ago

This freezes up and throws the below area when I'm using web app in chrome in debug mode. Any ideas?

My Code:

// Cupertino Date Picker
CupertinoDatePicker(
                  initialDateTime: initialDateTime,
                  minimumDate: initialDateTime,
                  onDateTimeChanged: (val) {
                    if (val != null && val != _chosenDateTime) {
                      setState(() {
                        _chosenDateTime = val;
                      });
                    }
                    // RendererBinding.instance
                    //     .addPostFrameCallback((_) => setState(() {
                    //           _chosenDateTime = val;
                    //         }));
                    // setState(() {
                    //   _chosenDateTime = val;
                    // });
                  }),
            ),

            // Close the modal
            CupertinoButton(
              child: const Text('OK'),
              onPressed: () {
                var formattedTime = DateFormat('EEE, MMM. d, y - h:mm a')
                    .format(_chosenDateTime!);
                dateInput.text = formattedTime;
                Navigator.of(ctx).pop();
              },
            )

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════ The following assertion was thrown during performLayout(): Build scheduled during frame. While the widget tree was being built, laid out, and painted, a new frame was scheduled to rebuild the widget tree. This might be because setState() was called from a layout or paint callback. If a change is needed to the widget tree, it should be applied as the tree is being built. Scheduling a change for the subsequent frame instead results in an interface that lags behind by one frame. If this was done to make your build dependent on a size measured at layout time, consider using a LayoutBuilder, CustomSingleChildLayout, or CustomMultiChildLayout. If, on the other hand, the one frame delay is the desired effect, for example because this is an animation, consider scheduling the frame in a post-frame callback using SchedulerBinding.addPostFrameCallback or using an AnimationController to trigger the animation.

The relevant error-causing widget was: CupertinoDatePicker CupertinoDatePicker:file:///Users/jonathanvu/development/RideRuta/flutter/rutaV1/lib/pages/ create_page.dart:69:22

When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddcruntime/errors.dart 251:49 throw packages/flutter/src/widgets/binding.dart 756:9 packages/flutter/src/widgets/binding.dart 778:14 [_handleBuildScheduled] packages/flutter/src/widgets/framework.dart 2482:7 scheduleBuildFor packages/flutter/src/widgets/framework.dart 4495:5 markNeedsBuild packages/flutter/src/widgets/framework.dart 1129:5 setState packages/flutter/src/cupertino/date_picker.dart 921:5 [_pickerDidStopScrolling] packages/flutter/src/cupertino/date_picker.dart 693:11 packages/flutter/src/widgets/notification_listener.dart 130:22 onNotification packages/flutter/src/widgets/framework.dart 3078:18 dispatchNotification packages/flutter/src/widgets/framework.dart 3081:13 dispatchNotification packages/flutter/src/widgets/framework.dart 3081:13 dispatchNotification packages/flutter/src/widgets/framework.dart 4375:24 dispatchNotification packages/flutter/src/widgets/notification_listener.dart 60:13 dispatch packages/flutter/src/widgets/scroll_activity.dart 104:61 dispatchScrollEndNotification packages/flutter/src/widgets/scroll_position.dart 907:5 didEndScroll packages/flutter/src/widgets/scroll_position.dart 876:23 beginActivity packages/flutter/src/widgets/scroll_position_with_single_context.dart 114:11 beginActivity packages/flutter/src/widgets/scroll_position_with_single_context.dart 129:5 goIdle packages/flutter/src/widgets/scroll_position_with_single_context.dart 148:7 goBallistic packages/flutter/src/widgets/scroll_activity.dart 549:14 applyNewDimensions packages/flutter/src/widgets/scroll_position.dart 623:5 applyNewDimensions packages/flutter/src/widgets/scroll_position_with_single_context.dart 104:11 applyNewDimensions packages/flutter/src/widgets/scroll_position.dart 553:7 applyContentDimensions packages/flutter/src/rendering/list_wheel_viewport.dart 669:12 performLayout packages/flutter/src/rendering/object.dart 1757:7 [_layoutWithoutResize] packages/flutter/src/rendering/object.dart 887:17 flushLayout packages/flutter/src/rendering/binding.dart 504:19 drawFrame packages/flutter/src/widgets/binding.dart 892:13 drawFrame packages/flutter/src/rendering/binding.dart 370:5 [_handlePersistentFrameCallback] packages/flutter/src/scheduler/binding.dart 1146:15 [_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1083:9 handleDrawFrame packages/flutter/src/scheduler/binding.dart 997:5 [_handleDrawFrame] lib/_engine/engine/platform_dispatcher.dart 1090:13 invoke lib/_engine/engine/platform_dispatcher.dart 160:5 invokeOnDrawFrame lib/_engine/engine/initialization.dart 194:45

The following RenderObject was being processed when the exception was fired: RenderListWheelViewport#7835c NEEDS-LAYOUT: needs compositing creator: ListWheelViewport ← IgnorePointer-[GlobalKey#1a0b2] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey#bd4b6] ← Listener ← _ScrollableScope ← _ScrollSemantics-[GlobalKey#dd7d4] ← NotificationListener ← _FixedExtentScrollable ← NotificationListener ← ⋯ parentData: (can use size) constraints: BoxConstraints(w=297.0, h=400.0) layer: OffsetLayer#e9131 size: Size(297.0, 400.0) This RenderObject had the following descendants (showing up to depth 5): child 1: RenderIndexedSemantics#3f899 relayoutBoundary=up1 child: RenderPadding#4bcb3 relayoutBoundary=up2 child: RenderPositionedBox#abfa7 relayoutBoundary=up3 child: RenderPositionedBox#cc2e5 relayoutBoundary=up4 child: RenderParagraph#de66e relayoutBoundary=up5 child 2: RenderIndexedSemantics#c4c55 relayoutBoundary=up1 child: RenderPadding#fadc5 relayoutBoundary=up2 child: RenderPositionedBox#51df8 relayoutBoundary=up3 child: RenderPositionedBox#e0bcc relayoutBoundary=up4 child: RenderParagraph#e53e1 relayoutBoundary=up5 child 3: RenderIndexedSemantics#5a811 relayoutBoundary=up1 child: RenderPadding#7bb56 relayoutBoundary=up2 child: RenderPositionedBox#c54f9 relayoutBoundary=up3 child: RenderPositionedBox#3bfbf relayoutBoundary=up4 child: RenderParagraph#31919 relayoutBoundary=up5 child 4: RenderIndexedSemantics#217e2 relayoutBoundary=up1 child: RenderPadding#b06f8 relayoutBoundary=up2 child: RenderPositionedBox#260fd relayoutBoundary=up3 child: RenderPositionedBox#8ad49 relayoutBoundary=up4 child: RenderParagraph#802e8 relayoutBoundary=up5 child 5: RenderIndexedSemantics#26093 relayoutBoundary=up1 child: RenderPadding#09418 relayoutBoundary=up2 child: RenderPositionedBox#673ee relayoutBoundary=up3 child: RenderPositionedBox#a353c relayoutBoundary=up4 child: RenderParagraph#f33e1 relayoutBoundary=up5 ...(descendants list truncated after 25 lines) ═════════════════════════════════════════════════════════════════════════════════════════════ ═══════