svg图像作为颤动中的按钮 [英] svg image as button in flutter
问题描述
我创建了一个播放按钮,并将其另存为svg文件.
I created a play-button and saved it as a svg dokument.
我还创建了主屏幕,其中的背景图片和居中的floatActionButton.(我为此使用了堆栈).
I have also created my home screen with a picture in the background and a floatingActionButton centered. (I used stack for this).
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吗?如果是,请问如何获得此帮助或者我应该从哪里开始寻找如何获得帮助?
My question is: Can I use my svg-image as button instead of my current floatingActionButton? If yes, can I please get some help how to do this or where I should start looking for how to do this?
我仍然希望背景图片和居中按钮:)
I still want my background picture and a centered button :)
谢谢!
推荐答案
您可以使用手势检测器
向Flutter中的任何窗口小部件添加点击功能:
You can use the Gesture Detector
to add click functionality to any Widget in Flutter:
GestureDetector(
onTap: () {
print("onTap called.");
},
child: Text("foo"),
),
并且子svg窗口小部件就像使用此lib一样简单(因为flutter仍然不支持本机SVG): https://pub.dev/packages/flutter_svg
And the child svg Widget is as simple as using this lib (since flutter still doesn't have native SVG support): https://pub.dev/packages/flutter_svg
这篇关于svg图像作为颤动中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!