Skip to content

Can't access useMaterial3 from the theme in the showSnackBar method to conditionally change SnackBar animation for Material 3. #115924

@esouthren

Description

@esouthren

While working on #115750, I was attempting to conditionally change the duration of the SnackBar animation, depending on whether the theme was Material 3 or not.

The Scaffold creates the animation controller for its snackbars in the ScaffoldMessengerState method showSnackBar():

 _snackBarController ??= SnackBar.createAnimationController(vsync: this)

(scaffold.dart)

createAnimationController is a static method of SnackBar:

  static AnimationController createAnimationController({ required TickerProvider vsync }) {
    return AnimationController(
      duration: _snackBarTransitionDuration,
      debugLabel: 'SnackBar',
      vsync: vsync,
    );
  }

(snack_bar.dart)

Ideally we could pass an optional useMaterial3 parameter to this method, and change the duration accordingly.

However, when running a Material 3 example (like snackbar.2.dart in the above mentioned PR) I can't seem to access a value of Theme.of(context).useMaterial3 = true from ScaffoldMessengerState, though I can from ScaffoldState.

Perhaps there's a trivial solution to this, but I need some insight from someone with more Scaffold familiarity.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.f: themingStyling widgets with a themeframeworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions