In my main.dart file I want to navigate to the secondroute screen when I press log in button. but it’s not working.
here is my code,
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: MyApp(),));
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.white,
body:Column(
children: [
const SizedBox(height: 80,),
Image.asset('Assets/3.jpg'),
const SizedBox(height: 30,),
Padding(
padding: const EdgeInsets.all(10.0),
child: Center(
child: Text( "\"Losing weight is hard, maintaining weight is hard, "
"staying overweight is hard. Choose your hard.”",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 20,color: Colors.blue.shade800,fontStyle: FontStyle.italic)),
),
),
const Center(child: Text("– Anonymous",style: TextStyle(fontWeight:FontWeight.w500,fontSize: 15 ),)),
const SizedBox(height: 80,),
Center(
child: SizedBox(
height: 45,width: 170,
child: ElevatedButton(
style: ElevatedButton.styleFrom(elevation:5,backgroundColor: Colors.blue.shade300,shape: RoundedRectangleBorder(borderRadius:BorderRadius.circular(25))),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SecondRoute()),
);
},
child: const Text('Log In',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 20)),
),
),
),
const SizedBox(height: 20,) ,
Center(
child: SizedBox(
height: 45,width: 170,
child: OutlinedButton(
style: OutlinedButton.styleFrom(shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),side:const BorderSide(color: Colors.blue,width: 2.0)),
onPressed: () {},
child: const Text('Sign Up',style: TextStyle(fontWeight: FontWeight.bold,color: Colors.blue,fontSize: 20),),
),
)
),
],
)
),
);
}
}
class SecondRoute extends StatelessWidget {
const SecondRoute({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Route'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Go back!'),
),
),
);
}
}