Files
flame/packages/flame_splash_screen
Lukas Klingsbo d409193300 chore(release): Publish Flame v1.16.0 et. al (#3044)
```
Package Name           Current Version   Updated Version   Update Reason
flame                  1.15.0            1.16.0            manual versioning
flame_audio            2.1.8             2.10.0            manual versioning
flame_bloc             1.10.10           1.11.0            manual versioning
flame_fire_atlas       1.4.8             1.5.0             manual versioning
flame_rive             1.9.11            1.10.0            manual versioning
flame_riverpod         5.2.0             5.3.0             manual versioning
flame_svg              1.9.0             1.10.0            manual versioning
flame_test             1.15.4            1.16.0            manual versioning
flame_texturepacker    3.0.0             3.1.0             manual versioning
flame_tiled            1.18.4            1.19.0            manual versioning
flame_forge2d          0.16.0+5          0.17.0            updated with major changes
flame_isolate          0.5.1             0.6.0             updated with major changes
flame_lottie           0.3.0+8           0.4.0             updated with major changes
flame_markdown         0.1.1+8           0.2.0             updated with major changes
flame_network_assets   0.2.0+13          0.3.0             updated with major changes
flame_noise            0.2.0             0.3.0             updated with major changes
flame_oxygen           0.1.9+8           0.2.0             updated with major changes
flame_spine            0.1.1+10          0.2.0             updated with major changes
flame_splash_screen    0.2.0             0.3.0             updated with major changes
jenny                  1.2.1             1.3.0             updated with minor changes
```
2024-02-17 11:23:14 +01:00
..

flame

Style your Flame game with a beautiful splash screen.

This package includes a FlameSplashScreen widget.

Install

Add flame_splash_screen as a dependency to your pubspec.yaml file.

Import the widget:

import 'package:flame_splash_screen/flame_splash_screen.dart';

Usage

The splash screen is a widget that can be used to show the splash screen.

Simple usage

There is just two required params:

  • onFinish, a callback that is executed when all animations from the splash screen is over.
  • theme, than can be either FlameSplashTheme.dark or FlameSplashTheme.white.
FlameSplashScreen(
  theme: FlameSplashTheme.dark,
  onFinish: (BuildContext context) => Navigator.pushNamed(context, '/your-game-initial-screen'),
)

Adding your own content

You can pass your own logo (or/and anything else) to be shown before or after the Flame's logo.

FlameSplashScreen(
  theme: FlameSplashTheme.dark,
  showBefore: (BuildContext context) {
    return Text("To be shown before flame animation");
  },
  onFinish: (BuildContext context) => Navigator.pushNamed(context, '/your-game-initial-screen'),
)
FlameSplashScreen(
  theme: FlameSplashTheme.dark,
  showAfter: (BuildContext context) {
    return Text("To be shown after flame animation");
  },
  onFinish: (BuildContext context) => Navigator.pushNamed(context, '/your-game-initial-screen'),
)

Remember: you can also specify both showBefore and showAfter at the same time.

Changing theme

By default the splash screen has a dark background. You can change it by specifying the white theme.

Aside from FlameSplashTheme.dark, you can pass FlameSplashTheme.white for a white background.

FlameSplashScreen(
  theme: FlameSplashTheme.white,
  onFinish: (BuildContext context) => Navigator.pushNamed(context, '/your-game-initial-screen'),
)

You can create your own theme passing a custom logo builder (changing flames logo for another one) and a background decoration

Usage with controller

Controller enables FlameSplashScreen to be customized regarding animation duration and when it starts.

There is duration params and autoStart (which is true by default).

To use it, make the controller lives as much as a widget state:

class SplashScreenGameState extends State<SplashScreenGame> {
  FlameSplashController controller;
  @override
  void initState() {
      super.initState();
      controller = FlameSplashController(
        fadeInDuration: Duration(seconds: 1),
        fadeOutDuration: Duration(milliseconds: 250),
        waitDuration: Duration(seconds: 2),
        autoStart: false,
      );
  }
  
  @override
  void dispose() {
    controller.dispose(); // dispose it when necessary
    super.dispose();
  }
  
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FlameSplashScreen(
        showBefore: (BuildContext context) {
          return Text("Before the logo");
        },
        showAfter: (BuildContext context) {
          return Text("After the logo");
       },
       theme: FlameSplashTheme.white,
       onFinish: (context) => Navigator.pushNamed(context, '/the-game-initial-screen'),
        controller: controller,
      ),
    );
  }
}