如何在flutter中将onTap()或onPressed()添加到ExpansionTileCard?

时间:2020-06-06 14:35:09

标签: listview flutter

我正在为ExpansionTileCard小部件使用ListView.Builder,我可以使用它生成列表,但是如果用户按下列表中的项目然后执行FlutterToast操作,则无法添加功能,我试图用flutter包找到解决方案,但没有成功

请指导我该怎么做。

  child:  ExpansionTileCard(

    leading: CircleAvatar(child: Image.network(widget.Picurl)),
    title: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Text("text1"),
        Text('text2'),
      ],
    ),
    subtitle: Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            Text("Text1"),
            SizedBox(width: 5,),
            Text("Text2")
          ],
        ),

      ],
    ),
    children: <Widget>[
      Divider(
        thickness: 1.0,
        height: 1.0,

      ),
      Align(
        alignment: Alignment.centerLeft,
        child: Padding(
          padding: const EdgeInsets.symmetric(
            horizontal: 16.0,
            vertical: 8.0,
          ),
          child: Text(
          widget.postcontent,
            style: Theme.of(context)
                .textTheme
                .body1
                .copyWith(fontSize: 16),
          ),
        ),
      ),
      ButtonBar(
        alignment: MainAxisAlignment.spaceAround,
        buttonHeight: 52.0,
        buttonMinWidth: 90.0,
        children: <Widget>[
          FlatButton(
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(4.0)),
            onPressed: () {


               },
            child: Column(
              children: <Widget>[
                Icon(Icons.star),
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 2.0),
                ),
                Text('Button1'),
              ],
            ),
          ),
          FlatButton(
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(4.0)),
            onPressed: () {



            },
            child: Column(
              children: <Widget>[
                Icon(Icons.open_in_browser),
                Padding(
                  padding: const EdgeInsets.symmetric(vertical: 2.0),
                ),
                Text('Button2'),

              ],
            ),
          ),

        ],
      ),
    ],
  ),

3 个答案:

答案 0 :(得分:1)

只需将要注册点击或按下手势的小部件放在GestureDetector小部件中,然后为所需的手势事件选择适当的回调

GestureDetector(
   onTap: () {
       // your code here
   },
   child: ExpansionTileCard(
       ........
   ),
),

有关更多详细信息和手势选项:https://api.flutter.dev/flutter/widgets/GestureDetector-class.html

答案 1 :(得分:0)

尝试使用GestureDetector包装。

答案 2 :(得分:0)

如果要在轻敲窗口小部件时产生波纹效果,则应将窗口小部件包装在2020-06-06T16:19:18.883352+00:00 app[web.1]: File "/app/__init__.py", line 4, in <module> 2020-06-06T16:19:18.883352+00:00 app[web.1]: from flask import Flask, flash, jsonify, redirect, render_template, session, url_for, request 2020-06-06T16:19:18.883353+00:00 app[web.1]: ModuleNotFoundError: No module named 'flask' 2020-06-06T16:19:18.883432+00:00 app[web.1]: [2020-06-06 16:19:18 +0000] [9] [INFO] Worker exiting (pid: 9) 2020-06-06T16:19:18.908691+00:00 app[web.1]: [2020-06-06 16:19:18 +0000] [4] [INFO] Shutting down: Master 2020-06-06T16:19:18.908782+00:00 app[web.1]: [2020-06-06 16:19:18 +0000] [4] [INFO] Reason: Worker failed to boot.

这里是-

data = train
corr = data.corr()
columns = np.full((corr.shape[0],), True, dtype=bool)
for i in range(corr.shape[0]):
    for j in range(i+1, corr.shape[0]):
        if corr.iloc[i,j] >= 0.9:
            if columns[j]:
                columns[j] = False
selected_columns = data.columns[columns]
data = data[selected_columns]