【问题标题】:LinearGradient button figma to flutterLinearGradient 按钮 figma 颤动
【发布时间】:2022-01-20 08:13:02
【问题描述】:

我的 CSS:

background: linear-gradient(91.97deg, #F8A170 14.73%, #FFCD61 97.52%);
border-radius: 10px; 

我想使用颤振,但是当我将这些颜色提供给带有子提升按钮的容器小部件时,我无法获得我想要的结果。我将按钮样式设置为透明,但还是无法解决。

【问题讨论】:

标签: css flutter


【解决方案1】:

根据你的图片和css,你可以简单的装饰ElevatedButton的样式。

 DecoratedBox(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(10),
            gradient: const LinearGradient(
              colors: [
                Color(0xFFF8A170),
                Color(0xFFFFCD61),
              ],
            ),
          ),
          child: SizedBox(
            width: 400,
            height: 75,
            child: ElevatedButton(
              style: ElevatedButton.styleFrom(
                elevation: 0,
                primary: Colors.white.withOpacity(0),
                padding: const EdgeInsets.all(0),
              ),
              onPressed: () {},
              child: const Text(
                "Search a room",
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                  fontSize: 22,
                ),
              ),
            ),
          ),
        ),

更多关于 DecoratedBox 和 ElevatedButton

【讨论】:

  • 兄弟,你能用容器小部件的孩子的提升按钮来做吗?
  • 我想我们可以装饰一下,让我试试,否则你可以用可点击的小部件包裹这个小部件来完成工作。
  • 用样式方法完成
【解决方案2】:

请参考以下示例代码

使用提升按钮

LinearGradient yellowLinearGradientValues() {
    return LinearGradient(
      colors: [Colors.orange, Color(0xffFFB800).withOpacity(0.65)],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {},
          style: ElevatedButton.styleFrom(
            elevation: 0.0,
            padding: EdgeInsets.zero,
            primary: Colors.transparent,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8.0),
            ),
            side: BorderSide(
              width: 0.0,
              color: Colors.orange,
              style: BorderStyle.none,
            ),
            tapTargetSize: MaterialTapTargetSize.shrinkWrap,
          ),
          child: Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(
                Radius.circular(8.0),
              ),
              gradient: yellowLinearGradientValues(),
            ),
            child: Padding(
              padding: EdgeInsets.symmetric(
                horizontal: 40.0,
                vertical: 8.0,
              ),
              child: Text(
                "Search a Room" ?? "",
                textAlign: TextAlign.start,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                  fontSize: 24.0,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

LinearGradient yellowLinearGradientValues() {
    return LinearGradient(
      colors: [Colors.orange, Color(0xffFFB800).withOpacity(0.7)],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {},
          style: ButtonStyle(
            backgroundColor: MaterialStateProperty.all(Colors.transparent),
            elevation: MaterialStateProperty.all(0.0),
            padding: MaterialStateProperty.all(EdgeInsets.zero),
            tapTargetSize: MaterialTapTargetSize.shrinkWrap,
          ),
          child: Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.all(
                Radius.circular(8.0),
              ),
              gradient: yellowLinearGradientValues(),
            ),
            child: Padding(
              padding: EdgeInsets.symmetric(
                horizontal: 40.0,
                vertical: 8.0,
              ),
              child: Text(
                "Search a Room" ?? "",
                textAlign: TextAlign.start,
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
                style: TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                  fontSize: 24.0,
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }

【讨论】:

  • 兄弟,你能用容器小部件的孩子的提升按钮来做吗?
  • 请检查编辑后的代码,如果它符合您的要求,请告诉我
  • 感谢兄弟,但当我尝试使用提升按钮.styleform 时,我无法编辑:我忘记了海拔 :(
  • 我使用了提升按钮。请检查
  • 请使用 ElevatedButton.styleFrom style: ElevatedButton.styleFrom( elevation: 0.0, padding: EdgeInsets.zero, primary: Colors.transparent, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8.0), ), side: BorderSide( width: 0.0, color: Colors.orange, style: BorderStyle.none, ), tapTargetSize: MaterialTapTargetSize.shrinkWrap, ),检查修改后的代码
猜你喜欢
  • 2021-12-24
  • 2022-01-13
  • 1970-01-01
  • 2020-08-05
  • 2020-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-28
相关资源
最近更新 更多