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

Add getter for floatingActionButtonLocation in ScaffoldState #147804

Open
kacpmu opened this issue May 3, 2024 · 2 comments · May be fixed by #148082
Open

Add getter for floatingActionButtonLocation in ScaffoldState #147804

kacpmu opened this issue May 3, 2024 · 2 comments · May be fixed by #148082
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-design Owned by Design Languages team triaged-design Triaged by Design Languages team

Comments

@kacpmu
Copy link

kacpmu commented May 3, 2024

Use case

During development of custom bottom app bar I ran into the issue where I need to place items differently based on Scaffold's FAB location.

My current workaround:

class NewScaffold extends Scaffold {
  const NewScaffold({
    super.key, 
    super.appBar,
    super.body,
    super.floatingActionButton,
    // ... and so on, truncated for readability
  });

  @override
  ScaffoldState createState() => NewScaffoldState();

  static NewScaffoldState of(BuildContext context) {
    final NewScaffoldState? result = context.findAncestorStateOfType<NewScaffoldState>();
    if (result != null) {
      return result;
    }
    throw Exception();
  }
}

class NewScaffoldState extends ScaffoldState {
  NewScaffoldState() : super();

  FloatingActionButtonLocation get floatingActionButtonLocation
      => widget.floatingActionButtonLocation ?? FloatingActionButtonLocation.endFloat;
}

Then:

final fabLocation = NewScaffold.of(context).floatingActionButtonLocation;

Which is just fine, because as of today, the internal _floatingActionButtonLocation changes only if widget.floatingActionButtonLocation is changed.

Of course I could simply pass current FAB location to my custom bottom app bar, but it's not the point.

Proposal

Add getter to ScaffoldState:

FloatingActionButtonLocation get floatingActionButtonLocation
      => _floatingActionButtonLocation!; // if widget.floatingActionButtonLocation is null, then it has a value of _kDefaultFloatingActionButtonLocation
@darshankawar darshankawar added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. c: proposal A detailed proposal for a change to Flutter team-design Owned by Design Languages team and removed in triage Presently being triaged by the triage team labels May 6, 2024
@Piinks
Copy link
Contributor

Piinks commented May 8, 2024

Hi @kacpmu, the ScaffoldState should not be needed to access the FloatingActionButtonLocation. By default it is FloatingActionButtonLocation.endFloat, otherwise it is whatever location you have provided to Scaffold.floatingActionButtonLocation. Is there a case that requires getting that value from the state of the Scaffold?

@Piinks Piinks added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 8, 2024
@kacpmu
Copy link
Author

kacpmu commented May 9, 2024

By getting that value from the Scaffold's state I could provide very easy to use and more responsive implementation that does not require setup. Of course, I could pass current FAB location directly into the bottom app bar, but I would like to obtain this info without doing so, since it requires yet another state in your app to be properly managed or at least another place you need to put this info for your widget. On the other hand, Scaffold's state is already out there and may be utilized.

@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 May 9, 2024
@Piinks Piinks added P3 Issues that are less important to the Flutter project triaged-design Triaged by Design Languages team labels May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-design Owned by Design Languages team triaged-design Triaged by Design Languages team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants