import
'package:flutter/material.dart'
;
import
'package:popover/popover.dart'
;
void
main() => runApp(MyApp());
class
MyApp extends StatelessWidget {
const
MyApp({super.key});
@override
Widget build(BuildContext context) {
return
MaterialApp(
theme: ThemeData(
primarySwatch: Colors.green,
),
debugShowCheckedModeBanner:
false
,
home: PopoverExample(),
);
}
}
class
PopoverExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
Scaffold(
appBar: AppBar(title:
const
Text(
'Popover Example'
)),
body: SafeArea(
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
PopoverButton(),
],
),
),
),
);
}
}
class
PopoverButton extends StatelessWidget {
const
PopoverButton({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return
Center(
child: Container(
width: 150,
height: 60,
decoration:
const
BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(
Radius.circular(8)),
boxShadow: [
BoxShadow(color: Colors.black26, blurRadius: 5)
],
),
child: GestureDetector(
child:
const
Center(
child: Text(
'Show Popover'
,
style: TextStyle(color: Colors.white),
),
),
onTap: () {
showPopover(
context: context,
bodyBuilder: (context) =>
const
ListItems(),
onPop: () => print(
'Popover was popped!'
),
direction:
PopoverDirection.bottom,
width: 200,
height: 250,
arrowHeight: 15,
arrowWidth: 30,
);
},
),
),
);
}
}
class
ListItems extends StatelessWidget {
const
ListItems({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return
Padding(
padding:
const
EdgeInsets.symmetric(vertical: 8),
child: ListView(
padding:
const
EdgeInsets.all(8),
children: [
InkWell(
onTap: () {
Navigator.of(context)
..pop()
..push(
MaterialPageRoute<SecondRoute>(
builder: (context) => SecondRoute(),
),
);
},
child: Container(
height: 50,
color: Colors.amber[100],
child:
const
Center(child: Text(
'Entry A'
)),
),
),
const
Divider(),
Container(
height: 50,
color: Colors.amber[200],
child:
const
Center(child: Text(
'Entry B'
)),
),
const
Divider(),
Container(
height: 50,
color: Colors.amber[300],
child:
const
Center(child: Text(
'Entry C'
)),
),
],
),
);
}
}
class
SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return
Scaffold(
appBar: AppBar(
title:
const
Text(
'Second Route'
),
automaticallyImplyLeading:
false
,
),
body: Center(
child: ElevatedButton(
onPressed: () => Navigator.pop(context),
child:
const
Text(
'Back'
),
),
),
);
}
}