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

MenuItemButton error if child is null #147479

Closed
javaone199 opened this issue Apr 28, 2024 · 6 comments · Fixed by #147485
Closed

MenuItemButton error if child is null #147479

javaone199 opened this issue Apr 28, 2024 · 6 comments · Fixed by #147485
Labels
r: invalid Issue is closed as not valid

Comments

@javaone199
Copy link

Steps to reproduce

MenuItemButton(
onPressed: () {},
leadingIcon: Icon(Icons.any),
child: null,
);

Null check operator used on a null value

Expected results

The child is nullable. If it is null, the MenuItemButton should be the same as IconButton.

Actual results

Null check operator used on a null value

Code sample

Code sample
MenuItemButton(
      onPressed: () {},
      leadingIcon: Icon(Icons.any),
      child: null,
    );

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.22631.3447], locale en-US)
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.4.4)
[✓] Android Studio (version 2022.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!
@wuweijian1997
Copy link

but it's required

  const MenuItemButton({
    super.key,
    this.onPressed,
    this.onHover,
    this.requestFocusOnHover = true,
    this.onFocusChange,
    this.focusNode,
    this.shortcut,
    this.style,
    this.statesController,
    this.clipBehavior = Clip.none,
    this.leadingIcon,
    this.trailingIcon,
    this.closeOnActivate = true,
    required this.child,
  });

@wuweijian1997
Copy link

child cannot be null.

class MenuItemButton extends StatefulWidget {
  @override
  State<MenuItemButton> createState() => _MenuItemButtonState();
}


class _MenuItemButtonState extends State<MenuItemButton> {
  @override
  Widget build(BuildContext context) {
     Widget child = TextButton(
      onPressed: widget.enabled ? _handleSelect : null,
      onHover: widget.enabled ? _handleHover : null,
      onFocusChange: widget.enabled ? widget.onFocusChange : null,
      focusNode: _focusNode,
      style: mergedStyle,
      statesController: widget.statesController,
      clipBehavior: widget.clipBehavior,
      isSemanticButton: null,
      child: _MenuItemLabel(
        leadingIcon: widget.leadingIcon,
        shortcut: widget.shortcut,
        trailingIcon: widget.trailingIcon,
        hasSubmenu: false,
        child: widget.child!,  <<<<<<<<<<< look here. can't null
      ),
    );
  }
}

@huycozy huycozy added the in triage Presently being triaged by the triage team label Apr 29, 2024
@huycozy
Copy link
Member

huycozy commented Apr 29, 2024

Hi @javaone199
I'm quite inclined to mark this as a proposal instead since the child property is required by design. I wonder what the use case is although you can pass an empty widget (SizedBox.shrink() or Container()) to child, right?

@huycozy huycozy added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 29, 2024
@javaone199
Copy link
Author

No compilation error if passing null to child.
MenuItemButton = IconButton + TextButton.

I am using different types of buttons by checking if icon or text is null.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 30, 2024
@javaone199
Copy link
Author

This issue is minor and can be closed.

@javaone199
Copy link
Author

javaone199 commented Apr 30, 2024

From VSC, the child parameter is defined as { required Widget? child}. Should it be {required Widget child}? If this is the case, this issue should be re-opened. :)

@huycozy huycozy added r: invalid Issue is closed as not valid and removed in triage Presently being triaged by the triage team labels May 2, 2024
auto-submit bot pushed a commit that referenced this issue May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r: invalid Issue is closed as not valid
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants