spring_boot_starter_flutter_material

spring_boot_starter_flutter_material adds Material Design to a Flutter app built on spring_boot_starter_flutter. 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). An app that uses Scaffold, AppBar, FilledButton and the other Material widgets needs more, and that is what this starter brings:

Setup

# 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:

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

# lib/resources/application.yml
spring:
  flutter:
    app:
      title: Counter
    theme:
      seed-color: deepPurple
      components:
        card: { elevation: level2, shape: large }
// 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). 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

What every design shares (colors, typography, shapes, tokens, styles, motion, backgrounds, loaders) is documented with the Flutter starter: Themes.

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