【问题标题】:Overlap leading Icon on form input field in flutter颤动中表单输入字段上的重叠前导图标
【发布时间】:2021-08-11 16:11:59
【问题描述】:

尝试在 Flutter 中实现这种登录方式。有任何想法吗?尝试使用前缀图标和行,但没有真正得到它。 Example Login Image

【问题讨论】:

  • 发布您的尝试和平台成员的贡献。这不是 stackoverlow 的工作方式

标签: flutter user-interface dart flutter-layout


【解决方案1】:

您可以将Stack 与两个孩子一起使用,一个用于前导图标,另一个用于文本输入。我写了你需要的代码来实现你想要的。所以,我将与您分享。您只需根据自己的喜好设置颜色和文本样式。

我们开始...

Column(
  children: <Widget>[
    Stack(
      children: <Widget>[
        Container(
          margin: EdgeInsets.symmetric(vertical: 6.0),
          height: 36.0,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(24.0),
            boxShadow: [BoxShadow(blurRadius: 12.0)],
          ),
          child: Padding(
            padding: EdgeInsets.fromLTRB(70.0, 0.0, 30.0, 0.0),
            child: TextFormField(
              decoration: InputDecoration(
                contentPadding: EdgeInsets.symmetric(vertical: 8.0),
                border: InputBorder.none,
                hintText: 'Username',
              ),
            ),
          ),
        ),
        Container(
          decoration: BoxDecoration(
            color: Colors.white,
            shape: BoxShape.circle,
            boxShadow: [BoxShadow(blurRadius: 12.0)],
          ),
          child: Padding(
            padding: EdgeInsets.all(12.0),
            child: Icon(Icons.person_outline),
          ),
        ),
      ],
    ),
    SizedBox(height: 12.0),
    Stack(
      children: <Widget>[
        Container(
          margin: EdgeInsets.symmetric(vertical: 6.0),
          height: 36.0,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(24.0),
            boxShadow: [BoxShadow(blurRadius: 12.0)],
          ),
          child: Padding(
            padding: EdgeInsets.fromLTRB(70.0, 0.0, 30.0, 0.0),
            child: TextFormField(
              decoration: InputDecoration(
                contentPadding: EdgeInsets.symmetric(vertical: 8.0),
                border: InputBorder.none,
                hintText: 'Password',
              ),
            ),
          ),
        ),
        Container(
          decoration: BoxDecoration(
            color: Colors.white,
            shape: BoxShape.circle,
            boxShadow: [BoxShadow(blurRadius: 12.0)],
          ),
          child: Padding(
            padding: EdgeInsets.all(12.0),
            child: Icon(Icons.lock_outline),
          ),
        ),
      ],
    ),
  ],
),

输出是这样的:

【讨论】:

  • 感谢您的帮助
  • @Samuel Paintsil 不客气。如果您认为答案是您正在寻找的解决方案,请将其标记为已回答。提前致谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-22
  • 2017-05-19
  • 2020-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多