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

BoxyChild receives null parentData on first layout #9

Closed
MikeFP opened this issue Sep 20, 2021 · 2 comments
Closed

BoxyChild receives null parentData on first layout #9

MikeFP opened this issue Sep 20, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@MikeFP
Copy link

MikeFP commented Sep 20, 2021

The first time BoxyDelegate.layout() is processed, trying to access a child's parentData evaluates to null.

After a hot reload or changing the screen state to rebuild it, layout is called again but parentData is now accessible.

Code example:

import 'package:boxy/boxy.dart';
import 'package:flutter/widgets.dart';

class TestBug extends StatelessWidget {
  const TestBug({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: CustomBoxy(
        delegate: MyBoxy(),
        children: [
          BoxyId<String>(
            id: 'child-0',
            data: "I'm a child",
            child: SizedBox(width: 50, height: 50),
          ),
        ],
      ),
    );
  }
}

class MyBoxy extends BoxyDelegate {
  @override
  Size layout() {
    final child = getChild('child-0');
    print(child.parentData);
    print(child.parentData as String?);
    child.layout(constraints);
    child.position(Offset.zero);
    return constraints.biggest;
  }
}

Putting this widget in a Scaffold's body prints null twice, which is unexpected. Hitting Ctrl+S to save the file triggers a hot reload and prints "I'm a child" twice, as expected.

@pingbird
Copy link
Owner

I reproduced the issue and published a fix in version 2.0.4, let me know if that works!

@MikeFP
Copy link
Author

MikeFP commented Sep 20, 2021

@PixelToast It's working fine. Thanks!

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
None yet
Development

No branches or pull requests

2 participants