-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdrop_down_menu.dart
95 lines (84 loc) · 2.32 KB
/
drop_down_menu.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import 'package:easy_popup/easy_popup.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
class DropDownMenu extends StatefulWidget with EasyPopupChild {
final _PopController controller = _PopController();
@override
_DropDownMenuState createState() => _DropDownMenuState();
@override
dismiss() {
controller.dismiss();
}
}
class _DropDownMenuState extends State<DropDownMenu>
with SingleTickerProviderStateMixin {
Animation<Offset> _animation;
AnimationController _controller;
@override
void initState() {
super.initState();
widget.controller._bindState(this);
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 300),
);
_animation = Tween<Offset>(begin: Offset(0, -1), end: Offset.zero)
.animate(_controller);
_controller.forward();
}
dismiss() {
_controller?.reverse();
}
@override
void dispose() {
super.dispose();
_controller?.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.transparent,
body: Container(
padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 50),
child: ClipRect(
child: SlideTransition(
position: _animation,
child: Container(
color: Colors.white,
child: ListView.builder(
padding: EdgeInsets.all(0),
shrinkWrap: true,
itemCount: 4,
itemExtent: 50,
itemBuilder: (context, index) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Fluttertoast.showToast(msg: 'item$index');
EasyPopup.pop(context);
},
child: Container(
alignment: Alignment.center,
child: Text(
'item$index',
),
),
);
},
),
),
),
),
),
);
}
}
class _PopController {
_DropDownMenuState state;
_bindState(_DropDownMenuState state) {
this.state = state;
}
dismiss() {
state?.dismiss();
}
}