Whenever I want to navigate to next page with specific time, the destination page isn't found, even I imported the page. Instead of Navigation, if I print something, It works OK. Error line is highlighted in bold inside code.
import 'package:flutter/material.dart';
import 'dart:async';
import 'main.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: "Flutter App",
theme: ThemeData(
appBarTheme: AppBarTheme(
color: Colors.deepOrangeAccent,
),
primarySwatch: Colors.indigo,
),
home: LoginScreen(),
);
}
}
class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key);
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
@override
void initState() {
// TODO: implement initState
super.initState();
Timer(Duration(seconds: 5), () {
// 5 seconds over, navigate to Page2.
**Navigator.of(context).push(MaterialPageRoute(builder: (context)=>main()));****
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.indigo,
body: Padding(
//padding: const EdgeInsets.all(20.0),
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Image.asset(
"assets/images/logo.png",
//fit: BoxFit.fitWidth,
height: 200,
width: 200,
),
),
//CircularProgressIndicator(),
SizedBox(
height: 20,
),
Text(
"Fresh Food Restaurant",
style: TextStyle(
color: Colors.deepOrangeAccent,
fontSize: 25,
fontWeight: FontWeight.w900,
),
),
SizedBox(
height: 150,
),
// CircularProgressIndicator(
// backgroundColor: Colors.deepOrangeAccent,
// ),
// SizedBox(
// height: 10,
// ),
// Text(
// "Loading, Please wait",
// style: TextStyle(
// color: Colors.white,
// ),
// ),
SizedBox(
height: 100,
),
FloatingActionButton(
backgroundColor: const Color(0xff03dac6),
foregroundColor: Colors.black,
onPressed: () {
},
child: Icon(Icons.arrow_forward),
)
],
),
),
),
);
}
}