Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 DatePicker throws Exception: A RenderListWheelViewport was mutated in _RenderLayoutBuilder.performLayout. #1117

Open
pamtbaau opened this issue Sep 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@pamtbaau
Copy link

pamtbaau commented Sep 15, 2024

Describe the bug
A clear and concise description of what the bug is.

When changing the value of a DatePicker by scrolling the date, an exception is thrown when setState() is called in onChanged.

Workaround until fixed:
Wrap setState() inside a Future.delayed():

    onChanged: (value) {
      Future.delayed(const Duration(milliseconds: 500), () {
        setState(() {
          selected = value;
        });
      });
    },

To Reproduce
Steps to reproduce the behavior:

  • Create fresh Flutter app using cli
  • Add the following dependency:
    fluent_ui:
      git: https://github.com/bdlukaa/fluent_ui.git
    
  • Update main.dart as follows:
    import 'package:fluent_ui/fluent_ui.dart';
    
    void main() async {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return FluentApp(
          title: 'Bug issue',
          home: NavigationView(
            pane: NavigationPane(
              selected: 0,
              displayMode: PaneDisplayMode.compact,
              items: [
                PaneItem(
                  icon: const Icon(FluentIcons.home),
                  title: const Text('Home'),
                  body: Container(
                    alignment: Alignment.center,
                    child: const DateWidget(),
                  ),
                ),
              ],
            ),
          ),
        );
      }
    }
    
    class DateWidget extends StatefulWidget {
      const DateWidget({super.key});
    
      @override
      State<DateWidget> createState() => DateWidgetState();
    }
    
    class DateWidgetState extends State<DateWidget> {
      DateTime selected = DateTime.now();
    
      @override
      void initState() {
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return DatePicker(
          selected: selected,
          fieldOrder: const [
            DatePickerField.year,
            DatePickerField.month,
            DatePickerField.day,
          ],
          onChanged: (value) {
            setState(() {
              selected = value;
            });
          },
        );
      }
    }
    
  • Run app in debug mode
    • Change date by scrolling the year, month or day value.
    • Error is thrown.
  • Run app in release mode
    • Change date by scrolling the year, month or day value.
    • All goes well.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

@bdlukaa
Copy link
Owner

bdlukaa commented Sep 15, 2024

We are calling onChanged before popping the picker. I believe changing this order fixes this issue.

@bdlukaa bdlukaa added the bug Something isn't working label Sep 15, 2024
@MiaraSystems
Copy link

I see the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Ready
Development

No branches or pull requests

3 participants