Asked Feb 16th, 2023 10:02 a.m. 118 0 2
  • 118 0 2
-5

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?

Share
  • 118 0 2

đă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 image.png đâ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 ANSWERS


Answered Feb 16th, 2023 10:11 a.m.
0

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();//
              },
            ),
          );
        },
      ),
    ],
  ),
);

} }

Share
Avatar Đỗ Phuonganh @phanh.viblo
Feb 16th, 2023 10:12 a.m.

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!'), ), ), ); } } */

0
| Reply
Share
Feb 17th, 2023 2:19 a.m.

Bạn cho code vào trong thẻ codeblock đi, đọc như này mù mắt.

0
| Reply
Share
Answered Feb 18th, 2023 2:05 a.m.
0

Tên class viết hoa lên bác. homescreen -> HomeScreen

Share
Viblo
Let's register a Viblo Account to get more interesting posts.