
我的应用程序有一个简介屏幕,但每次打开应用程序时都会显示
我需要第一次证明这一点
怎么做?
//ThIS IS THE SCREEN COMES 1ST WHEN opening THE APP (SPLASHSCREEN)class SplashScreen extends StatefulWidget {@overrIDe_SplashScreenState createState() => _SplashScreenState();}class _SplashScreenState extends State<SplashScreen> {@overrIDevoID initState() {super.initState();//After 2seconds of time the Introscreen will e opened by bellow codeTimer(Duration(seconds: 2), () => MyNavigator.goToIntroscreen(context));}//The below code has the text to show for the spalshing screen@overrIDeWidget build(BuildContext context){return Scaffold(body: new Center(child:Text('SPLASH SCREEN'),));}}此屏幕始终打开内部屏幕,延迟时间为2秒.
但我只是第一次想要如何使用共享偏好?
请添加所需的代码请….
解决方法:
如果您希望仅首次显示介绍屏幕,则需要在本地保存此用户已经看过的介绍.
对于这样的事情,您可以使用Shared Preference.您可以使用共享偏好flutter package
编辑:
请参阅以下完整测试代码以了解如何使用它:
import 'dart:async';import 'package:Flutter/material.dart';import 'package:shared_preferences/shared_preferences.dart';voID main() => runApp(new MyApp());class MyApp extends StatelessWidget {@overrIDeWidget build(BuildContext context) { return new MaterialApp( color: colors.blue, home: new Splash(), );}}class Splash extends StatefulWidget {@overrIDeSplashState 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 Home())); } else { prefs.setBool('seen', true); Navigator.of(context).pushReplacement( new MaterialPageRoute(builder: (context) => new IntroScreen())); }}@overrIDevoID initState() { super.initState(); new Timer(new Duration(milliseconds: 200), () { checkFirstSeen(); });}@overrIDeWidget build(BuildContext context) { return new Scaffold( body: new Center( child: new Text('Loading...'), ), );}}class Home extends StatelessWidget {@overrIDeWidget 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 {@overrIDeWidget 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())); }, ) ], ), ), );}} 总结 以上是内存溢出为你收集整理的android – Flutter一次性介绍屏幕?全部内容,希望文章能够帮你解决android – Flutter一次性介绍屏幕?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)