Giter Site home page Giter Site logo

flame_splash_screen's Introduction

Warning This repository is archived and its development has moved to the flame_monorepo.

Flame Splash Screen

Test

Style your Flame game with a beautiful splash screen.

This package includes a FlameSplashScreen widget.

Install

Add flame_splash_screen as a dependency in your pubspec.yaml file (what?).

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,
      ),
    );
  }
}

flame_splash_screen's People

Contributors

erickzanardo avatar luanpotter avatar renancaraujo avatar spydon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flame_splash_screen's Issues

Failed assertion: line 779 pos 7: '_ticker != null'

Installed this lib and getting this error from time to time. It's not crashing an app or something, but still might be something to investigate into.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: 'package:flutter/src/animation/animation_controller.dart': Failed assertion: line 779 pos 7: '_ticker != null': AnimationController.stop() called after AnimationController.dispose()
AnimationController methods should not be used after calling dispose.
#0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
#1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
#2      AnimationController.stop (package:flutter/src/animation/animation_controller.dart:779:7)
#3      AnimationController.value= (package:flutter/src/animation/animation_controller.dart:367:5)
#4      __SplashScreenStepState.startAnimation (package:flame_splash_screen/src/splash.dart:162:9)
<asynchronous suspension>

This is how my widget looks like:

    return MaterialApp(
      title: 'Some title',
      home: FlameSplashScreen(
        theme: FlameSplashTheme.dark,
        showAfter: (BuildContext context) {
          return const CreatedBy();
        },
        onFinish: (BuildContext context) => Navigator.pushReplacement(
          context,
          PageRouteBuilder(
            pageBuilder: (_, __, ___) => const GamePage(),
            transitionDuration: const Duration(seconds: 2),
            transitionsBuilder: (_, a, __, c) =>
                FadeTransition(opacity: a, child: c),
          ),
        ),
      ),
    );

Null error occurred

Maybe I'm using it wrong, but I sometimes get the following error This does not always happen.

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
#0 AnimationController.stop (package:flutter/src/animation/animation_controller.dart:777)
#1 AnimationController.value= (package:flutter/src/animation/animation_controller.dart:364)
#2 __SplashScreenStepState.startAnimation (package:flame_splash_screen/src/splash.dart:162)

Don't run `onFinish` on hot reload

It seems that the onFinish method is been run again even after the hot reload happens. That makes the development of an app that uses this package very bad. Maybe we could just don't run it after hot reloads.

how to

Hello,

In fact, this is not an issue or problem report. I just want to ask a how to question.

I want to make a Loading Screen for a game that I am developing. I want to show just my game's logo and remove flame logo. Is it possible to this with this package?

Also, if it is possible I want to show a percentage bar and update it while loading assets. And loading screen will be dismissed as soon as last asset loaded.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.