I am having issues with Navigating to the LoginScreen. Here are the two modules, first is the welcome_screen.dart module, and 2nd is the login_screen.dart module. I am facing an error. I am unable to navigate to the 2nd screen. i.e. the login_screen.dart. I hope I have written the code properly. It's causing a lot of issues in navigating and routing.
welcome_screen.dart
import 'package:flutter/material.dart';
import 'package:my_first_flutter_app/login_screen.dart';
import 'package:my_first_flutter_app/signup_screen.dart';
class WelcomeScreen extends StatefulWidget {
const WelcomeScreen({Key? key}) : super(key: key);
@override
State<WelcomeScreen> createState() => WelcomeScreenState();
}
class WelcomeScreenState extends State<WelcomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body:Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget> [
const Text("Login",
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
)),
Image.asset("assets/images/girl-icon.jpg", height: 200,),
Padding(
padding: const EdgeInsets.all(20.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 50),
minimumSize: const Size(500, 50),
backgroundColor: Colors.pink,
primary: Colors.white,
textStyle: const TextStyle(
letterSpacing: 2,
),
),
onPressed: (){
Navigator.push(context,MaterialPageRoute(builder: (context)=> const LoginScreen()));
},
child: const Text("Login", style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
), )),
)),
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: TextButton(
style: TextButton.styleFrom( padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 50),
shape: const BeveledRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2))),
minimumSize: const Size(375, 50),
backgroundColor: Colors.pink,
primary: Colors.white,
textStyle: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
letterSpacing: 2,
),
),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=> const SigninScreen()));
},
child: const Text("SignUp")),)
],
),
heightFactor: 30,
),
);
}}
login_screen.dart
import 'package:flutter/material.dart';
import 'package:my_first_flutter_app/welcome_screen.dart';
class LoginScreen extends WelcomeScreen{
const LoginScreen({Key? key}) : super(key: key);
Widget build (BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text("LOGIN",
),
const TextField(
decoration: InputDecoration(
border: InputBorder.none,
),
),
Image.asset("assets/images/girl-icon.png")
],
));
}
}
CodePudding user response:
Your LoginScreen.dart extends WelcomeScreen then how navigator will work??
Your LoginScreen.dart must have Stateful or Stateless screen then you can easily navigate your Welcome screen to Login.
Ex:-class LoginScreen extends Steteless (Or make it Stateful as per your need)
CodePudding user response:
ISSUE RESOLVED.
class LoginScreen extends WelcomeScreen worked for me.
Thank you all for contributing your time.
