2021-01-25 10:03:12 +01:00

4.1 KiB
Raw Blame History

Backdrop

Engineering Guidance Document

What is the backdrop?

The backdrop is a component that consists of a back layer and a front layer. The back layer may be revealed to show context and actions that are relevant to the front layers content. To learn more about the backdrop, take a look at the Material Guidelines.

Backdrop in Crane Material Study

Is there a widget for backdrop in Material Components for Flutter?

No. In Flutter, the backdrop is an advanced component. Advanced components don't make great reusable components as they tend to be highly specific to your app. But you can use existing components and classes to achieve the desired interaction!

What are some good ideas for building my own?

When you break it down, backdrops are composed of 2 pieces:

  1. The front layer, a view that displays the users main content whose height can change to reveal information behind it on certain events.
  2. The back layer, that contains context and actionable items that can change the information shown on the front layer.

You probably want to start with a StatefulWidget that ties the two pieces together. This widget will contain the back layer and other widgets such as the AppBar. You will have a separate widget to build out the front layer. To produce the open/close motion of the front layer, build an animation in the back layers parent widget and manage it with an AnimationController. Then implement a button on the AppBar to trigger the animation.

Example code

Example code for building a simple backdrop can be found in the MDC-Flutter codelabs repo.

The example uses existing widgets such as PositionedTransition in tandem with the AnimationController. It also uses some custom widgets to establish the desired look.

Codelab

See MDC-103 for Flutter for a codelab on building this example.

To learn more about animations in Flutter, see flutter.dev/animations.

From a designers point of view

The backdrop is an opportunity to give users easy access to an important element of the app that is secondary to another element. The backdrops back layer is persistent yet unobtrusive. Users have immediate access to the actions and content relevant to the front layer.

Why not a reusable code component?

The backdrop is complex. The component uses multiple types of animations and may depend on app-specific models or information. The level of complexity makes it difficult to generalize for a variety of contexts and a poor candidate for a reusable code component.

The appearance of the backdrop can change with context.

  • Some apps may only need a single front layer and back layer, containing the backdrop to a vertical back and forth interaction.
  • Tabs may necessitate multiple front layer widgets and may also require custom widgets, as the widgets in Flutter dont currently support the desired interactions.

In the Material Study Shrine, backdrop unveils a menu to filter the products found on the front layer. In Crane, the backdrop has multiple front layers that change content based on the selected Tab. The backdrop component has many different uses with various potential uses and doesnt fit a one size fits all.

A backdrop is meant to be used only once per app. You don't need to instantiate more than one for a normal experience even if you have multiple front layers.