Everything Material
All At Once
Package Author
Mike Rydstrom�@RydMike
Flutter Contributor
Taha Tesser
@TahaTesser
Everything Material Agenda
Everything Material
The ColorScheme has gone wild and we are going to talk about it …
Everything Material
The Carousel has landed in master!
Everything Material
MaterialState
WidgetState
Everything Material
Button builders can completely transform your Material buttons
Everything Material
Quality improvements in:
Everything Material
We will dig into how to make platform adaptive themes and other advanced techniques
Everything Material
We will look at
“New” ColorScheme
The Evolution of Flutter’s Material ColorScheme
From Material 2
An easy 12 colors per
light and …
The Evolution of Flutter’s Material ColorScheme
From Material 2
An easy 12 colors per
light and dark theme
So 24 in total, not so hard to do
The Evolution of Flutter’s Material ColorScheme
To Material 3
With 30 colors per
light and …
The Evolution of Flutter’s Material ColorScheme
To Material 3
With 30 colors per
light and dark theme
Making it 60 in total!
Eh, OK, but OUCH …
NOTE: There were 7 more colors in Flutter than those shown in above M3 guide at the time. These were outlineVariant, inversePrimary, inverseSurface, onInverseSurface, surfaceTint, scrim and shadow making it 30 per mode
The Evolution of Flutter’s Material ColorScheme
To the revised ColorScheme in
Flutter 3.22 and later
With 46 colors per
light and …
The Evolution of Flutter’s Material ColorScheme
To the revised ColorScheme in
Flutter 3.22 and later
With 46 colors per
light and dark scheme
Now it is 92 in total !
WHAT?
NOTE: The color surfaceTint is missing above. There are also 3 deprecated colors in the Flutter ColorScheme: background, onBackground and surfaceVariant
Revised ColorScheme
Why this change?
To bring Flutter up to Material Design specification changes introduced already in March 23, 2023
Why the specification update?
Address developer experience feedback about using elevation to create surfaces with tinted surfaces
Revised ColorScheme
Surface Colors
The update introduces new dedicated surface color roles that are no longer tied to Material elevation
We now have predefined color shades for different surface roles
New surface color roles
Surface container is the default role, others are used for creating hierarchy and nested containers in layouts on larger media
Revised ColorScheme
Fixed Colors
Primary fixed, secondary fixed, and tertiary fixed plus their dim variants, are fill colors used against surfaces
These colors maintain the same tone, meaning they are the same color, in light and dark themes. This is different from regular container colors, which change in tone, or color, between theme mod
The fixed color role may be used instead of the equivalent container role in situations where such fixed behavior is desired
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Tonal Spot
Material and Flutter default
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Fidelity
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Vibrant
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Content
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Neutral
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Monochrome
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Expressive
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Rainbow
Used source color
Revised ColorScheme
Scheme Variants
In Flutter 3.22.2 and later we have
DynamicSchemeVariant
Fruit Salad
Used source color
Revised ColorScheme
Contrast Level
In coming next stable we will likely also get contrast level from -1 to 1, where -1 is the lowest, zero is normal, 1 is highest
We will look at all the new ColorScheme features a bit closer in a demo shortly
Too many colors to
define manually
Use a tool?
Web Material Theme Builder�https://material-foundation.github.io/material-theme-builder/
Figma Material Theme Builder�https://www.figma.com/community/plugin/1034969338659738588/material-theme-builder
Web Material
Theme Builder
Select your main colors, add theme extension colors, add custom fonts, and export …
export…
And we get this, for the light theme and another set for the …
export…
And we get this, for the light theme and another set for the dark theme
For both light and dark, we also get the higher than normal contrast schemes, medium contrast and high contrast
As mentioned, the contrast level is a new feature coming in a future release of Flutter, potentially in next stable
�Contrast level exists already as a property in ColorScheme.fromSeed in the master channel
export…
We also get some nice utilities for the theme and our custom colors
Note:�The custom colors are not implemented as Flutter theme extensions, just a getter!
The theme also uses deprecated background color
For more info about Theme Builder check out a talk tomorrow (July 5, 2024) by Shree Bhagwat at 10:15 in the Async Area room
Manually?
The Material theme builders are nice, but if you change anything you will need to regenerate everything and import it again
They also demonstrate the futility of trying the define schemes manually
Too many colors and intricate relationships between them that must be defined correctly
How can we do it in Flutter?
From Seed
Using ColorScheme.fromSeed is the well known standard approach in Flutter for defining a custom Material ColorScheme using Flutter code
You can use a custom or brand color as the seed color to generate the ColorScheme
Let’s say we have indigo blue:
Where is my brand color?
From Seed
Using ColorScheme.fromSeed is the well known standard approach in Flutter for defining a custom Material ColorScheme using Flutter code
You can use a custom or brand color as the seed color to generate the ColorScheme
Let’s say we have indigo blue:
Pin the brand color to desired scheme color!
From Seed
ColorScheme.fromSeed produces a different result in Flutter 3.22 compared to earlier
Before
Flutter 3.22
From Seed
ColorScheme.fromSeed produces a different result in Flutter 3.22 compared to earlier
After
Flutter 3.22
From Seed
ColorScheme.fromSeed produces a different result in Flutter 3.22 compared to earlier
Proposed solution, the new API in Flutter 3.22.2
DynamicSchemeVariant
“Fidelity”
Brighter? Yes!
Nice, but not the same
From Seeds?
We have TWO brand colors! With Theme Builder I can specify them and use our accent brand color and get it applied to e.g. tertiary colors
How can I do this with ColorScheme.fromSeed?
We have indigo blue and …
From Seeds?
We have TWO brand colors! With Theme Builder I can specify them and use our accent brand color and get it applied to e.g. tertiary colors
How can I do this with ColorScheme.fromSeed?
We have indigo blue and asparagus:
Not doable?
From Seeds
Use a package, where we can use:�SeedColorScheme.fromSeeds
Slightly different API, but very close to original. It can use a separate seed key color for every color palette used by the ColorScheme
We have indigo blue and asparagus:
From Seeds
When using�SeedColorScheme.fromSeeds
You also get many additional features to modify and tune the ColorScheme generation, for example:
We have indigo blue and asparagus:
FlexSeedScheme
We need a package that gives us:�SeedColorScheme.fromSeeds
Available in package: flex_seed_scheme�https://pub.dev/packages/flex_seed_scheme
Web demo: https://rydmike.com/flexseedscheme/demo-v3/
Dynamic schemes MCU
Dynamic schemes MCU
Flex tones schemes FSS
Dynamic schemes MCU
Flex tones schemes FSS
Seed for each palette MCU & FSS
Dynamic schemes MCU
Flex tones schemes FSS
Seed for each palette MCU & FSS
Contrast level MCU
Dynamic schemes MCU
Flex tones schemes FSS
Seed for each palette MCU & FSS
Contrast level MCU
Test pinning of seed colors
FSS only:
Quick scheme modifiers
Customizable scheme generation
New Component Color Mappings
The new Material specification changed how all Material widgets use surface colors
Example�Navigation Bar
Instead of using surface impacted by elevation 3 and surfaceTint, it now uses surfaceContainer with fixed pre-computed color with a defined shade for the used surface role
Elevation is still 3, but surfaceTint is set to transparent so it has no effect
New Component Color Mappings
The new Material specification changed how all Material widgets use surface colors
Example�Navigation Bar
Instead of using surface impacted by elevation 3 and surfaceTint, it now uses surfaceContainer with fixed pre-computed color with a defined shade for the used surface role
Elevation is still 3, but surfaceTint is set to transparent so it has no effect
New Component Color Mappings
The new Material specification changed how all Material widgets use surface colors
The changes in the NavigationBar case are small and subtle, but in total this was an enormous change in Flutter 3.22, that impacted
Files changed 181 (for part 2 only !!)
Component Defaults?
Two related questions I here about Material:
Answer 1:
Check the Material 3 guide!
It tells you what it should be
Component Defaults?
Two related questions I here about Material:
Answer 2:
Check the Flutter component M3 defaults at the end of each component’s code file
It tells you what it actually is!
Typically the guide spec and Flutter code match
New Carousel Widget
New CarouselView Widget
https://main-api.flutter.dev/flutter/material/CarouselView-class.html
CarouselView
WidgetState
WidgetState
WidgetState replaces MaterialState
Kind of boring, but good to know
API moved from Material library to Widget Library. Rationale, allow Cupertino Widgets and custom libraries to use it the APIs without depending on Material
Flutter does not use new APIs internally yet, its code samples are still
Yes there is a Flutter fix
You are most likely to come across the new APIs when you maks themes or style buttons.
Other than WidgetState itself you will often use and come across:
WidgetStateColor
WidgetStateProperty
WidgetStatePropertyAll
Button builders
Button builders
Button builders
Button builders
Button builders
Button builders
https://api.flutter.dev/flutter/material/TextButton/styleFrom.html
Quality Improvements
Button Icon Alignment
https://api.flutter.dev/flutter/material/ButtonStyleButton/iconAlignment.html
Button Icon Alignment
https://api.flutter.dev/flutter/material/ButtonStyleButton/iconAlignment.html
Button Icon Alignment
https://api.flutter.dev/flutter/material/ButtonStyleButton/iconAlignment.html
Button Icon Alignment
https://api.flutter.dev/flutter/material/ButtonStyleButton/iconAlignment.html
Menu Item Button
Menu Item Button
Menu Item Button
Menu Item Button
Chip leading & trailing constraints
Chip leading & trailing constraints
Chip leading & trailing constraints
https://main-api.flutter.dev/flutter/material/Chip/avatarBoxConstraints.html
https://main-api.flutter.dev/flutter/material/Chip/deleteIconBoxConstraints.html
Chip leading & trailing constraints
https://main-api.flutter.dev/flutter/material/Chip/avatarBoxConstraints.html
https://main-api.flutter.dev/flutter/material/Chip/deleteIconBoxConstraints.html
SegmentedButton expanded insets
SegmentedButton expanded insets
SegmentedButton expanded insets
AppBar Shape Customization
AppBar Shape Customization
AppBar Shape Customization
Adaptive Theming
Platform Adaptive Theming
Material ThemeData can be platform aware
You can make an application where built-in and custom components look and behave differently depending on the platform your app is running on
We will take a look at an example of this and at the same time get a primer into advanced customization of Material widgets in Flutter using theming
A theme for a fictive Avocado Deli
Designer’s Color Tokens
Avocado
#334601
Avocado Ripe
#3F4925
Avocado Lush
#C4D39D
Avocado Prime
#FFFBD8
Avocado Meat
#FFF5AD
Avocado Tender
#E2EEBC
Avocado Core
#4C1C0A
Effect Light
#F2B9CC
Effect Dark
#3E0021
App colors that must be used in the design
Define ColorScheme Tokens
First step, define the same color tokens. We need to figure out how to get these into a light and dark ColorScheme
A theme for a fictive Avocado Deli
Designer’s Color Tokens
Received Light
#00257F
Received Dark
#C1CCFF
Preparing Light
#045E72
Preparing Dark
#DBF5FF
Delivery Light
#00513D
Delivery Dark
#BBFFE4
Delivered Light
#005305
Delivered Dark
#CFFFC1
Semantic order status colors
Define Semantic Color Tokens
We use some custom semantic colors for order status. We will use them via ThemeExtension and also harmonize the colors to our scheme’s primary color
Adaptive Theme Tokens
We also need some tokens to drive our custom adaptive theme response
Not many, first a bool for when we use it, plus a BorderRadius and OutlinedBorder Shape
We will use these in our component themes
Define ColorScheme
A ColorScheme with three key colors, pin token colors as appropriate in light and dark schemes. Use FlexTones.chroma as it follows the chroma of used key colors, we modify it to use monochrome surfaces on none Android platforms
ColorScheme Result
A ColorScheme with popping colors, we baked in our color tokens so that the scheme follows the Material color system
ColorScheme result on none Android platforms
ColorScheme Result
A ColorScheme with popping colors, we baked in our color tokens so that the scheme follows the Material color system
ColorScheme result on Android platform
ColorScheme Result
If we had not pinned our color design tokens, the result would have looked like this on the Android platform
Platform Adaptive Theming
We want a platform adaptive theme where components on Android are recognizable as being Material 3 design based, but on all other platforms we want a more platform agnostic design
Buttons a more iOS like radius, we use 10dp and also no ink splash on none Android platforms!
Android
Other platforms
Platform Adaptive Theming
We want a platform adaptive theme where components on Android are recognizable as being Material 3 design based, but on all other platforms we want a more platform agnostic design
ToggleButtons match Outlined and Filled buttons SegmentedButton matches FilledTonal
Android
Other platforms
Platform Adaptive Theming
We want a platform adaptive theme where components on Android are recognizable as being Material 3 design based, but on all other platforms we want a more platform agnostic design
Chips default rounded corners on Android and Stadium on other platforms. They need to use a design that makes them look different from buttons on respective platforms. We also want smaller Chips, the defaults are too bulky, almost button sized
Android
Other platforms
Platform Adaptive Theming
We want a platform adaptive theme where components on Android are recognizable as being Material 3 design based, but on all other platforms we want a more platform agnostic design
Switch default Material style on Android, themed to be iOS like on other platforms
Android
Other platforms
Other Advanced Theming
Adaptive Theme Demo
Adaptive Theming and Other Tricks
Basic Setup
Only three ThemeSettings properties in a data class�A single function that returns our app’s ThemeData�No controversial state management package, just setState :)�
Adaptive Theming and Other Tricks
Define ThemeData
Define our ThemeData based on brightness and theme settings�Get our custom platform adaptive ColorScheme�Use customized platform adaptive visual density
Adaptive Theming and Other Tricks
Define ThemeData
Use Material-3, really don’t use Material-2 anymore!�Apply our platform adaptive ColorScheme and VisualDensity�Use a custom splash factory “InstantSplash” for none Android builds
Copy of built-in InkSplash.splashFactory with modified animation durations and splash velocity. There is a built-in NoSplash.splashFactory, it can also be used. It animates the tap highlight, this custom one is instant. Used as an example, you may prefer the NoSplash.splashFactory for a similar effect
By the way ThemeData uses adaptive splash by default too, it does this:
Adaptive Theming and Other Tricks
ThemeData Legacy Props
Prefer the Material-3 Typography, even if you still use M2.�Fix legacy colors in ThemeData, eventually these will be deprecated, but as long as they exist, set them to our ColorScheme colors
Coming ThemeData color deprecations https://github.com/flutter/flutter/issues/91772
Adaptive Theming and Other Tricks
AppBar
A “secret” sauce is a shape to get the scroll under effect to animate. Shadow is used for a faint underline separation. Background also has a hint of opacity and we use a custom font
Adaptive Theming and Other Tricks
Buttons
Platform adaptive shape on all Material buttons�Custom color mapping on Elevated button�Ink splashes only on Android
Adaptive Theming and Other Tricks
Toggle and Segmented Buttons
We can style Toggle and Segmented buttons differently for different use cases. Toggle Buttons theming it is a bit tricky. We want it to match the style of our Outlined and Filled buttons
Adaptive Theming and Other Tricks
Chip and Switch
We want Chips to be smaller and not the same shape as buttons
For the Switch we want iOS look alike on none Android platforms
Adaptive Theming and Other Tricks
NavigationBar
Don’t be afraid to tweak the Material Navigation bar, you can for example make it less tall and use a more distinct selected option color than the default one
Adaptive Theming and Other Tricks
Android System Navigation Bar
And please make the Android system navigation look nice, like iOS. Make it edge-to-edge and transparent. Use the AnnotatedRegion to style it with a custom SystemUiOverlayStyle
Adaptive Theming and Other Tricks
Input Decoration
Making a nice custom InputDecoration theme is tedious and complex. You also need to use it in some component themes that can accept an input decoration, like eg DropdownMenu
Adaptive Theming and Other Tricks
Dialogs
Not much done to Dialogs, some minor custom color mapping and bringing back shadows to them. The surface colors on Android have minor primary chroma in them, other platforms are monochrome
Adaptive Theming and Other Tricks
Text Theme
With GoogleFonts define styles for each TextStyle in a TextTheme using google fonts text styles or use GoogleFonts.nnnTextTheme
Adaptive Theming and Other Tricks
Text Theme
Since GoogleFonts TextTheme has a color issue, prefer using individual GoogleFonts styles or work around the issue��Note: Typically you have same styles on primaryTextTheme, different styles used to show the issue
Adaptive Theming and Other Tricks
Theme Extension
As the last piece we will use ThemeExtension as a means to add custom theme properties. We define one theme extension for all our semantic colors and our two “semantic” content text styles
Adaptive Theming and Other Tricks
Theme Extension
Defining a ThemeExtension has some boilerplate, we need to define our properties, extend ThemeExtension having a type of the class we define, plus we must override its copyWith and lerp methods
Adaptive Theming and Other Tricks
Harmonize Colors
In schemes, you can automatically adjust the hue of static colors so they look better alongside the scheme’s primary color. This especially useful if you have many themes or if it is dynamic
Material 3 guide https://m3.material.io/styles/color/advanced/adjust-existing-colors#1cc12e43-237b-45b9-8fe0-9a3549c1f61e
Adaptive Theming and Other Tricks
Theme Extension using Order Status Widget
Just the�token value��Theme extension and harmonized
Adaptive Theming and Other Tricks
Theme Extension TextStyles
Adaptive Theme Result
That was a lot, and we learned that
Theming Rocks!
Animations
Material Easings
Material Easings
Material Easings
Easings.emphasizedDecelerate
Easings.standardDecelerate
Material Durations
Material Durations
Material Durations
AnimationStyle
AnimationStyle
What We Learned
The updated ColorScheme is complex, but nice with static and more surface shades. Scheme generation is flexible, with the right package
The new Carousel widget is lovely
Migrate to WidgetState
Use button builders to take your Material Buttons to the next level
Components continuously improve, also in subtle ways, as we saw with Button icons alignment, Chip constraints and AppBar shape customization.
Material theming in Flutter is deep and full of powerful capabilities
Animations are not only fun to play with, they lift the user experience to new levels
Thank you!
Questions?
Everything Material
All At Once
Package Author
Mike Rydstrom�@RydMike
Flutter Contributor
Taha Tesser
@TahaTesser