如果在自定义启动画面上看到检查,我该怎么办?如果已经看到漫游屏幕

How can I do if seen check on custom splash screen? If walkthrough screen is already seen

我先做一个闪屏应用程序,如果用户第一次使用该应用程序,然后是一个演练页面,否则如果已经看到演练屏幕,请转到欢迎页面登录/注册。

我的代码来自此项目 main.dart 文件:https://github.com/instaflutter/flutter-login-screen-firebase-auth-facebook-login 并将其修改为此代码(来自启动画面教程 FlutterKart)

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:binder/ui/screens/root_screen.dart';
import 'package:binder/ui/screens/walk_screen.dart';


void main() {
   Firestore.instance.settings(timestampsInSnapshotsEnabled: true);
   SharedPreferences.getInstance().then((prefs) {
   SplashScreen(prefs: prefs);
});
}

   class SplashScreen extends StatefulWidget {  
     final SharedPreferences prefs;
     SplashScreen({Key key,this.prefs}): super(key: key);

     @override
     _SplashScreenState createState() => _SplashScreenState();
     }

   class _SplashScreenState extends State<SplashScreen> {

    @override
   void initState() {
   super.initState();
   Timer(Duration(seconds: 3), () => _handleCurrentScreen(context));
   }

    @override
  Widget build(BuildContext context) {
     final logowhite = Hero(
      tag: 'hero',
      child: //code insert flutterkart splashscreen
                )
              ],
            ),
          )
        ],
      )
    ],
  ),
);
}
 Widget _handleCurrentScreen (BuildContext context) {
bool seen = (widget.prefs.getBool('seen') ?? false);
if (seen) {
  return new RootScreen();
} else {
  return new WalkthroughScreen(prefs: widget.prefs);
}
}
}

我希望它首先显示初始屏幕,如果已经看到则定向到根屏幕,如果第一次使用则定向到演练屏幕。

您可能想要使用 shared_preferences 或类似的东西。像这样:

// add this static variable somewhere
// could technically be initialized during splash screen and added to a Provider or something similar after
static SharedPreferences prefs;

// make `main` async if it is not already
Future<void> main() async {
  prefs = await SharedPreferences.getInstance();

  ...
}

Future<void> onSplashScreenDone() async {
  if (prefs.getBool('isFirstTime') ?? true) {
    // you might want to put this at the end of your walkthrough, so they don't miss it if they close the app, for example
    await prefs.setBool('isFirstTime', false);

    // this is their first time, show walkthrough, etc.
    ...
  } else {
    // this is not their first time, do normal things.
  }
}