
# spring_boot_starter_flutter_material

`spring_boot_starter_flutter_material` adds Material Design to a Flutter app built on [spring_boot_starter_flutter](../spring-boot-starter-flutter/index.md). The Flutter starter knows no design library: since Flutter 3.50, Material is not part of the SDK but the Flutter team's package `material_ui`. This starter is the bridge between the two. With it, the app is a `MaterialApp` (`spring.flutter.app.type: material`, which need not be set when this is the one design starter), and every theme of `spring.flutter.theme.*` becomes Material's `ThemeData`.

## Why

An app of type `widgets` has its themes, its palette and its text styles without Material in the build (see [Design libraries](../spring-boot-starter-flutter/design-libraries.md)). An app that uses `Scaffold`, `AppBar`, `FilledButton` and the other Material widgets needs more, and that is what this starter brings:

- **A `MaterialApp` from properties.** The type `material`, deduced from this starter or set with `spring.flutter.app.type`, with the title, locales and themes of the configuration.
- **Material's `ThemeData` from `spring.flutter.theme.*`.** Colors, typography, shapes, and about fifty component themes under `components.*` (`card`, `app-bar`, `filled-button`, `input`, ...), each by Flutter's own property names.
- **Palettes from a seed color.** `seed-color`, `scheme-variant` and `contrast` make a Material 3 palette (`ColorScheme.fromSeed`).
- **Themes in code where properties end.** `ThemeCustomizer` beans change every `ThemeData`; a `ThemeData` bean named `theme` or `darkTheme` replaces the made one.
- **Material for the other starters.** Material's page route for the router of the navigation starter, Material's text field and button for the login form of the security starter, Material's text styles and selection in `MarkdownView`.

## Setup

```yaml
# pubspec.yaml
environment:
  sdk: ^3.14.0
  flutter: '>=3.50.0'

dependencies:
  flutter:
    sdk: flutter
  material_ui: ^1.11.0                                  # the Material widgets
  spring_boot_starter_flutter_material: ^0.9.0

dev_dependencies:
  build_runner: ^2.17.0
  spring_core_dart_generator: ^0.9.0
```

The starter brings and re-exports `spring_boot_starter_flutter`, so an app lists this package instead of the Flutter starter. It does not re-export `material_ui`: the app lists it for the widgets it uses, and imports both:

```dart
import 'package:material_ui/material_ui.dart';
import 'package:spring_boot_starter_flutter_material/spring_boot_starter_flutter_material.dart';
```

It needs Flutter 3.50 or later (Dart 3.14). After adding it, run `dart run build_runner build` once: the generator finds the starter, adds its beans and its design to `lib/spring_gen/main.spring.dart`.

## Example

```yaml
# lib/resources/application.yml
spring:
  flutter:
    app:
      title: Counter
    theme:
      seed-color: deepPurple
      components:
        card: { elevation: level2, shape: large }
```

```dart
// lib/main.dart
import 'package:material_ui/material_ui.dart';
import 'package:spring_boot_starter_flutter_material/spring_boot_starter_flutter_material.dart';

import 'spring_gen/main.spring.dart';

@SpringBootApplication()
void main() => runApp(
  SpringApplicationWidget(
    application: () => springApplication,
    home: const CounterPage(), // inside a MaterialApp
  ),
);

@ChangeNotifierComponent()
class Counter {
  int value = 0;
  void increment() => value++;
}

class CounterPage extends SpringStatelessWidget<(Counter,)> {
  const CounterPage({super.key});

  @override
  Widget build(BuildContext context) {
    final (counter,) = beans;
    return Scaffold(
      body: Center(child: Text('${counter.value}')),
      floatingActionButton: FloatingActionButton(
        onPressed: counter.increment,
        child: const Icon(Icons.add),
      ),
    );
  }
}
```

No `spring.flutter.app.type` in the example: as Spring Boot deduces `spring.main.web-application-type` from the class path, the application's starters decide, and with this starter as the one design starter the app is of type `material`. The property is for choosing. An app with both design starters sets it, for every platform and per platform in a profile; without it the start fails, naming the property and the types (see [Material on Android, Cupertino on iOS](app-widget.md#material-on-android-cupertino-on-ios)). `widgets` keeps a `WidgetsApp` although this starter is in the build. Set, it always wins.

Without this starter in the dependencies, `spring.flutter.app.type: material` fails the start, and the message names the package to add: "the app widget of type material is built by spring_boot_starter_flutter_material: add it to the dependencies".

## What is inside

- [The app widget](app-widget.md): the `MaterialApp` of `spring.flutter.app.type: material`, and a `MaterialApp` of your own.
- [Themes from properties](themes.md): how each theme of `spring.flutter.theme.*` becomes Material's `ThemeData`, what comes from the Flutter starter and what this starter adds, light, dark and system, themes loaded at run time.
- [The palette from a seed](palette.md): `seed-color`, the nine scheme variants, `contrast`, roles by hand over the seed.
- [Density and ink](density-and-ink.md): `visual-density`, `tap-target-size` and the ink `splash`.
- [Component themes](components/index.md): how `components.*` is written, and a page for each of the 49 components with every property.
- [Themes in code](themes-in-code.md): `ThemeCustomizer`, replacing theme beans, the order, the `MaterialThemes` bean, tests.
- [With the other starters](other-starters.md): page routes for the navigation starter, the controls of the login form, `MarkdownView`.

What every design shares (colors, typography, shapes, tokens, styles, motion, backgrounds, loaders) is documented with the Flutter starter: [Themes](../spring-boot-starter-flutter/themes/index.md).

## In Spring (Java)

Spring has no themes for apps and no counterpart of this starter. What follows Spring is the shape: a starter that adds a feature by being in the dependencies, an auto-configuration with its beans, customizer beans (as `WebServerFactoryCustomizer` customizes a web server), and a factory found before any bean exists, as Spring Boot finds the entries of `META-INF/spring.factories`.

## See also

- [spring_boot_starter_flutter](../spring-boot-starter-flutter/index.md)
- [Design libraries](../spring-boot-starter-flutter/design-libraries.md)
- [Moving to 0.8](../spring-boot-starter-flutter/moving-to-0-8.md)
- [spring_boot_starter_flutter_cupertino](../spring-boot-starter-flutter-cupertino/index.md)
- [Themes from properties](themes.md)
- [Component themes](components/index.md)
- [What a build contains](optimizations.md)
