1. Introduction
What you'll build
Material 3 is Google's open-source design system for building expressive, adaptive user interfaces. In this codelab, you start with an empty Flutter application and collaborate with Google Antigravity to build a fully styled and animated messaging application powered by the material_ui package.
Your finished application meets the following requirements:
- Uses adaptive design to adjust seamlessly between mobile, tablet, and desktop screen sizes.
- Choreographs staggered animations to fluidly transition between a bottom
NavigationBar, a sideNavigationRail, and a two-pane list-detail view. - Applies Material 3 color schemes, surface tinting, and typography using
package:material_ui/material_ui.dart. - Runs on Android, iOS, the web, Windows, Linux, and macOS.

Your learning journey
This codelab takes you through building the adaptive messaging app step by step:
- Set up your Flutter environment - Configure the Flutter SDK and Google Antigravity for your target platform.
- Getting started - Prompt Antigravity to scaffold an empty Flutter project with the
material_uipackage. - Make a messenger app - Add user avatars, message models, and Material 3 inbox widgets (
EmailListView,EmailWidget,SearchBar, andStarButton). - Add a
NavigationBar- Define top-level destinations and wire up a bottomNavigationBarfor narrow screens. - Add a
NavigationRail- Switch between a bottomNavigationBarand a left-handNavigationRailwhen the window width exceeds600pixels. - Animate the transitions - Choreograph staggered
CurvedAnimationintervals and transition widgets so the bar, rail, and FAB morph smoothly on resize. - Add a list with detail view - Expand into a two-pane inbox and threaded reply layout on wide screens using
ListDetailTransition.
What you'll learn
- How to collaborate with Google Antigravity to iteratively build and customize an adaptive Material 3 Flutter application.
- How to style widgets using Material 3
ColorSchemeroles,Color.alphaBlendsurface tints, andTextThemewithpackage:material_ui/material_ui.dart. - How to build responsive layouts using both widget-level constraints (
LayoutBuilder) and screen-level metrics (MediaQuery). - How to coordinate multi-part explicit animations using
AnimationController,CurvedAnimation,Interval, andTweenSequence.
Prerequisites
- Basic familiarity with Flutter and Dart syntax.
2. Set up your Flutter environment
Editor
This codelab uses Google Antigravity as your AI-first development environment. In each step, you prompt Antigravity to generate or evolve your app's components, review the key Flutter and Material 3 concepts in the generated code, and optionally explore design variations.
Install Flutter
The most up-to-date instructions on installing the Flutter SDK are always on docs.flutter.dev.
For this codelab, install the following software:
- Flutter SDK
- Google Antigravity with the official Dart and Flutter plugin enabled (available in the Plugin Marketplace under the Build with Google section).
- Compiler software for your chosen development target (for example, Visual Studio to target Windows, Xcode to target macOS or iOS, or Chrome to target the web).
To verify that your environment is set up for your chosen deployment target, run flutter doctor:
flutter doctor
If there are issues listed in the output that impact your chosen deployment target, run flutter doctor -v for detailed troubleshooting steps, or reach out to the Flutter community.
3. Getting started
Prompt Antigravity to create the project
Most Flutter developers create a basic counter app with flutter create and then spend a couple of minutes removing boilerplate they don't need. Passing the --empty flag creates a minimal Flutter project with just the bare essentials, which you can then pair with the material_ui package.
- Launch Google Antigravity and open an empty directory where you'd like to build your project (choose a path that doesn't require elevated privileges or contain spaces, such as a folder in your home directory or
C:\src\). - In the Antigravity agent chat panel, send the following prompt to create the Flutter project, add
material_ui, and wire up the initial app:
Create a new empty Flutter project named `animated_responsive_layout` for a Material 3 adaptive messaging app. Add the `material_ui` package, and update `lib/main.dart` to import `package:material_ui/material_ui.dart` and run the initial `MainApp` widget.
Understanding the generated code
Antigravity runs flutter create animated_responsive_layout --empty, adds material_ui to pubspec.yaml, and updates lib/main.dart to import package:material_ui/material_ui.dart:
import 'package:material_ui/material_ui.dart';
void main() {
runApp(const MainApp());
}
Run and test the app
Run the application on your chosen target device (such as Chrome or desktop) to verify that the empty scaffold builds and launches cleanly:

