Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter first launch page

Tags:

flutter

dart

I'm currently working on a Flutter version of an android application and now want to implement the first launch page. It should only be displayed on the very first launch of the app after it has been installed on a device. I figured out how to do it for the android app, but I only have a basic knowledge of Flutter, so I'm asking this question. Does anyone know how to do this in Flutter in a simple way?

Thanks in advance for your help!

like image 550
Felix Teupke Avatar asked May 17 '18 11:05

Felix Teupke


People also ask

How do I change my first page on Flutter?

In your main. dart you can specify the first screen that your app opens to: runApp(new MaterialApp( debugShowCheckedModeBanner: false, theme: //theme title: "Title", home: new Login(), //Here you can specify the screen the app starts on.

How do I check my first app launch on Flutter?

You simply do: bool firstRun = await IsFirstRun. isFirstRun(); It returns true if the app is launched for the first time.

When did Flutter come out?

Flutter 1.0 was launched on Dec 4th, 2018 and Flutter 2 on March 3rd, 2021. Since its launch, over 400,000 apps have shipped using Flutter to many hundreds of millions of devices. See some sample apps in the showcase.

How to return to the first route in flutter?

Return to the first route using Navigator.pop () Most apps contain several screens for displaying different types of information. For example, an app might have a screen that displays products. When the user taps the image of a product, a new screen displays details about the product. Terminology: In Flutter, screens and pages are called routes .

How do I create my first Flutter App?

Create a simple, templated Flutter app, using the instructions in Getting Started with your first Flutter app . Name the project startup_namer (instead of flutter_app ). Tip: If you don’t see “New Flutter Project” as an option in your IDE, make sure you have the plugins installed for Flutter and Dart.

What is flutter introduction screen?

Flutter Introduction Screen will help the developer to have a screen that will show only one time at launcher of the App to explain what the app can do an how users can use a welcome screen. Then, Now you know about the Flutter widget Let’s begin the implementation straight into the Our App.

How to add a splash screen in flutter?

We will implement three basic methods to add a splash screen in our app. In this method, we will create a splash screen with the help of the Timer () function. 1. Create a new Flutter app using Command Prompt. 2. Delete the code from main.dart file and copy the below code.


4 Answers

You could do this by having a separate route for your intro/app:

void main() {
  runApp(new MaterialApp(
    home: new MyIntroPage(),
    routes: <String, WidgetBuilder> {
      '/app': (BuildContext context) => new MyAppPage()
    },
  ));
}

In your intro page you could check a flag for whether the user has seen it (see here for some ideas on persisting data) and if so, just navigate straight to the app (for example like the _completeLogin function here)

like image 96
Danny Tuppeny Avatar answered Nov 15 '22 09:11

Danny Tuppeny


You could make the Splash screen in Dart but is not recommend because it can bore your users (you will use a fixed duration time) , so in my personal opinion I will go for a native splash screen in each platform.

Android

  • Modify the file launch_background.xml
  • Uncomment the bitmap item and put any item that you have in your mipmap or drawable folder
  • Change the color of your background in android:drawable item

iOS

  • Add your custom images into the Assets.xcassets folder
  • Modify the file LaunScreen.storyboard, change the background color, add and imageview, etc.

I created a post with all of the details about the Splash Screen in Flutter, you can take a look : https://medium.com/@diegoveloper/flutter-splash-screen-9f4e05542548

like image 43
diegoveloper Avatar answered Nov 15 '22 10:11

diegoveloper


First-time view Page with user input, It's sample code, you can get idea

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:reborn_next_job02/ui/LoginScreen.dart';
import 'package:reborn_next_job02/ui/splashScreen.dart';
import 'package:shared_preferences/shared_preferences.dart';

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

class SplashState extends State<Splash> {
  Future checkFirstSeen() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    bool _seen = (prefs.getBool('seen') ?? false);
    if (_seen) {
      Navigator.of(context).pushReplacement(
          new MaterialPageRoute(builder: (context) => new LoginScreen()));
    } else {
      prefs.setBool('seen', true);
      Navigator.of(context).pushReplacement(
          new MaterialPageRoute(builder: (context) => new urlScreen()));
    }
  }

  @override
  void initState() {
    super.initState();
    new Timer(new Duration(seconds: 10), () {
      checkFirstSeen();
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Text('Loading...'),
      ),
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Hello'),
      ),
      body: new Center(
        child: new Text('This is the second page'),
      ),
    );
  }
}

class IntroScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Center(
        child: new Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            new Text('This is the intro page'),
            new MaterialButton(
              child: new Text('Gogo Home Page'),
              onPressed: () {
                Navigator.of(context).pushReplacement(
                    new MaterialPageRoute(builder: (context) => new Home()));
              },
            )
          ],
        ),
      ),
    );
  }
}
like image 41
BIS Tech Avatar answered Nov 15 '22 09:11

BIS Tech


I don't really Know the exact Logic but This is How I would implement it, I will be just explaining you the logic the code below is not syntactically correct

lets call your one time view page as intro page I will maintain an integer variable in that intro page

int counter;

When for the first Time the intro page loads I will initialize

 counter = sharedPreferencevalue // defaults to 0 when App is fresh installed 

and check if counter==0

 if yes
   load the intro page 
   counter++;
   store counter in SharedPreference; //overwrite the default value
 else
   go to Home

simply increment the variable and store the value of that variable locally using SharedPreference

for those who don't know about Shared Preferences, it allows a Flutter application (Android or iOS) to save settings, properties, data in the form of key-value pairs that will persist even when the user closes the application.

hope this Helps :)

like image 37
Mahesh Jamdade Avatar answered Nov 15 '22 10:11

Mahesh Jamdade