简体   繁体   English

Flutter:每个 Listtile 的弹出窗口

[英]Flutter : Popup for each Listtile

I am working on a flutter project and I want to popup to get generated on clicking a particular tile.我正在处理一个颤振项目,我想在单击特定磁贴时弹出以生成。 This is my code这是我的代码

This is my ListTile generator这是我的 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);
  }

The Popup I need on tap :我需要的弹出窗口:

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();
  }

I tried to wrap Record with GestureDetector and Inkwell, but I only got errors and Android Studio tells me that Record is not expected in that context.我尝试使用 GestureDetector 和 Inkwell 包装Record ,但我只遇到错误,Android Studio 告诉我在该上下文中不期望Record I looked up in the internet and couldnt find anything on this matter.我在互联网上查了一下,找不到关于这件事的任何信息。 Please help.请帮忙。

Record, as far I can see is just a model, and not a widget.记录,据我所知只是一个模型,而不是一个小部件。 Item Builder requires a widget. Item Builder 需要一个小部件。 You should wrap what you are passing to the item builder with an actual widget like a Container(), ListTile(), .. etc. These widgets can be wrapped with Gesture Detector to perform the pop ups you want.您应该使用实际的小部件(如 Container()、ListTile() 等)包装您传递给项目构建器的内容。这些小部件可以使用 Gesture Detector 包装以执行您想要的弹出窗口。

It would look like this它看起来像这样

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),
      ),
    );
  },
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM