text
stringlengths 1
474
|
|---|
will eventually be deprecated according to
|
Flutter’s deprecation policy.For most Flutter widgets, upgrading to Material 3
|
is seamless. But some widgets couldn’t be
|
updated—entirely new implementations were needed,
|
such as NavigationBar.
|
You must make these changes to your code manually.
|
Until your app is entirely updated,
|
the UI might look or act a bit strange.
|
You can find the entirely new Material components by
|
visiting the Affected widgets page.Explore the updated components, typography, color system,
|
and elevation support with the
|
interactive Material 3 demo:<topic_end>
|
<topic_start>More information
|
To learn more about Material Design and Flutter,
|
check out:
|
<topic_end>
|
<topic_start>Migrate to Material 3
|
<topic_end>
|
<topic_start>
|
Summary
|
The Material library has been updated to match the Material 3 Design spec.
|
Changes include new components and component themes, updated component visuals,
|
and much more. Many of these updates are seamless. You’ll see the new version
|
of an affected widget when recompiling your app against the 3.16 (or later)
|
release. But some manual work is also required to complete the migration.<topic_end>
|
<topic_start>
|
Migration guide
|
Prior to the 3.16 release, you could opt in to the Material 3 changes by
|
setting the useMaterial3 flag to true. As of the Flutter 3.16 release
|
(November 2023), useMaterial3 is true by default.By the way, you can revert to Material 2 behavior in your app by setting the
|
useMaterial3 to false. However, this is just a temporary solution. The
|
useMaterial3 flag and the Material 2 implementation will eventually be
|
removed as part of Flutter’s deprecation policy.<topic_end>
|
<topic_start>
|
Colors
|
The default values for ThemeData.colorScheme are updated to match
|
the Material 3 Design spec.The ColorScheme.fromSeed constructor generates a ColorScheme
|
derived from the given seedColor. The colors generated by this
|
constructor are designed to work well together and meet contrast
|
requirements for accessibility in the Material 3 Design system.When updating to the 3.16 release, your UI might look a little strange
|
without the correct ColorScheme. To fix this, migrate to the
|
ColorScheme generated from the ColorScheme.fromSeed constructor.Code before migration:Code after migration:To generate a content-based dynamic color scheme, use the
|
ColorScheme.fromImageProvider static method. For an example of generating a
|
color scheme, check out the ColorScheme from a network image sample.Changes to Flutter Material 3 include a new background color.
|
ColorScheme.surfaceTint indicates an elevated widget.
|
Some widgets use different colors.To return your app’s UI to its previous behavior (which we don’t recommend):Code before migration:Code after migration:The ColorScheme.surfaceTint value indicates a component’s elevation in
|
Material 3. Some widgets might use both surfaceTint and shadowColor to
|
indicate elevation (for example, Card and ElevatedButton) and others might
|
only use surfaceTint to indicate elevation (such as AppBar).To return to the widget’s previous behavior, set, set Colors.transparent
|
to ColorScheme.surfaceTint in the theme. To differentiate a widget’s shadow
|
from the content (when it has no shadow), set the ColorScheme.shadow color to
|
the shadowColor property in the widget theme without a default shadow color.Code before migration:Code after migration:The ElevatedButton now styles itself with a new combination of colors.
|
Previously, when the useMaterial3 flag was set to false, ElevatedButton
|
styled itself with ColorScheme.primary for the background and
|
ColorScheme.onPrimary for the foreground. To achieve the same visuals, switch
|
to the new FilledButton widget without the elevation changes or drop shadow.Code before migration:Code after migration:<topic_end>
|
<topic_start>
|
Typography
|
The default values for ThemeData.textTheme are updated to match the
|
Material 3 defaults. Changes include updated font size, font weight, letter
|
spacing, and line height. For more details, check out the TextTheme
|
documentation.As shown in the following example, prior to the 3.16 release, when a Text
|
widget with a long string using TextTheme.bodyLarge in a constrained layout
|
wrapped the text into two lines. However, the 3.16 release wraps the text into
|
three lines. If you must achieve the previous behavior, adjust the text style
|
and, if necessary, the letter spacing.Code before migration:Code after migration:<topic_end>
|
<topic_start>
|
Components
|
Some components couldn’t merely be updated to match the Material 3 Design spec
|
but needed a whole new implementation. Such components require manual migration
|
since the Flutter SDK doesn’t know what, exactly, you want.Replace the Material 2 style BottomNavigationBar widget with the new
|
NavigationBar widget. It’s slightly taller, contains pill-shaped
|
navigation indicators, and uses new color mappings.Code before migration:Code after migration:Check out the complete sample on
|
migrating from BottomNavigationBar to NavigationBar.Replace the Drawer widget with NavigationDrawer, which provides
|
pill-shaped navigation indicators, rounded corners, and new color mappings.Code before migration:Code after migration:Check out the complete sample on migrating from Drawer to NavigationDrawer.Material 3 introduces medium and large app bars that display a larger headline
|
before scrolling. Instead of a drop shadow, ColorScheme.surfaceTint color
|
is used create a separation from the content when scrolling.The following code demonstrates how to implement the medium app bar:There are now two types of TabBar widgets: primary and secondary.
|
Secondary tabs are used within a content area to further separate
|
related content and establish hierarchy. Check out the TabBar.secondary
|
example.The new TabBar.tabAlignment property specifies the horizontal alignment
|
of the tabs.The following sample shows how to modify tab alignment in a scrollable TabBar:SegmentedButton, an updated version of ToggleButtons,
|
uses fully rounded corners, differs in layout height and
|
size, and uses a Dart Set to determine selected items.Code before migration:Code after migration:Check out the complete sample on
|
migrating from ToggleButtons to SegmentedButton.<topic_end>
|
<topic_start>New components
|
<topic_end>
|
<topic_start>
|
Timeline
|
In stable release: 3.16<topic_end>
|
<topic_start>
|
References
|
Documentation:API documentation:Relevant issues:Relevant PRs:
|
<topic_end>
|
<topic_start>Text
|
<topic_end>
|
<topic_start>
|
Topics
|
<topic_end>
|
<topic_start>Flutter's fonts and typography
|
Typography covers the style and appearance of
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.