flutter 如何将RichText与屏幕底部中心对齐?

mcdcgff0  于 2022-12-14  发布在  Flutter
关注(0)|答案(1)|浏览(296)

我尝试使用Align(对齐方式:Alignment.bottomCenter,但它不起作用。从我上的课做这个,他所有的是一个大小的框,以适应它在屏幕的底部。但这是不工作的不同屏幕大小。
这里是SingleChildScrollView里面的所有内容。RichText在底部附近。(从注册屏幕更改为我的登录屏幕,因为它的代码更少)。

Widget build(BuildContext context) => SingleChildScrollView(
        padding: EdgeInsets.symmetric(vertical: 45, horizontal: 50),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(height: 50),
            Image(
              image: AssetImage('assets/image.jpg'),
            ),
            
            SizedBox(height: 50),

             TextFormField(
              style: TextStyle(color: Colors.white),
              controller: emailController,
              textInputAction: TextInputAction.next,
              decoration: InputDecoration(
                hintText: "Enter Email",
                hintStyle: TextStyle(color: Color(0xFFD6D6D6)),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.white),
                ),
              ),
              keyboardType: TextInputType.emailAddress,
             ),

            SizedBox(height: 4),

            TextFormField(
              style: TextStyle(color: Colors.white),
              controller: passwordController,
              obscureText: isHiddenPassword,
              textInputAction: TextInputAction.done,
              decoration: InputDecoration(
                hintText: "Enter Password",
                hintStyle: TextStyle(color: Color(0xFFD6D6D6)),
                enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.white),
                ),
                suffixIcon: InkWell(
                  onTap: _togglePasswordView,
                  child: Icon(
                      isHiddenPassword
                          ? Icons.visibility_outlined
                          : Icons.visibility_off_outlined,
                      color: Colors.white),
                ),
              ),
            ),
    
            SizedBox(height: 20),
            ElevatedButton(
              style: ElevatedButton.styleFrom(

                minimumSize: Size.fromHeight(40),
                primary: Colors.white,
              ),
              
              child: Text(
                'Sign In',
                style: TextStyle(
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                    color: Color(0xFF162242)),
              
              ),
              onPressed: signIn, 
            ),
            
            SizedBox(height: 20),
            SignInButton(
              Buttons.Facebook, onPressed: () {},
              text: "Sign in with Facebook",
              ),

              SizedBox(height: 16),

            SignInButton(
              Buttons.Google,
              text: "Sign in with Google",
              onPressed: () {
                signInWithGoogle();
              },
            ),
            SizedBox(height: 20),
            GestureDetector(
              child: Text(
                'Forgot Password?',
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 18,
                decoration: TextDecoration.underline,
                          color: Colors.white,
                ),
              ),
              onTap: () => Navigator.of(context).push(MaterialPageRoute(
                builder: (context) => ForgotPasswordPage(),
              )),
            ),
            // SizedBox(
            //   height: 100),
            Align(
              alignment: Alignment.bottomCenter,
              child: RichText(
                text: TextSpan(
                  style: TextStyle(color: Color(0xFFD6D6D6), fontSize: 20),
                  text: 'No account?  ',
                  children: [
                    TextSpan(
                      recognizer: TapGestureRecognizer()
                        ..onTap = widget.onClickedSignUp,
                      text: 'Sign Up',
                      style: TextStyle(
                        decoration: TextDecoration.underline,
                          fontWeight: FontWeight.bold,
                          color: Colors.white,
                        ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      );

感谢您抽出宝贵时间!

rqqzpn5f

rqqzpn5f1#

可以使用Spacer将子对象推到Column的末尾,如下所示:

Column(
  children: [
    Container(
      height: 200,
      color: Colors.black,
    ),
    Container(
      height: 200,
      color: Colors.green,
    ),
    Spacer(),
    RichText(
      textAlign: TextAlign.center,
      text: TextSpan(
        text: 'Already have an account?',
        style: TextStyle(color: Colors.black),
        children: [
          TextSpan(
            text: 'Sign In',
          )
        ],
      ),
    ),
  ],
)

相关问题