4. Make a messenger app
Avatar assets and inbox widgets
Every messaging application needs user avatars and sample conversations. In this step, Antigravity downloads eight image assets (avatar_1.png through avatar_7.png and thumbnail_1.png) into an assets/ folder at the root of your project:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Along with registering those assets in pubspec.yaml, you'll prompt Antigravity to create the data models (lib/models/models.dart and lib/models/data.dart) and four Material 3 UI widgets under lib/widgets/:
search_bar.dart: A pill-shaped search input displaying the active user's avatar.star_button.dart: A favorite button that spins withAnimatedRotationwhen toggled.email_widget.dart: A versatile card that renders email previews, full threaded messages (EmailContent), thread headers (EmailHeadline), and action buttons (EmailReplyOptions).email_list_view.dart: A scrollable list combining the search bar and email cards.
Prompt Antigravity to build the inbox UI
Send the following prompt in Antigravity:
Download `avatar_1.png` through `avatar_7.png` and `thumbnail_1.png` from `https://github.com/flutter/codelabs/tree/main/animated-responsive-layout/step_04/assets` (using raw URLs like `https://raw.githubusercontent.com/flutter/codelabs/main/animated-responsive-layout/step_04/assets/avatar_1.png`) into `assets/` and register them under `flutter: assets:` in `pubspec.yaml`. Create the messaging data models (`Attachment`, `Email`, `Name`, and `User`) in `lib/models/models.dart` and populate sample users (`user_0` through `user_4`), `emails`, and `replies` in `lib/models/data.dart`. Then create the Material 3 messaging widgets using `package:material_ui/material_ui.dart`: a rounded `SearchBar` (`lib/widgets/search_bar.dart`), a toggleable `StarButton` using `AnimatedRotation` (`lib/widgets/star_button.dart`), an `EmailWidget` (`lib/widgets/email_widget.dart`) with `EmailContent`, `EmailHeadline`, and `EmailReplyOptions` that adapt to `LayoutBuilder` constraints and selection state, and an `EmailListView` (`lib/widgets/email_list_view.dart`, importing `search_bar.dart as search_bar`). Finally, update `lib/main.dart` to display `Feed(currentUser: data.user_0)` with a surface-tinted background and a tertiary-colored `FloatingActionButton`.
Understanding the generated code
Surface tinting and Dart 3 switch expressions in EmailWidget
In lib/widgets/email_widget.dart, _EmailWidgetState derives its card colors from the ambient Theme.of(context).colorScheme. Rather than hardcoding hex colors, it blends a subtle tint of _colorScheme.primary over _colorScheme.surface and uses a Dart 3 object pattern switch expression to pick the right surface color for threaded views, selected previews, and unselected previews:
late final ColorScheme _colorScheme = Theme.of(context).colorScheme;
late Color unselectedColor = Color.alphaBlend(
_colorScheme.primary.withAlpha(20),
_colorScheme.surface,
);
Color get _surfaceColor => switch (widget) {
EmailWidget(isPreview: false) => _colorScheme.surface,
EmailWidget(isSelected: true) => _colorScheme.primaryContainer,
_ => unselectedColor,
};
Similarly, EmailContent formats the sender's relative lastActiveLabel using relational patterns over Duration getters (inSeconds: < 60, inMinutes: < 60, inHours: < 24, and inDays: < 365).
Widget-level responsiveness with LayoutBuilder
Even before you add screen-level navigation breakpoints, EmailContent, EmailHeadline, and EmailReplyOptions use LayoutBuilder to prevent layout overflows when an individual card becomes narrow (such as during a split-screen transition):
LayoutBuilder(
builder: (context, constraints) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (constraints.maxWidth - 200 > 0) ...[
CircleAvatar(
backgroundImage: AssetImage(
widget.email.sender.avatarUrl,
),
),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 6.0),
),
],
// Sender name and last active timestamp...
if (constraints.maxWidth - 200 > 0) ...[const StarButton()],
],
);
},
),
When constraints.maxWidth drops to 200 pixels or less, the avatar and star button automatically hide so the sender's name and timestamp never overflow.
Implicit rotation in StarButton and import aliasing
In lib/widgets/star_button.dart, toggling a starred message updates state and smoothly spins the icon using Flutter's implicit AnimatedRotation widget:
@override
Widget build(BuildContext context) {
return AnimatedRotation(
turns: turns,
curve: Curves.decelerate,
duration: const Duration(milliseconds: 300),
child: FloatingActionButton(
elevation: 0,
shape: const CircleBorder(),
backgroundColor: _colorScheme.surface,
onPressed: () => _toggle(),
child: Padding(padding: const EdgeInsets.all(10.0), child: icon),
),
);
}
Run and test the app
Perform a hot restart (or stop and re-run the app so Flutter bundles the new assets/ entries from pubspec.yaml). You should see the styled inbox list and search bar:

5. Add a NavigationBar
At the end of the previous step, the app displays a list of messages, but has no top-level navigation. In this step, you define four app destinations (Inbox, Articles, Messages, and Groups) and add a Material 3 NavigationBar along the bottom of the Scaffold.
Prompt Antigravity to add a bottom NavigationBar
Send the following prompt in Antigravity:
Create `lib/destinations.dart` using `package:material_ui/material_ui.dart` with a `Destination(this.icon, this.label)` class and four `destinations`: Inbox (`Icons.inbox_rounded`), Articles (`Icons.article_outlined`), Messages (`Icons.messenger_outline_rounded`), and Groups (`Icons.group_outlined`). In `lib/main.dart`, add `int selectedIndex = 0` to `_FeedState`, wire `selectedIndex` and `onSelected` into `EmailListView`, and add a Material 3 `NavigationBar` as the `Scaffold.bottomNavigationBar` mapped from `destinations`.
Understanding the generated code
Modeling navigation destinations
Separating navigation metadata into lib/destinations.dart keeps your data independent of the specific navigation widget rendering it—which becomes essential in the next step when both a bottom NavigationBar and a side NavigationRail share the same list:
class Destination {
const Destination(this.icon, this.label);
final IconData icon;
final String label;
}
const List<Destination> destinations = <Destination>[
Destination(Icons.inbox_rounded, 'Inbox'),
Destination(Icons.article_outlined, 'Articles'),
Destination(Icons.messenger_outline_rounded, 'Messages'),
Destination(Icons.group_outlined, 'Groups'),
];
Wiring NavigationBar in lib/main.dart
In _FeedState.build, destinations maps directly to NavigationDestination widgets inside Scaffold.bottomNavigationBar, sharing selectedIndex with EmailListView:
bottomNavigationBar: NavigationBar(
elevation: 0,
backgroundColor: Colors.white,
destinations: destinations.map<NavigationDestination>((d) {
return NavigationDestination(icon: Icon(d.icon), label: d.label);
}).toList(),
selectedIndex: selectedIndex,
onDestinationSelected: (index) {
setState(() {
selectedIndex = index;
});
},
),
Selecting a destination in the NavigationBar highlights the corresponding card in EmailListView, and tapping an email card updates the active destination in the NavigationBar.
Run and test the app
Hot reload the application and tap the items in the bottom NavigationBar or the email list to verify that selection stays synchronized:

