我目前正在Flutter开发一款Android应用.如何添加圆形按钮,类似于此?http://pertamini.co/rounded-button/
我只是有一个简单的卡片new Card(child: new Text('My cool card')),我希望能够点击它上面的任何地方运行一些功能,除了没有onPressed卡的方法.我可以在底部添加一个按钮,但这对于这种情况并不理想.
任何人都知道如何使整张卡可点击?
当用户点击瓷砖时,我正试图InkWell在图像顶部使用涟漪效果GridTile.
我相信图像本身会模糊纹波,因为当我移除图像时,我看到了波纹.
下面是单个GridTile的代码.
return new InkWell(
onTap: () => debugPrint(s.displayName),
highlightColor: Colors.pinkAccent,
splashColor: Colors.greenAccent,
child: new GridTile(
footer: new GridTileBar(
title: new Text(s.displayName),
subtitle: new Text(s.gameName),
backgroundColor: Colors.black45,
trailing: new Icon(
Icons.launch,
color: Colors.white,
),
),
child: new Image.network( //this is obscuring the InkWell ripple
s.imageSrc,
fit: BoxFit.cover,
),
),
);
Run Code Online (Sandbox Code Playgroud)
我已经尝试将InkWell移动到层次结构的不同级别,使用DecorationImage内部a Container,但这些似乎都无法揭示波纹.
如何让纹波出现在图块/图像的顶部?
有与此主题相关的答案,但它们提供了解决方法而不是解释。
为什么不能在需要 ImageProvider 的地方使用 Image?从概念上讲,它们对我来说听起来是一样的。
child: new CircleAvatar(
backgroundImage: NetworkImage("https..."), // works
backgroundImage: Image.asset('images/image.png'), // error
),
Run Code Online (Sandbox Code Playgroud)
尝试直接使用图像产生的错误是:
错误:无法将参数类型“Image”分配给参数类型“ImageProvider”。
我的场景中有一个数据表。我想当用户将鼠标悬停在任何行上时更改行的背景颜色。我在 flutter.dev 上找到了几个示例,但没有一个有效。
例如,看下面的代码(完整代码)。虽然我将绿色作为背景颜色,但当我将鼠标悬停在行上时,它不会变成蓝色。
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return DataTable(
dataRowColor: MaterialStateProperty.resolveWith(_getDataRowColor),
columns: const <DataColumn>[
DataColumn(
label: Text(
'Name',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Age',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Role',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
],
rows: <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(Text('Sarah')),
DataCell(Text('19')),
DataCell(Text('Student')),
],
onSelectChanged: (isSelected) => {
print('Item 1 clicked!')
},
),
DataRow(
cells: <DataCell>[
DataCell(Text('Janine')),
DataCell(Text('43')), …Run Code Online (Sandbox Code Playgroud) 我知道在小部件之后onPressed和之后调用函数的语法onTap。有两个选项,我们可以使用() => function()或() { function(); }语法。空括号是什么意思?
我想在项目上添加涟漪,在我使用对该项目添加渐变之前,它工作正常BoxDecoration。
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Material(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)),
elevation: 6.0,
shadowColor: Colors.grey[50],
child: InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: AlignmentDirectional.bottomStart,
end: AlignmentDirectional.topEnd,
colors: [
Colors.yellow[800],
Colors.yellow[700],
],
),
),
padding: EdgeInsets.all(16.0),
child: Text(
widget.title,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
),
),
),
);
}
Run Code Online (Sandbox Code Playgroud) 在 Flutter 中,我想用圆形边框设计图标按钮的样式,并让 Material 涟漪效果正常工作,以便涟漪效果包含在圆圈中。在下面的代码中,第一个按钮工作正常。在第二个(弹出)按钮中,涟漪效果延伸到围绕按钮的正方形,而不是被限制在圆形边框上。
MaterialApp(
home: Scaffold(
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 2),
shape: BoxShape.circle,
),
child: MaterialButton(
minWidth: 0,
padding: EdgeInsets.all(0.0),
child: Padding(
padding: EdgeInsets.all(11.0),
child: Icon(Icons.home, size: 27.0),
),
shape: CircleBorder(),
onPressed: () {},
),
),
PopupMenuButton<String>(
onSelected: (String action) {},
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 2),
shape: BoxShape.circle,
),
child: Padding(
padding: EdgeInsets.all(11.0),
child: Icon(Icons.menu, size: 27.0),
),
),
itemBuilder: (BuildContext context) => …Run Code Online (Sandbox Code Playgroud)