有没有一种方法可以创建具有圆角半径,渐变和动态阴影的按钮?

时间:2019-02-05 03:41:22

标签: flutter

我正在创建一个具有拐角半径和渐变的按钮,但是我也希望它的阴影在用户按下并释放时做出反应。我正在尝试一个带装饰的容器,但是没有运气,因为我似乎找不到onRelease回调。所以我在想我走错了方向。那么有什么办法吗?

1 个答案:

答案 0 :(得分:1)

此按钮正是我需要的: 渐变,圆角,动态阴影,波纹效果Padding( padding: const EdgeInsets.only(bottom: 50), child: Transform.scale( scale: btnScale, child: GestureDetector( onTapCancel: () { setState(() {}); btnHeight = 5; btnScale = 1.0; }, onTapDown: (loc) { btnHeight = 0; btnScale = 0.99; setState(() {}); }, onTapUp: (loc) { setState(() {}); btnHeight = 5; btnScale = 1.0; }, child: Container( width: 190, height: 62, decoration: BoxDecoration( boxShadow: [ new BoxShadow( blurRadius: 4, color: Colors.black12, offset: new Offset( -btnHeight, btnHeight), ), new BoxShadow( blurRadius: 4, color: Colors.black12, offset: new Offset( btnHeight, btnHeight), ) ], borderRadius: BorderRadius.all( Radius.circular(100)), gradient: BtnTeal), child: Material( color: Colors.transparent, child: InkWell( borderRadius: (BorderRadius.circular(100)), onTap: () {}, highlightColor: const Color(0xFF63DCA0), splashColor: Colors.teal, child: Center( child: Text( "LOG IN", style: TextStyle( fontWeight: FontWeight.bold, color: Colors.white, fontSize: 21, ), ), ), ), ), ), ), ), ),