This layout works well on a narrow portrait screen, but if you widen the window or rotate a mobile simulator to landscape, stretching a bottom bar across a wide display wastes horizontal space. In the next step, you'll introduce a NavigationRail on the left side when the screen is wide enough.
6. Add a NavigationRail
To adapt the navigation layout to the current screen width, you'll refactor the bottom bar into DisappearingBottomNavigationBar, create a DisappearingNavigationRail for wide screens, and switch between them at a 600 pixel width breakpoint.
Prompt Antigravity to add a responsive NavigationRail
Send the following prompt in Antigravity:
Refactor the bottom `NavigationBar` into a `DisappearingBottomNavigationBar` widget (`lib/widgets/disappearing_bottom_navigation_bar.dart`), and create a `DisappearingNavigationRail` widget (`lib/widgets/disappearing_navigation_rail.dart`) using `NavigationRail` with a leading menu `IconButton`, a rounded-rectangle compose `FloatingActionButton`, `groupAlignment: -0.85`, and `destinations`. In `lib/main.dart`, track `bool wideScreen = width > 600` in `didChangeDependencies()` using `MediaQuery.of(context).size.width`, show `DisappearingNavigationRail` in a `Row` alongside the expanded `EmailListView` when `wideScreen` is true, and hide the `Scaffold`'s `floatingActionButton` and `bottomNavigationBar` on wide screens.
Understanding the generated code
Building DisappearingNavigationRail
In lib/widgets/disappearing_navigation_rail.dart, NavigationRail renders the same destinations list vertically and tucks the menu button and compose FloatingActionButton into its leading slot:
return NavigationRail(
selectedIndex: selectedIndex,
backgroundColor: backgroundColor,
onDestinationSelected: onDestinationSelected,
leading: Column(
children: [
IconButton(onPressed: () {}, icon: const Icon(Icons.menu)),
const SizedBox(height: 8),
FloatingActionButton(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15)),
),
backgroundColor: colorScheme.tertiaryContainer,
foregroundColor: colorScheme.onTertiaryContainer,
onPressed: () {},
child: const Icon(Icons.add),
),
],
),
groupAlignment: -0.85,
destinations: destinations.map((d) {
return NavigationRailDestination(
icon: Icon(d.icon),
label: Text(d.label),
);
}).toList(),
);
Detecting screen width in didChangeDependencies
In lib/main.dart, _FeedState overrides didChangeDependencies() to query MediaQuery.of(context).size.width whenever the window size or device orientation changes:
bool wideScreen = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
final double width = MediaQuery.of(context).size.width;
wideScreen = width > 600;
}
When wideScreen is true, the Scaffold inserts DisappearingNavigationRail as the first child of the body's Row and sets both floatingActionButton and bottomNavigationBar to null.
Run and test the app
Hot reload the app and resize the window across the 600 pixel threshold to compare the narrow and wide layouts:
|
|
Switching between two distinct layouts works, but the instant jump between the bar and the rail feels abrupt. In the next step, you'll choreograph smooth animations between the two layouts.
7. Animate the transitions
Creating a polished adaptive transition involves choreographing multiple animations along a shared timeline. Instead of immediately swapping widgets with if (wideScreen), you drive an AnimationController forward when the screen widens past 600 pixels and in reverse when it narrows, slicing its 0.0 to 1.0 timeline into staggered Interval curves.
Prompt Antigravity to animate the layout transitions
Send the following prompt in Antigravity:
Create `lib/animations.dart` defining staggered `CurvedAnimation` and `ReverseAnimation` classes (`BarAnimation`, `OffsetAnimation`, `RailAnimation`, `RailFabAnimation`, `ScaleAnimation`, `ShapeAnimation`, and `SizeAnimation`) using `Interval`s and `Curves.easeInOutCubicEmphasized`. Create `BottomBarTransition` (`lib/transitions/bottom_bar_transition.dart`) and `NavRailTransition` (`lib/transitions/nav_rail_transition.dart`) that combine `ClipRect`, `Align` (`heightFactor` and `widthFactor`), and `FractionalTranslation` to slide and size the navigation widgets, plus an `AnimatedFloatingActionButton` (`lib/widgets/animated_floating_action_button.dart`) that animates scale and border radius (`lerpDouble(30, 15, ...)`). Update `DisappearingBottomNavigationBar` and `DisappearingNavigationRail` to wrap their widgets in these transitions, and update `_FeedState` in `lib/main.dart` with `SingleTickerProviderStateMixin`, an `AnimationController` driven in `didChangeDependencies()` when `width > 600`, and an `AnimatedBuilder` wrapping the `Scaffold`.
Understanding the generated code
Staggered intervals in lib/animations.dart
Each animation class in lib/animations.dart wraps the parent AnimationController in a CurvedAnimation (or ReverseAnimation for the bottom bar, which hides as the controller advances toward 1.0) with distinct forward and reverse Interval windows:
class BarAnimation extends ReverseAnimation {
BarAnimation({required AnimationController parent})
: super(
CurvedAnimation(
parent: parent,
curve: const Interval(0, 1 / 5),
reverseCurve: const Interval(1 / 5, 4 / 5),
),
);
}
class OffsetAnimation extends CurvedAnimation {
OffsetAnimation({required super.parent})
: super(
curve: const Interval(
2 / 5,
3 / 5,
curve: Curves.easeInOutCubicEmphasized,
),
reverseCurve: Interval(
4 / 5,
1,
curve: Curves.easeInOutCubicEmphasized.flipped,
),
);
}
Using Curves.easeInOutCubicEmphasized (and its .flipped counterpart when reversing) applies Material 3's signature expressive easing curve.
Sliding and sizing in BottomBarTransition and NavRailTransition
In lib/transitions/nav_rail_transition.dart, NavRailTransition combines two child animations derived from widget.animation—widthAnimation (driven by SizeAnimation) and offsetAnimation (driven by OffsetAnimation, respecting text Directionality):
child: AnimatedBuilder(
animation: widthAnimation,
builder: (context, child) {
return Align(
alignment: Alignment.topLeft,
widthFactor: widthAnimation.value,
child: FractionalTranslation(
translation: offsetAnimation.value,
child: widget.child,
),
);
},
),
Animating Align.widthFactor (and heightFactor in BottomBarTransition) smoothly expands or collapses the space the widget occupies in the layout, while FractionalTranslation slides the widget in from the edge clipped by ClipRect.
Driving the AnimationController in lib/main.dart
In _FeedState, didChangeDependencies() checks the current window width and runs _controller.forward() when widening past 600 pixels or _controller.reverse() when narrowing:
final double width = MediaQuery.of(context).size.width;
final AnimationStatus status = _controller.status;
if (width > 600) {
if (status != AnimationStatus.forward &&
status != AnimationStatus.completed) {
_controller.forward();
}
} else {
if (status != AnimationStatus.reverse &&
status != AnimationStatus.dismissed) {
_controller.reverse();
}
}
if (!controllerInitialized) {
controllerInitialized = true;
_controller.value = width > 600 ? 1 : 0;
}
Setting _controller.value directly on the initial build (!controllerInitialized) ensures the app launches immediately in the appropriate layout without playing an entry transition on startup.
Run and test the app
Resize the application window back and forth across the 600 pixel width threshold. The bottom NavigationBar, NavigationRail, and compose FloatingActionButton now animate fluidly between mobile and desktop modes.
8. Add a list with detail view
A messaging app is a natural fit for a two-pane list-detail layout when the display is wide enough. In this final step, you add a ReplyListView widget to display the selected email thread and a ListDetailTransition widget that animates the detail pane into view alongside EmailListView and scales its flex allocation as the window widens.
Prompt Antigravity to add the list-detail view
Send the following prompt in Antigravity:
Create a `ReplyListView` widget (`lib/widgets/reply_list_view.dart`) using `package:material_ui/material_ui.dart` that renders `data.replies` as threaded `EmailWidget` cards (`isPreview: false`, `isThreaded: true`, and `showHeadline: index == 0`). Then create a `ListDetailTransition` widget (`lib/transitions/list_detail_transition.dart`) that animates a second `Flexible` detail pane into a `Row` alongside `widget.one` using `SizeAnimation`, `OffsetAnimation`, `TweenSequence`, and a width-responsive flex factor (`lerpDouble` across `800`, `1200`, and `1600` px breakpoints). Finally, wrap `EmailListView` and `const ReplyListView()` in `ListDetailTransition(animation: _railAnimation, ...)` inside `lib/main.dart`.
Understanding the generated code
Proportional width allocation in ListDetailTransition
In lib/transitions/list_detail_transition.dart, didChangeDependencies() calculates nextFlexFactor relative to widget.one's fixed flex: 1000 allocation using a Dart 3 relational pattern switch expression:
final double width = MediaQuery.of(context).size.width;
double nextFlexFactor = switch (width) {
>= 800 && < 1200 => lerpDouble(1000, 2000, (width - 800) / 400)!,
>= 1200 && < 1600 => lerpDouble(2000, 3000, (width - 1200) / 400)!,
>= 1600 => 3000,
_ => 1000,
};
- When the window width is under
800pixels,nextFlexFactoris1000, giving the inbox list (widget.one) and reply pane (widget.two) each1/2of the available space. - Between
800and1200pixels, the ratio smoothly interpolates to1/3for the inbox list and2/3for the detail view. - At
1600pixels and wider, the detail pane receives3/4(3000versus1000) of the available width.
When widthAnimation.value.toInt() == 0 (on narrow screens), ListDetailTransition returns widget.one alone so the hidden detail pane uses zero layout resources:
@override
Widget build(BuildContext context) {
return widthAnimation.value.toInt() == 0
? widget.one
: Row(
children: [
Flexible(flex: 1000, child: widget.one),
Flexible(
flex: widthAnimation.value.toInt(),
child: FractionalTranslation(
translation: offsetAnimation.value,
child: widget.two,
),
),
],
);
}
Run and test the app
Hot reload (or hot restart) the application and widen the window to see the navigation rail, inbox list, and threaded detail view working together:

