#flutter #popup #gesture-recognition
Вопрос:
Я работаю над проектом flutter и хочу, чтобы всплывающее окно создавалось при нажатии на определенную плитку. Это мой код
Это мой генератор списков
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();
}
Я попытался обернуть Record
с помощью GestureDetector и чернильницы, но получил только ошибки, и Android Studio сообщает мне, что Record
в этом контексте этого не ожидается. Я поискал в Интернете и не смог найти ничего по этому вопросу. Пожалуйста, помогите.
Ответ №1:
Запись, насколько я вижу, это просто модель, а не виджет. Для создания элементов требуется виджет. Вы должны обернуть то, что вы передаете в конструктор элементов, с помощью фактического виджета, такого как контейнер (), список () и т. Д. Эти виджеты могут быть обернуты детектором жестов для выполнения всплывающих окон, которые вы хотите.
Это выглядело бы так
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),
),
);
},
);