Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – I am trying to create a splash screen in my project but this code is not working. it just shows the splash screen forever

Posted on November 11, 2022 By

Solution 1 :

Separate your MaterialApp from your splash

import 'dart:async';

import 'package:flutter/material.dart';
void main() {
  runApp(MyApp(),);
}

class Splash extends StatefulWidget {
  @override
  _SplashState createState() => _SplashState();
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Splash(),
    );
  }
}

class _SplashState extends State<Splash> {
  @override
  void initState() {
    super.initState();
    Timer(
      Duration(seconds: 5),
          () => Navigator.of(context).pushReplacement(MaterialPageRoute(
        builder: (BuildContext context) => Home(),),),);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(child: Text("Splash Screen"),)
    );
  }
}


class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text("Home"),
        ),
      ),
    );
  }
}

Problem :

I am trying to create a splash screen in my project but this code is not working. it just shows the splash screen forever. it doesn’t switch to the home screen. Any help? (I want to create an app that starts with a splash screen but i don’t want this splash screen to be a photo)

import 'dart:async';
void main() {
  runApp( splash(),);
}
// ignore: camel_case_types
class splash extends StatefulWidget {
  @override
  _splashState createState() => _splashState();
}
// ignore: camel_case_types
class _splashState extends State<splash> {
  @override
  void initState() {
    super.initState();
    Timer(
        Duration(seconds: 5),
            () => Navigator.of(context).pushReplacement(MaterialPageRoute(
            builder: (BuildContext context) => home(),),),);
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
       body: Center(child: Text("Splash Screen"),)
      ),
    );
  }
}
class home extends StatefulWidget {
  @override
  _homeState createState() => _homeState();
}
// ignore: camel_case_types
class _homeState extends State<home> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text("Home"),
        ),
      ),
    );
  }
}```
READ  [FIXED] android - How do I get Room database size
Powered by Inline Related Posts
Android Tags:android, dart, flutter

Post navigation

Previous Post: [FIXED] java – How can I solve this Android Studio Firebase problem?
Next Post: [FIXED] Android Java Publish result cast issue at MyCustomAdapter.java

Related Posts

[FIXED] How can we add android nugets in Xamarin.forms and not only in Xamarin.Android Android
[FIXED] android – Foreground Service and WakeLocks are not working on Huawei Devices Android
[FIXED] android – Add text to dates in material-calendarview Android
[FIXED] unity3d – What is a correct way to display complex models in AR on Android app? Android
[FIXED] zoom an imageView and also be able to launch another activity by clicking on it android Android
[FIXED] api – Why do my Android app param names changed after uploading to playstore? Android

Archives

  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can Vicks humidifier be used without filter?
  • What color is Spanish green?
  • How old is Jamie in The War That Saved My Life?
  • When should I use scalp massager for hair growth?
  • Can I put polyurethane over liming wax?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme