我创建了一个播放按钮,并将其另存为svg文档。
我还创建了主屏幕,其中的背景图片和居中的floatActionButton。 (我为此使用堆栈)。
import 'package:flutter/material.dart';
class MyBackgroundWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Stack(
children: <Widget>[
new Container(
child: new Image.asset('assets/Backgr.png'),
width: double.infinity,
height: double.infinity),
Center(
child: new FloatingActionButton(
child: new Icon(Icons.arrow_right),
backgroundColor: new Color(0xFFE57373),
onPressed: () {}),
),
],
);
}
}
我的问题是:我可以将svg图像用作按钮,而不是当前的floatActionButton吗?如果是,请问如何获得此帮助,或者我应该从哪里开始寻找如何做到这一点?
我仍然想要背景图片和居中按钮:)
谢谢!
最佳答案
您可以使用Gesture Detector
向Flutter中的任何窗口小部件添加点击功能:
GestureDetector(
onTap: () {
print("onTap called.");
},
child: Text("foo"),
),
子svg窗口小部件就像使用此lib一样简单(因为flutter仍然不支持 native SVG):
https://pub.dev/packages/flutter_svg
关于svg - svg图像作为颤动中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53973034/