springBootStarterFlutterAutoConfiguration top-level property

  1. @AutoConfigurationModule()
BeanModule springBootStarterFlutterAutoConfiguration
final

The beans the starter adds to every Flutter application:

  • support for asset: locations, so @Value('asset:...') injects Flutter assets as resources;
  • the advice that calls notifyListeners() for @NotifyListeners and @ChangeNotifierComponent beans, and the one that tells Spring widgets which of those beans their build read;
  • the app's themes from spring.flutter.theme.* (SpringThemes) and the choice of the theme shown (ThemeSelection), and the loader of the themes that come from a URL (themes.<name>.source);
  • the app's files: a FileStore (platformFileStore: the device's directories, IndexedDB in a browser) and the FileTemplate on it (fileTemplate), each only when the app declares none;
  • the keyboard shortcuts of spring.flutter.shortcuts.* and the @Shortcut methods (keyboardShortcuts), around the app's navigator (keyboardShortcutsCustomizer);
  • the theme the user chooses, kept between runs (fileThemeChoiceStore, unless the app declares a ThemeChoiceStore) and shown again while the splash shows (themeChoiceRestore), unless spring.flutter.theme.remember is false;
  • with spring.flutter.splash.warm-up.text.enabled, the fonts of the app's text downloaded while the splash shows (textWarmUp, a SplashTask, of the text of spring.flutter.splash.warm-up.text.resources and the TextWarmUpSource beans).

