create button to direct to registration page does not appear

0

I know the question is simple but I am in doubt about creating a simple button, which directs to the initial page of user registration. I'm inserting the code below, there are no errors but when compiling nothing appears, I have already tested it by changing other elements and they update but the new button created does not appear on the screen.

New Button:

Container(
    height: 30,
    alignment: Alignment.center,
    child: SizedBox.expand(
        child: TextButton(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("Cadastre-se", style: TextStyle(color: Colors.black))
              ],
            ),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) {
                    return RegisterName();
                  },
                ),
              );
            })));

Current Code:

   final button = Container(
    height: 50,
    alignment: Alignment.center,
    decoration: BoxDecoration(
      color: Color(0xFFF18A00),
      borderRadius: BorderRadius.only(
          bottomRight: Radius.circular(8), bottomLeft: Radius.circular(8)),
    ),
    child: SizedBox.expand(
        child: TextButton(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("Entrar", style: TextStyle(color: Color(0xFFFFFFFF)))
              ],
            ),
            onPressed: _submitEmail)));

final forgotPassword = Container(
  height: 40,
  alignment: Alignment.center,

  //child: FlatButton(
  //style: TextStyle(color: Color(0xFF45CAD0))),
  // onPressed: () => {},
);

return Scaffold(
  backgroundColor: Color.fromRGBO(248, 248, 248, 1),
  body: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      ListView(
        //physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        padding: EdgeInsets.only(left: 70, right: 70),
        children: <Widget>[
          logo,
          SizedBox(height: 30),
          email,
          password,
          button,
          SizedBox(height: 20),
          forgotPassword,
        ],
      ),
    ],
  ),
);

} }

I tried to insert below the "Enter" button and nothing happened.

Where am I going wrong?

flutter
dart
visual-studio-code
asked on Stack Overflow May 6, 2021 by Allan Alencar

2 Answers

1

replace the Column with Center(child:... and give your scaffold background static color

answered on Stack Overflow May 6, 2021 by biruk IS
1

If I understand correctly, you want to figure out where to place the code for "New Button". In that case, assign your new button container to a variable like this:

final newButton = Container(
    height: 30,
    alignment: Alignment.center,
    child: SizedBox.expand(
        child: TextButton(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("Cadastre-se", style: TextStyle(color: Colors.black))
              ],
            ),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) {
                    return RegisterName();
                  },
                ),
              );
            })));

Then, in your Current Code, you can put this variable inside the ListView like the other variables:

return Scaffold(
  backgroundColor: Color.fromRGBO(248, 248, 248, 1),
  body: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      ListView(
        //physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        padding: EdgeInsets.only(left: 70, right: 70),
        children: <Widget>[
          logo,
          SizedBox(height: 30),
          email,
          password,
          button,
          newButton,
          SizedBox(height: 20),
          forgotPassword,
        ],
      ),
    ],
  ),
);

So your final "Current Code" will be:

final button = Container(
    height: 50,
    alignment: Alignment.center,
    decoration: BoxDecoration(
      color: Color(0xFFF18A00),
      borderRadius: BorderRadius.only(
          bottomRight: Radius.circular(8), bottomLeft: Radius.circular(8)),
    ),
    child: SizedBox.expand(
        child: TextButton(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("Entrar", style: TextStyle(color: Color(0xFFFFFFFF)))
              ],
            ),
            onPressed: _submitEmail)));

final newButton = Container(
    height: 30,
    alignment: Alignment.center,
    child: SizedBox.expand(
        child: TextButton(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("Cadastre-se", style: TextStyle(color: Colors.black))
              ],
            ),
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) {
                    return RegisterName();
                  },
                ),
              );
            })));

final forgotPassword = Container(
  height: 40,
  alignment: Alignment.center,

  //child: FlatButton(
  //style: TextStyle(color: Color(0xFF45CAD0))),
  // onPressed: () => {},
);

return Scaffold(
  backgroundColor: Color.fromRGBO(248, 248, 248, 1),
  body: Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      ListView(
        //physics: const NeverScrollableScrollPhysics(),
        shrinkWrap: true,
        padding: EdgeInsets.only(left: 70, right: 70),
        children: <Widget>[
          logo,
          SizedBox(height: 30),
          email,
          password,
          button,
          newButton,
          SizedBox(height: 20),
          forgotPassword,
        ],
      ),
    ],
  ),
);
answered on Stack Overflow May 6, 2021 by Zac

User contributions licensed under CC BY-SA 3.0