【问题标题】:Flutter : Popup for each ListtileFlutter:每个 Listtile 的弹出窗口
【发布时间】:2021-09-20 12:54:51
【问题描述】:

我正在处理一个颤振项目,我想在单击特定磁贴时弹出以生成。这是我的代码

这是我的 ListTile 生成器

Future<Widget> getRecordView()  {
      print("405 name " + name.toString());
      print(nameArr);
      var items = List<Record>.generate(int.parse(widget.vcont), (index) => Record(
        name: nameArr[index],
        type: typeArr[index],
        address: addressArr[index],
        state: stateArr[index],
        phone:phoneArr[index],
        city: cityArr[index],
        id: idArr[index],
      ));
      print("Started");
      var listItems =  items;
      var listview = ListView.builder(
          itemCount: int.parse(widget.vcont),
          itemBuilder: (context,index){
            return listItems[index] ;
          }
      );
      return Future.value(listview);
  }

我需要的弹出窗口:

Future <bool> details(BuildContext context,String type) {
    return  Alert(
      context: context,
      type: AlertType.success,
      title: "Submission",
      desc: type,  //The parameter
      buttons: [
        DialogButton(
          child: Text(
            "OKAY",
            style: TextStyle(color: Colors.white, fontSize: 20),
          ),
          onPressed: () => Navigator.pop(context),
          color: Color.fromRGBO(0, 179, 134, 1.0),
          radius: BorderRadius.circular(0.0),
        ),
      ],
    ).show();
  }

我尝试使用 GestureDetector 和 Inkwell 包装 Record,但我只收到了错误,Android Studio 告诉我在这种情况下不需要 Record。我在互联网上查找并找不到任何关于这件事的信息。请帮忙。

【问题讨论】:

    标签: flutter popup gesture-recognition


    【解决方案1】:

    记录,据我所知,它只是一个模型,而不是一个小部件。项目生成器需要一个小部件。您应该使用一个实际的小部件(如 Container()、ListTile()、.. 等)包装您传递给项目构建器的内容。这些小部件可以用 Gesture Detector 包装以执行您想要的弹出窗口。

    应该是这样的

    var listview = ListView.builder(
       itemCount: items.length,
       itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              // Tap on an item in the list and this will get executed.
            },
            // Return an actual widget, I'm using a ListTile here, but you can
            // use any other type of widget here or a create custom widget.
            child: ListTile(
              // this will display the record names as list tiles.
              title: Text(items[index].name),
          ),
        );
      },
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 2021-05-01
      • 2012-12-12
      • 1970-01-01
      相关资源
      最近更新 更多