Logins and secrets (the platform's secure storage, the login window) are spring_boot_starter_flutter_security's.

Implementation

@AutoConfigurationModule()
final BeanModule springBootStarterFlutterAutoConfiguration = BeanModule(
  'springBootStarterFlutterAutoConfiguration',
  [
    BeanDefinition<AssetProtocolResolverRegistrar>(
      name: 'assetProtocolResolverRegistrar',
      types: const [
        AssetProtocolResolverRegistrar,
        BeanFactoryPostProcessor,
        ApplicationContextAware,
      ],
      source: _source,
      create: (_) => AssetProtocolResolverRegistrar(),
    ),
    BeanDefinition<DefaultPointcutAdvisor>(
      name: 'notifyListenersAdvisor',
      types: const [DefaultPointcutAdvisor, PointcutAdvisor, Advisor, Ordered],
      source: _source,
      create: (_) => DefaultPointcutAdvisor(
        const NotifyListenersPointcut(),
        const NotifyListenersInterceptor(),
      ),
    ),
    BeanDefinition<DefaultPointcutAdvisor>(
      name: 'beanReadsAdvisor',
      types: const [DefaultPointcutAdvisor, PointcutAdvisor, Advisor, Ordered],
      source: _source,
      create: (_) => DefaultPointcutAdvisor(
        const BeanReadsPointcut(),
        const BeanReadsInterceptor(),
      ),
    ),
    BeanDefinition<KeyboardShortcuts>(
      name: 'keyboardShortcuts',
      types: const [
        KeyboardShortcuts,
        BeanPostProcessor,
        BeanFactoryAware,
        SmartInitializingSingleton,
      ],
      source: _source,
      create: (r) => KeyboardShortcuts(r.dependency<ConfigurableEnvironment>()),
    ),
    BeanDefinition<KeyboardShortcutsCustomizer>(
      name: 'keyboardShortcutsCustomizer',
      types: const [KeyboardShortcutsCustomizer, FlutterAppCustomizer],
      source: _source,
      create: (r) => KeyboardShortcutsCustomizer(
        r.dependency<KeyboardShortcuts>(),
      ),
    ),
    BeanDefinition<StartupEvents>(
      name: 'startupEvents',
      types: const [StartupEvents, GenericApplicationListener],
      source: _source,
      create: (r) => StartupEvents(r.optionalDependency<SplashTrace>()),
    ),
    BeanDefinition<ResourcePrefetch>(
      name: 'resourcePrefetch',
      types: const [
        ResourcePrefetch,
        SplashTask,
        GenericApplicationListener,
      ],
      source: _source,
      preDestroy: (bean) => bean.stop(),
      create: (r) =>
          ResourcePrefetch.of(r.dependency<ConfigurableEnvironment>()),
    ),
    BeanDefinition<ResourceTextWarmUpSource>(
      name: 'resourceTextWarmUpSource',
      types: const [ResourceTextWarmUpSource, TextWarmUpSource],
      source: _source,
      conditions: const [_textWarmUp],
      create: (r) => ResourceTextWarmUpSource(
        r.dependency<ApplicationContext>(),
        r.dependency<ConfigurableEnvironment>().getPropertyAs<List<String>>(
              'spring.flutter.splash.warm-up.text.resources',
            ) ??
            const ['resources:messages*.properties'],
      ),
    ),
    BeanDefinition<TextWarmUp>(
      name: 'textWarmUp',
      types: const [TextWarmUp, SplashTask],
      source: _source,
      conditions: const [_textWarmUp],
      create: (r) {
        final environment = r.dependency<ConfigurableEnvironment>();
        final themes = r.dependency<SpringThemes>();
        return TextWarmUp(
          r.optionalDependencyList<TextWarmUpSource>() ?? const [],
          fontFamilies: {
            for (final name in themes.names) ...themes.data(name).fontFamilies,
          },
          fontFamilyFallback: {
            for (final name in themes.names)
              ...?themes.data(name).fontFamilyFallback,
          }.toList(),
          firstFont:
              environment.getPropertyAs<Duration>(
                'spring.flutter.splash.warm-up.text.first-font',
              ) ??
              const Duration(milliseconds: 400),
          settle:
              environment.getPropertyAs<Duration>(
                'spring.flutter.splash.warm-up.text.settle',
              ) ??
              const Duration(milliseconds: 250),
          chunk:
              environment.getPropertyAs<int>(
                'spring.flutter.splash.warm-up.text.chunk',
              ) ??
              200,
        );
      },
    ),
    BeanDefinition<SpringThemes>(
      name: 'springThemes',
      types: const [SpringThemes, ChangeNotifier, Listenable],
      source: _source,
      create: (r) => SpringThemes.fromEnvironment(
        r.dependency<ConfigurableEnvironment>(),
        addresses:
            r.optionalDependency<RemoteAddresses>() ?? const RemoteAddresses(),
        // The design libraries of the application's starters.
        designs: ThemeDesigns.of(
          r.optionalDependency<SpringFactories>() ?? const SpringFactories(),
          r.dependency<ConfigurableEnvironment>(),
        ),
      ),
    ),
    BeanDefinition<ThemeSelection>(
      name: 'themeSelection',
      types: const [ThemeSelection, ChangeNotifier, Listenable],
      source: _source,
      create: (r) => ThemeSelection(
        r.dependency<SpringThemes>(),
        store: r.optionalDependency<ThemeChoiceStore>(),
      ),
    ),
    BeanDefinition<ThemeChoiceStore>(
      name: 'fileThemeChoiceStore',
      types: const [ThemeChoiceStore, FileThemeChoiceStore],
      source: _source,
      conditions: const [
        _rememberTheme,
        ConditionGroup('$_source.fileThemeChoiceStore', [
          ConditionalOnMissingBean(ThemeChoiceStore),
        ]),
      ],
      create: (r) => FileThemeChoiceStore(r.dependency<FileTemplate>()),
    ),
    BeanDefinition<ThemeChoiceRestore>(
      name: 'themeChoiceRestore',
      types: const [ThemeChoiceRestore, SplashTask],
      source: _source,
      conditions: const [_rememberTheme],
      create: (r) => ThemeChoiceRestore(
        r.dependency<ThemeSelection>(),
        r.dependency<ThemeChoiceStore>(),
      ),
    ),
    BeanDefinition<FileStore>(
      name: 'platformFileStore',
      types: const [FileStore],
      source: _source,
      conditions: const [
        ConditionGroup('$_source.platformFileStore', [
          ConditionalOnMissingBean(FileStore),
        ]),
      ],
      create: (_) => createPlatformFileStore(),
    ),
    BeanDefinition<CacheStore>(
      name: 'fileCacheStore',
      types: const [CacheStore],
      source: _source,
      conditions: const [
        ConditionGroup('$_source.fileCacheStore', [
          ConditionalOnMissingBean(CacheStore),
        ]),
      ],
      create: (r) => FileCacheStore(r.dependency<FileStore>()),
    ),
    BeanDefinition<ResourceCache>(
      name: 'resourceCache',
      source: _source,
      preDestroy: (cache) => cache.close(),
      create: (r) {
        final properties = r.dependency<FlutterResourcesCacheProperties>();
        return ResourceCache(
          store: r.dependency<CacheStore>(),
          properties: properties,
          fetcher: RemoteFetcher(
            transport: r.optionalDependency<HttpTransport>(),
            timeout: const Duration(seconds: 30),
            maxBytes: properties.maxEntrySize?.toBytes() ?? 50 * 1024 * 1024,
            allowInsecure: RemoteAddressPolicy.of(
              r.dependency<ConfigurableEnvironment>(),
            ).allowInsecure,
          ),
        );
      },
    ),
    BeanDefinition<CachedResourceRegistrar>(
      name: 'cachedResourceRegistrar',
      types: const [
        CachedResourceRegistrar,
        BeanFactoryPostProcessor,
        ApplicationContextAware,
      ],
      source: _source,
      create: (_) => CachedResourceRegistrar(),
    ),
    BeanDefinition<FileTemplate>(
      name: 'fileTemplate',
      source: _source,
      conditions: const [
        ConditionGroup('$_source.fileTemplate', [
          ConditionalOnMissingBean(FileTemplate),
        ]),
      ],
      create: (r) => FileTemplate(
        r.dependency<FileStore>(),
        objectMapper: r.optionalDependency<ObjectMapper>(),
      ),
      preDestroy: (files) => files.close(),
    ),
    BeanDefinition<ThemeSourceLoader>(
      name: 'themeSourceLoader',
      types: const [ThemeSourceLoader, ApplicationRunner],
      source: _source,
      create: (r) => ThemeSourceLoader.fromEnvironment(
        r.dependency<ConfigurableEnvironment>(),
        themes: r.dependency<SpringThemes>(),
        files: r.dependency<FileTemplate>(),
        transport: r.optionalDependency<HttpTransport>(),
      ),
      preDestroy: (loader) => loader.dispose(),
    ),
    BeanDefinition<ThemeImageLoader>(
      name: 'themeImageLoader',
      types: const [ThemeImageLoader, ApplicationRunner],
      source: _source,
      create: (r) => ThemeImageLoader(
        themes: r.dependency<SpringThemes>(),
        files: r.dependency<FileTemplate>(),
        transport: r.optionalDependency<HttpTransport>(),
        allowInsecure: RemoteAddressPolicy.of(
          r.dependency<ConfigurableEnvironment>(),
        ).allowInsecure,
      ),
      preDestroy: (loader) => loader.dispose(),
    ),
  ],
  imports: [flutterConfigBeans],
);