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:
- A
MaterialAppfrom properties. The typematerial, deduced from this starter or set withspring.flutter.app.type, with the title, locales and themes of the configuration. - Material's
ThemeDatafromspring.flutter.theme.*. Colors, typography, shapes, and about fifty component themes undercomponents.*(card,app-bar,filled-button,input, ...), each by Flutter's own property names. - Palettes from a seed color.
seed-color,scheme-variantandcontrastmake a Material 3 palette (ColorScheme.fromSeed). - Themes in code where properties end.
ThemeCustomizerbeans change everyThemeData; aThemeDatabean namedthemeordarkThemereplaces 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
# 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
- The app widget: the
MaterialAppofspring.flutter.app.type: material, and aMaterialAppof your own. - Themes from properties: how each theme of
spring.flutter.theme.*becomes Material'sThemeData, 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:
seed-color, the nine scheme variants,contrast, roles by hand over the seed. - Density and ink:
visual-density,tap-target-sizeand the inksplash. - Component themes: how
components.*is written, and a page for each of the 49 components with every property. - Themes in code:
ThemeCustomizer, replacing theme beans, the order, theMaterialThemesbean, tests. - With the other starters: 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.
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.