màn app có gạch chéo và load mãi không ngừng cũng không chuyển màn do đâu?
đăng nhập từ màn log in sang homescreen: màn cứ loanding mãi như này và có dấu gạch chéo đây là homescreen:
import 'package:flutter/cupertino.dart';
// import 'package:http/http.dart';
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/Welcome/components/login_signup_btn.dart';
class homescreen extends StatefulWidget {
const homescreen({Key? key}) : super(key: key);
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.pink, title: Text('Home')),
body: Column(
children: [
Row(children: [
ElevatedButton(
child: Text('log out'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red)),
onPressed: () {Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const LoginAndSignupBtn()
)
);},
),
ElevatedButton(
child: Text('help'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.white)),
onPressed: () {},
),
Center(
child: Text('welcome'),
),
])
],
),
);
}
@override
State<homescreen> createState() => _homescreenState();
}
class _homescreenState extends State<homescreen> {
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
đây là màn login:
import 'package:flutter/material.dart';
import 'package:flutter_auth/Screens/HomeScreen/Home_screen.dart';
// import 'package:http/http.dart';
import '../../../components/already_have_an_account_acheck.dart';
import '../../../constants.dart';
import '../../Signup/signup_screen.dart';
class LoginForm extends StatelessWidget {
const LoginForm({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Form(
child: Column(
children: [
TextFormField(
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
cursorColor: kPrimaryColor,
onSaved: (email) {},
decoration: InputDecoration(
hintText: "Your email",
prefixIcon: Padding(
padding: const EdgeInsets.all(defaultPadding),
child: Icon(Icons.person),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: defaultPadding),
child: TextFormField(
textInputAction: TextInputAction.done,
obscureText: true,
cursorColor: kPrimaryColor,
decoration: InputDecoration(
hintText: "Your password",
prefixIcon: Padding(
padding: const EdgeInsets.all(defaultPadding),
child: Icon(Icons.lock),
),
),
),
),
const SizedBox(height: defaultPadding),
Hero(
tag: "login_btn",
child: ElevatedButton(
child: Text(
"Login".toUpperCase(),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const homescreen()
),
);},
//---------------------//
),
),
const SizedBox(height: defaultPadding),
AlreadyHaveAnAccountCheck(//gọi hàm
press: () {
Text('đã có một account ?');//press
Navigator.push( //push
context,
MaterialPageRoute(//hsfm sẵn
builder: (context) {
return SignUpScreen();//
},
),
);
},
),
],
),
);
}
}
2 CÂU TRẢ LỜI
login forrm : import 'package:flutter/material.dart'; import 'package:flutter_auth/Screens/HomeScreen/Home_screen.dart'; // import 'package:http/http.dart'; import '../../../components/already_have_an_account_acheck.dart'; import '../../../constants.dart'; import '../../Signup/signup_screen.dart';
class LoginForm extends StatelessWidget { const LoginForm({ Key? key, }) : super(key: key);
@override Widget build(BuildContext context) { return Form( child: Column( children: [ TextFormField( keyboardType: TextInputType.emailAddress, textInputAction: TextInputAction.next, cursorColor: kPrimaryColor, onSaved: (email) {}, decoration: InputDecoration( hintText: "Your email", prefixIcon: Padding( padding: const EdgeInsets.all(defaultPadding), child: Icon(Icons.person), ), ), ), Padding( padding: const EdgeInsets.symmetric(vertical: defaultPadding), child: TextFormField( textInputAction: TextInputAction.done, obscureText: true, cursorColor: kPrimaryColor, decoration: InputDecoration( hintText: "Your password", prefixIcon: Padding( padding: const EdgeInsets.all(defaultPadding), child: Icon(Icons.lock), ), ), ), ),
const SizedBox(height: defaultPadding),
Hero(
tag: "login_btn",
child: ElevatedButton(
child: Text(
"Login".toUpperCase(),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const homescreen()
),
);},
//---------------------//
),
),
const SizedBox(height: defaultPadding),
AlreadyHaveAnAccountCheck(//gọi hàm
press: () {
Text('đã có một account ?');//press
Navigator.push( //push
context,
MaterialPageRoute(//hsfm sẵn
builder: (context) {
return SignUpScreen();//
},
),
);
},
),
],
),
);
} }
home screen: import 'package:flutter/cupertino.dart';
// import 'package:http/http.dart'; import 'package:flutter/material.dart'; import 'package:flutter_auth/Screens/Welcome/components/login_signup_btn.dart';
class homescreen extends StatefulWidget { const homescreen({Key? key}) : super(key: key);
Widget build(BuildContext context) { return Scaffold( appBar: AppBar(backgroundColor: Colors.pink, title: Text('Home')), body: Column( children: [ Row(children: [ ElevatedButton( child: Text('log out'), style: ButtonStyle( backgroundColor: MaterialStateProperty.all(Colors.red)), onPressed: () {Navigator.push( context, MaterialPageRoute( builder: (context) => const LoginAndSignupBtn() ) );},
),
ElevatedButton(
child: Text('help'),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.white)),
onPressed: () {},
),
Center(
child: Text('welcome'),
),
])
],
),
);
}
@override State<homescreen> createState() => _homescreenState(); }
class _homescreenState extends State<homescreen> { @override Widget build(BuildContext context) { return const Placeholder(); } } /* mẫu code navigative
class FirstRoute extends StatelessWidget { const FirstRoute({super.key});
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('First Route'), ), body: Center( child: ElevatedButton( child: const Text('Open route'), onPressed: () { // Navigate to second route when tapped. }, ), ), ); } }
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: () { // Navigate back to first route when tapped. }, child: const Text('Go back!'), ), ), ); } } */
Bạn cho code vào trong thẻ codeblock đi, đọc như này mù mắt.