我要呼叫电子邮件功能并获取电子邮件功能的值,并检查其是否包含任何值如果email()不为空,则重定向到新屏幕
class SplashScreen extends StatefulWidget {
SharedPreferences sharedPreferences;
Future<String> email() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
return await preferences.getString("email");
}
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>
with SingleTickerProviderStateMixin {
@override
void initState() {
super.initState();
Future.delayed(
Duration(seconds: 3),
() {
Navigator.pushReplacement(
context,
PageRouteBuilder(
transitionDuration: Duration(milliseconds: 1500),
pageBuilder: (_, __, ___) => Introduction_Screen()));
},
);
}
您可以这样做。.
调用initState
中的函数。
void initState() {
super.initState();
email();
}
And..in email()
void email(){
SharedPreferences preferences = await SharedPreferences.getInstance();
var a = preferences.getString("email");
if(a != null && !a.isEmpty){
//Navigate to one screen
} else {
//Navigate to another screen
}
}
希望它能回答您的问题。
您可以执行此操作。
void init(){
super.init();
email();
}
void email() async {
SharedPreferences preferences = await SharedPreferences.getInstance();
var email = await preferences.getString("email");
if (email?.isNotEmpty ?? true) {
Navigator.pushReplacement(
context,
PageRouteBuilder(
transitionDuration: Duration(milliseconds: 1500),
pageBuilder: (_, __, ___) => Introduction_Screen()));
}
else{
//navigaate to some other screen
}
}