アプリのウィジェット
依存関係にこのスターターがあれば、SpringApplicationWidget(home: ...) は MaterialApp を組み立てます。アプリの種類は material で、spring.flutter.app.type で設定されるか、プロパティが設定されていなければ、これがアプリケーションの唯一のデザインのスターターなので推定されます (Spring Boot がクラスパスから spring.main.web-application-type を推定するのと同じです)。アプリのウィジェットのそれ以外のすべては Flutter のスターターのものです。タイトル、デバッグバナー、ロケール、ナビゲーターのオブザーバー、FlutterAppCustomizer Bean は、アプリのウィジェット に説明されているとおり spring.flutter.app.* から来ます。
例
# lib/resources/application.yml
spring:
flutter:
app:
type: material # 省略可: 唯一のデザインのスターターが決める
title: NEON Books
debug-banner: false
locales: en, ja
theme:
active: system # デバイスに従ってライトまたはダーク
seed-color: teal
@SpringBootApplication()
void main() => runApp(
SpringApplicationWidget(
application: () => springApplication,
home: const BookListPage(),
),
);
MaterialApp が受け取るもの
MaterialApp の |
由来 |
|---|---|
theme、darkTheme |
MaterialThemes Bean: ThemeData としての spring.flutter.theme.* のテーマで、ThemeCustomizer Bean が変更したもの (コードでのテーマ を参照) |
themeMode |
spring.flutter.theme.active: system (デフォルト) では、Material はデバイスに従ってライトとダークのテーマを切り替える。ThemeSelection Bean で選ばれたテーマや、実行時に読み込まれたテーマは即座に表示される |
localizationsDelegates |
Material、Cupertino、ウィジェットの翻訳、その後にアプリ独自のもの (FlutterAppSettings.localizationsDelegates) |
title、debugShowCheckedModeBanner、locale、supportedLocales、navigatorObservers、shortcuts、scrollBehavior |
spring.flutter.app.* と FlutterAppCustomizer Bean |
builder |
Flutter のスターターのもの (テーマの背景、モーションの設定、フレームメーター) を、Material のテキストスタイル、Material のテキスト選択、MaterialDesignControls を持つ DesignScope の中に置いたもの |
home または routerConfig |
SpringApplicationWidget の home:。それがなければ、アプリケーションの RouterConfig<Object> Bean (ナビゲーションのスターター のもの) の上の MaterialApp.router |
アプリのウィジェットは Bean materialAppFactory (MaterialAppFactory。型 material のための Flutter のスターターの SpringAppFactory を実装する) が作ります。Flutter のスターターは、プロパティが示す種類のファクトリーを、プロパティが設定されていなければ自身の widgets 以外の唯一のファクトリーを見つけます。
Android では Material、iOS では Cupertino
ほとんどのプラットフォームでは Material、iPhone では Cupertino のアプリは、二つのデザインのスターターを列挙するので、種類を設定しなければなりません。すべてのプラットフォーム向けに設定し、iOS のプロファイルでもう一度設定します。
# lib/resources/application.yml
spring.flutter.app.type: material
# lib/resources/application-ios.yml
spring.flutter.app.type: cupertino
プロパティがなければ、二つの種類のアプリファクトリーのどちらかが優先されるのではなく、起動が失敗します。
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)
spring_boot_starter_flutter_cupertino を参照してください。
独自の MaterialApp
SpringApplicationWidget(child: ...) では、アプリは独自のアプリのウィジェットを組み立て、spring.flutter.app.* は使われません。テーマは MaterialThemes Bean から受け取り、スターター自身のウィジェット (MarkdownView、ログインフォーム) には DesignScope で Material の見た目を与えます。
class BooksApp extends SpringStatelessWidget<(MaterialThemes,)> {
const BooksApp({super.key});
@override
Widget build(BuildContext context) {
final (themes,) = beans;
return MaterialApp(
theme: themes.theme('light'),
darkTheme: themes.theme('dark'),
builder: (context, child) => DesignScope(
textStyle: (context, style) =>
Theme.of(context).textTheme.styleNamed(style),
selectable: (context, child) => SelectionArea(child: child),
controls: const MaterialDesignControls(),
child: child!,
),
home: const BookListPage(),
);
}
}
DesignScope がなくても、セキュリティスターターのログインフォームは Material のコントロールを見つけます (materialDesignControls Bean がその上の MaterialApp を見つけます)。その場合 MarkdownView は SpringTheme と、Flutter のスターター自身の選択ハンドルを使います。