2
votes

I want to make a splash screen in flutter with some logic inside it to know if the user has already signed in or not in order to direct him to the right page.

I've made the Android and iOS splash screens separately but ofcourse I can't have any logic inside them, then made another splash screen in flutter to know whether the user has previously logged in or not, the problem is there's a small weird transition between the native splash screen and the flutter one, so is there a solution to avoid that transition? Or to have logic inside native splash screen that communicates with SharedPreferences?

1

1 Answers

0
votes

Don't make a Flutter splash. Let the native iOS/Android splash fill the screen while the Flutter app's main code decides to show the Home or Login page. It should be a very quick process if all you are doing is looking in SharedPreferences for a session token.

I just answered two other questions today that deal with this very same issue. It think they should help...

https://stackoverflow.com/a/60121967/7034640

https://stackoverflow.com/a/60122485/7034640

UPDATE

I created a Flutter test app.

I set the Android splash screen to be red.

I changed the contents of main.dart to the following.

import 'package:flutter/material.dart';

void main() async {
  await Future.delayed(Duration(seconds: 5));
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(final BuildContext context) {
    return MaterialApp(
      title: 'Splash Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(final BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("My Home Page")),
      body: Center(child: const Text("My Home Page")),
    );
  }
}

I ran the app on an Android device with flutter run --release.

I see the red screen for about 0.5 seconds, then see a black screen for 5 seconds, and finally see the home screen.

Hmm. I expected the red screen to show for about 5.5 seconds and then the home screen. I did not expect the black screen to show.