【发布时间】:2018-08-18 06:51:10
【问题描述】:
我正在编写我的第一个带有 Flutter 的应用程序,但遇到了 InkWell 在被点击时无法检测到的问题。这是一个比我找不到示例更复杂的结构。我写了以下函数:
class ChatOverviewElements {
static Widget buildChatEntry(BuildContext context, String username,
String lastMessageText,
String lastMessageDate, bool group,
int unread, int chatID) {
return new Material(
child: new Ink(
padding: const EdgeInsets.only(right: 32.0),
child: new InkWell(
onTap: ChatOverviewNavigation.openChat(context, chatID),
child: new Row(
children: <Widget>[
new Container(
padding: const EdgeInsets.all(10.0),
child: new Icon(
Icons.account_circle,
size: 60.0,
),
),
new Expanded (
child: new Container(
padding: const EdgeInsets.only(right: 5.0),
height: 60.0,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Row(
children: <Widget>[
group ? new Icon(Icons.group) : new Container(),
new Container(width: group ? 10.0 : 0.0,),
TextStyles.username(username),
],
),
TextStyles.chatSnippet(lastMessageText),
],
),
),
),
new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Icon(
Icons.done_all,
color: Colors.green,
),
new Container(width: 8.0,),
TextStyles.chatDate(lastMessageDate),
]),
new Icon(
Icons.thumb_up,
color: Colors.grey[500],
)
],
),
],
),
),
),
);
}
}
它会创建一个类似于您在 WhatsApp 等中看到的框,其中包含用户名、消息预览、未读标记(大拇指图标是一个占位符)等等。我希望那个外部容器可以点击,所以我改变了它和 Ink(查看波纹)并添加了 InkWell 和其他所有东西作为那个井的孩子。那是行不通的。它没有检测到所有的水龙头,我不明白为什么。
调用 build 函数来创建 ListView 的子项,该子项本身嵌套在 Scaffold 和 Material App 中。不过这不重要,我在 ListView 中尝试了 StackOverflow 中的简单示例,并且这些示例运行良好。
所以问题是:我在这里做错了什么? InkWell 必须在哪里才能使整个容器可以点击并且在容器背景上显示波纹?
【问题讨论】:
标签: android user-interface dart flutter