spring_boot_starter_flutter_cupertino

spring_boot_starter_flutter_cupertino adds the iOS design, Cupertino, to a Flutter app built on spring_boot_starter_flutter. Since Flutter 3.50 Cupertino is not part of the SDK but the Flutter team's package cupertino_ui, and the Flutter starter knows no design library. With this starter, the app is a CupertinoApp (spring.flutter.app.type: cupertino, which need not be set when this is the one design starter), and every theme of spring.flutter.theme.* becomes a CupertinoThemeData.

It depends on cupertino_ui and on material_color_utilities (the color math of Material 3, pure Dart), not on material_ui: a Cupertino app has no Material in its build.

Why

Setup

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

dependencies:
  flutter:
    sdk: flutter
  cupertino_ui: ^1.1.6                                   # the Cupertino widgets
  spring_boot_starter_flutter_cupertino: ^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; an app lists this package, and cupertino_ui for the widgets it uses:

import 'package:cupertino_ui/cupertino_ui.dart';
import 'package:spring_boot_starter_flutter_cupertino/spring_boot_starter_flutter_cupertino.dart';

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

Example

# lib/resources/application.properties
spring.flutter.app.title=Counter
spring.flutter.theme.seed-color=teal
spring.flutter.theme.cupertino.bar-background-color=#F2F2F7
# the same in lib/resources/application.yml
spring:
  flutter:
    app:
      title: Counter
    theme:
      seed-color: teal
      cupertino:
        bar-background-color: '#F2F2F7'
// lib/main.dart
import 'package:cupertino_ui/cupertino_ui.dart';
import 'package:spring_boot_starter_flutter_cupertino/spring_boot_starter_flutter_cupertino.dart';

import 'spring_gen/main.spring.dart';

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

@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 CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(middle: Text('Counter')),
      child: Center(
        child: CupertinoButton.filled(
          onPressed: counter.increment,
          child: Text('${counter.value}'),
        ),
      ),
    );
  }
}

Without this starter in the dependencies, spring.flutter.app.type: cupertino fails the start, and the message names the package to add: "the app widget of type cupertino is built by spring_boot_starter_flutter_cupertino: add it to the dependencies (this application has: widgets)".

The type is deduced

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 cupertino. Set, the property always wins: widgets keeps a WidgetsApp although this starter is in the build.

Design starters in the dependencies spring.flutter.app.type not set Set
This one cupertino The type set (cupertino or widgets)
This one and the Material starter The start fails: the type must be chosen The type set, per platform if needed
None widgets cupertino fails the start, naming this starter

Material on Android, Cupertino on iOS

An app that is Material on Android and Cupertino on iOS depends on both design starters and both widget libraries, and sets the type: for every platform in application.properties, and again in the platform's profile, which only that platform reads (see Platform profiles):

# pubspec.yaml
dependencies:
  material_ui: ^1.11.0
  cupertino_ui: ^1.1.6
  spring_boot_starter_flutter_material: ^0.9.0
  spring_boot_starter_flutter_cupertino: ^0.9.0
# lib/resources/application.properties: Material everywhere ...
spring.flutter.app.type=material
# lib/resources/application-ios.properties: ... and Cupertino on iPhones and iPads
spring.flutter.app.type=cupertino

The same in YAML:

# lib/resources/application.yml
spring.flutter.app.type: material
# lib/resources/application-ios.yml
spring.flutter.app.type: cupertino

Without the type, the start fails, naming the property and the types:

Invalid argument(s) (spring.flutter.app.type): not set, and the application has app widgets of several types: cupertino, material. Choose one, for every platform or in a profile of each (spring.flutter.app.type=cupertino in application-ios.properties)

One theme serves both: the palette, the typography and the tokens are shared, components.* is read by the Material app, cupertino.* by the Cupertino app. The Cupertino bars even take components.app-bar.background-color when cupertino.bar-background-color is not set (see Theme properties).

What is inside

In Spring (Java)

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

See also