Yêu cầu thg 2 16, 2023 10:02 SA 122 0 2
  • 122 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?

Chia sẻ
  • 122 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 CÂU TRẢ LỜI


Đã trả lời thg 2 16, 2023 10:11 SA
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();//
              },
            ),
          );
        },
      ),
    ],
  ),
);

} }

Chia sẻ
Avatar Đỗ Phuonganh @phanh.viblo
thg 2 16, 2023 10:12 SA

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

thg 2 17, 2023 2:19 SA

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

Đã trả lời thg 2 18, 2023 2:05 SA
0

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

Chia sẻ
Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí