闪烁的启动屏幕无法导航到所需屏幕



我的启动屏幕在500毫秒后没有导航到主屏幕

我在我的应用程序中维护了两个文件:

main.dart
app.dart

在我的主要艺术

void main() {
runApp(SplashScreen());
}

在我的飞溅屏幕上。飞镖:

class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
late Store store;
void initState() {
super.initState();
initAppAndNavigate();
}
Future initAppAndNavigate() async {
var _duration = new Duration(microseconds: 100);
return Timer(_duration, navigateToHomeScreen);
}
void navigateToHomeScreen() {
MaterialPageRoute(builder: (context) => App());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
// backgroundColor: CustomColors.primary,
backgroundColor: Color(0xff75c760),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildAppName(),
SizedBox(height: 20),
_buildSpinner(),
],
),
),
);
}
Widget _buildAppName() {
return Text(
"My App",
style: GoogleFonts.robotoMono(
color: Colors.black,
fontStyle: FontStyle.normal,
fontSize: 30,
fontWeight: FontWeight.bold,
),
);
}
Widget _buildSpinner() {
return SpinKitDoubleBounce(
color: Colors.white,
);
}
}

正如您所看到的,我已经将持续时间定义为500毫秒,但应用程序不会转到应用程序((。

现在,应用程序((已经定义了我的所有路由。有状态小部件内部:

int _currentIndex = 0;
Widget loadScreens(int currentIndex) {
switch (currentIndex) {
case 0:
return HomeScreen();
case 1:
return CategoryScreen();
case 2:
return WishlistScreen();
case 3:
return ProfileScreen();
default:
HomeScreen();
return Container();
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: loadScreens(_currentIndex),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _currentIndex,
backgroundColor: Colors.white,
onTap: (value) {
setState(
() {
_currentIndex = value;
},
);
},
selectedItemColor: Color(0xff75c760),
items: [
BottomNavigationBarItem(
icon: Icon(EvaIcons.messageCircleOutline),
label: "Feed",
),
BottomNavigationBarItem(
icon: Icon(EvaIcons.activity),
label: "Catergory",
),
BottomNavigationBarItem(
icon: Icon(EvaIcons.heartOutline),
label: "Favorites",
),
BottomNavigationBarItem(
icon: Icon(EvaIcons.personOutline),
label: "Profile",
),
],
),
),
);
}

我在这里做错了什么?

你可以试试这个

Timer(const Duration(milliseconds: 4000),(){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (BuildContext context) => LoginScreen()));
});

最新更新