android-studio - initState() 不显示在自动建议中
问题描述
我尝试覆盖initState()
inside _SplashScreenState
,但它没有显示在建议列表中,我也尝试了无效的捕获/重新启动。
import 'package:coupfferapp/screen/home.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_checkLoginSession().then((status) {
_navigateToHome();
});
}
Future<bool> _checkLoginSession() async {
await Future.delayed(Duration(microseconds: 5000), () {});
return true;
}
void _navigateToHome() {
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (BuildContext context) => Home()));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
color: Colors.white,
),
// Opacity(
// opacity: .9,
// child: Image.asset('images/splash.png', fit:
BoxFit.cover)),
Shimmer.fromColors(
child: Container(
padding: EdgeInsets.all(16.0),
child: Text(
"Mayur",
style: TextStyle(
fontSize: 90.0,
fontFamily: 'Calistoga',
shadows: <Shadow>[
Shadow(
blurRadius: 18.0,
color: Colors.black26,
offset: Offset.fromDirection(120, 12))
]),
),
),
baseColor: Colors.orange,
highlightColor: Colors.red)
],
),
),
);
}
}
解决方案
我遇到了同样的问题,我刚刚从构建函数的正上方调用了我的 initState 函数。让你的 initState() 和构建函数之间没有任何关系。
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return isAuth ? buildAuthScreen() : buildUnAuthScreen();
}
推荐阅读
- sql-server - SQL Server GROUP BY 但需要一个详细信息列
- php - 每个 TCP 连接上的误报 SYN 泛洪检测
- c# - 为什么 JsonSerializer 给空?
- node.js - FFMPEG 和 Node.js Spawn 不输出任何内容
- r - 在 R data.frame 中查找常量列的名称
- r - 当`Esc`在R中不起作用时如何停止运行函数?
- c# - 使用特定命名空间前缀的所有节点的 XPath 查询
- javascript - 有没有一种简洁的方式来查看网站的 JavaScript?
- java - 使用 java 8 流重构循环
- c# - EF Core并发,实体框架中SQL加法(+=)的等价物是什么?