Sub topic 1
What Material 3 Means in Flutter
Prerequisites
This chapter assumes that you can write basic Dart with null safety, build Flutter widget trees, and use MaterialApp, Scaffold, and BuildContext. You should also understand that ThemeData stores visual settings for an application.
Material 3 in Flutter
Material 3, also called M3, is Google’s design system for modern Android and Flutter interfaces. It defines how common controls look and behave, including buttons, app bars, navigation bars, dialogs, cards, and text.
Flutter implements Material 3 through the material.dart library. The main switch is ThemeData.useMaterial3. When this value is true, Material widgets use their Material 3 defaults instead of their Material 2 defaults.
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: Colors.indigo,
),
),
home: const Scaffold(
body: Center(
child: FilledButton(
onPressed: null,
child: Text('Continue'),
),
),
),
),
);
}The example explicitly enables Material 3 and supplies a ColorScheme. Setting these values in one application theme keeps the visual system consistent across screens.
What changes with Material 3
Material 3 changes more than colors. It updates component shapes, spacing, typography defaults, elevation behavior, and the names of some components.
For example, Material 3 commonly uses FilledButton for a prominent action. Material 2 code often used RaisedButton or a standard ElevatedButton for the same purpose. Material 3 also introduces components such as NavigationBar, FilledButton.tonal, and SegmentedButton.
| Area | Material 2 style | Material 3 style |
|---|---|---|
| Prominent action | Raised button or elevated button | Filled button |
| Bottom navigation | `BottomNavigationBar` | `NavigationBar` |
| Main color input | Individual color properties | Semantic `ColorScheme` roles |
| Component shape | Older rounded defaults | Updated shape and corner defaults |
Material 3 encourages semantic values. A semantic value describes a purpose, such as primary or surface, rather than a specific color such as purple. This lets the same widget work in light mode, dark mode, and different brand palettes.
How Flutter applies the theme
MaterialApp places a theme above the application’s widget tree. Material widgets below it read that theme and use its values. The theme does not force every widget to look identical. Individual widgets can still override selected properties, but application-wide defaults come from ThemeData.
The relationship looks like this:
Use Material 3 as the foundation, then customize the theme for your product. Avoid styling every button separately. Per-widget styling makes later changes harder and can produce inconsistent states.
Choosing Material 3 deliberately
New applications should usually set useMaterial3: true explicitly. This documents the intended design system and avoids relying on a framework default that may change between Flutter releases.
When migrating an existing application, inspect each screen rather than assuming that every component will look unchanged. M3 can alter padding, shape, color, and text contrast. Check disabled, focused, hovered, pressed, and dark-mode states on every important control.
Exercise
Why should an application set useMaterial3 explicitly instead of relying only on Flutter's default?
Show answer
Explicitly setting it documents the design choice and makes the application's behavior clear across Flutter versions.