flutter 它只显示它的背景组件,为什么不显示身体组件?

pieyvz9o  于 2022-11-17  发布在  Flutter
关注(0)|答案(2)|浏览(155)

当我按下登录,它触发了这个主体文件,但它只显示背景png。它没有显示主体文件的内容。
background.dart

class Login_Background extends StatelessWidget {
  const Login_Background({required this.size, required Column child});

  final Size size;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned(
            top: 0,
            left: 0,
            child: Image.asset(
              "android/assets/images/login_top.png",
              width: size.width * .22,
            )),
        Positioned(
            bottom: 0,
            right: 0,
            child: Image.asset(
              "android/assets/images/login_bottom.png",
              width: size.width * 0.31,
            )),
      ],
    );
  }
}

身体.省道

class body extends StatelessWidget {
  const body({
    Key? key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;

    return Login_Background(
        size: size,
        child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text(
                "login",
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
              SizedBox(height: size.height*0.03),
              Image.asset(
                "android/assets/images/12085707_20944201.jpg",
                height: 400,
                width: 100,
              ),
              RoundedInputField(
                hintText: 'Your Email',
                onChanged: (String value) {},
                icon: Icons.person,
              ),
              Rounded_password_field(
                onChanged: (String value) {},
              ),
              Roundedbutton(
                text: "login",
                press: () {},
                color: kPrimaryColor,
                textColor: kPrimaryColor,
              ),
              already_have_an_accountcheck(press: (){},)
            ]));
  }
}

我希望在单击登录时看到主体组件。

enyaitl3

enyaitl31#

您忘记将子项添加到Login_Background内的堆栈:

return Stack(
      children: [
        Positioned(
            top: 0,
            left: 0,
            child: Image.asset(
              "android/assets/images/login_top.png",
              width: size.width * .22,
            )),
        Positioned(
            bottom: 0,
            right: 0,
            child: Image.asset(
              "android/assets/images/login_bottom.png",
              width: size.width * 0.31,
            )),
        // add this
        Positioned.fill(                 
            child : child
        )

      ],
    );
5sxhfpxr

5sxhfpxr2#

您尚未在Login_Background的构建方法中使用其构造函数中传递的child参数。

相关问题