PopupMenu In ListView
Complete Code For PopupMenu In ListView In Flutter
main.dart
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
MyHomePageState createState() {
return new MyHomePageState();
}
}
class MyHomePageState extends State<MyHomePage> {
List<String> _texts = [
"BajarangiSoft.com",
"google.com",
"youtube.com",
"yahoo.com",
"gmail.com",
"flutter.dev",
];
_showPopupMenu() async {
await showMenu(
context: context,
position: RelativeRect.fromLTRB(100, 400, 100, 400),
items: [
PopupMenuItem(
child: Text("Menu 1"),
),
PopupMenuItem(
child: Text("Menu 2"),
),
PopupMenuItem(
child: Text("Menu 3"),
),
],
elevation: 8.0,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.blue[900],
title: Text(" PopupMenu In ListView"),
),
body: ListView(
children: _texts
.map((t) => ListTile(
title: Text(t,style: TextStyle(color: Colors.white),),
onTap: _showPopupMenu,
))
.toList(),
),
);
}
}