You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter登录页面仅显示背景组件,未加载body组件问题

问题解决:Flutter登录页面仅显示背景,不展示表单内容

问题根源

Login_Background组件虽然在构造函数中定义了child参数,但在build方法的Stack子组件列表里完全没有使用这个参数,导致传入的表单内容根本没有被渲染,只显示了两张背景图。

修复代码

修改background.dart文件,将传入的child添加到Stack中,确保内容能正常显示:

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

  final Size size;
  final Widget child;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        // 让表单内容铺满整个屏幕,作为底层内容
        Positioned.fill(
          child: child,
        ),
        // 左上角背景图
        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,
            )),
      ],
    );
  }
}

额外优化建议

  1. 遵循Dart命名规范,将body类名改为Body(首字母大写)
  2. 将Login_Background的child参数类型从Column改为Widget,让组件支持传入任意类型的子组件,提升复用性

内容的提问来源于stack exchange,提问作者Mohammad Ibrahim Khalil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 13:12:02