9. Congratulations
Congratulations! You've built an animated, responsive Material 3 messaging app with Flutter, the material_ui package, and Google Antigravity.
What you've built
- A Material 3 messaging interface (
EmailListView,EmailWidget,SearchBar, andStarButton) styled withpackage:material_ui/material_ui.dart,ColorSchemesurface tinting, andLayoutBuilderconstraints. - Adaptive navigation that switches between a bottom
NavigationBaron narrow screens and a sideNavigationRailon wider displays. - Choreographed layout transitions (
BottomBarTransition,NavRailTransition, andAnimatedFloatingActionButton) driven by staggeredCurvedAnimationintervals and Material 3 emphasized easing curves. - A responsive two-pane list-detail layout (
ListDetailTransitionandReplyListView) that smoothly animates the detail pane into view and scales its flex ratio across desktop breakpoints.
Where to go from here
Continue prompting Antigravity to expand your messaging app:
- Dark mode support: Ask Antigravity to add a
darkTheme: ThemeData.dark()configuration and a theme mode toggle button in theNavigationRailleading slot. - Mobile detail navigation: On narrow screens (
width <= 600), ask Antigravity to pushReplyListViewonto theNavigatorstack when a user taps an email preview card. - Search filtering: Connect
SearchBar'sTextFieldto filter the displayedemailslist by sender name, subject, or message body in real time.
What's next?
Check out some of these related codelabs:









