Hope to have what you need

Flutter 悬浮弹出效果

    Flutter

最近在 Flutter 的使用中需要做一个悬浮弹窗的效果。通过查阅资料了解 Overlay 可以做出悬浮框的效果,但没有弹出效果,不符合我的预期。后来发现其实并不一定要真的悬浮,通过 showModalBouttonSheet方法和 Stack组件,可以模拟出这样的效果。

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
Future _createSelectViewWithContext() async {
//屏幕宽高
RenderBox renderBox = context.findRenderObject();
var screenSize = renderBox.size;
final option = await showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, state) {
return Stack(
alignment: AlignmentDirectional.topCenter,
children: <Widget>[
Container(
color: Colors.black54,
height: screenSize.height * 0.37,
width: double.infinity,
),
Container(
height: screenSize.height * 0.35,
width: screenSize.width * 0.95,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20.0))),
child: Column(
children: <Widget>[
Text(
'This is a title',
style: TextStyle(color: Colors.grey, fontSize: 25),
),
Divider(),
Expanded(
child: ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.home),
title: Text('home'),
trailing: RaisedButton(
onPressed: () {},
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text('botton')),
),
ListTile(
leading: Icon(Icons.hotel),
title: Text('hotel'),
trailing: RaisedButton(
onPressed: () {},
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text('botton')),
),
],
))
],
),
)
]);
});
});
}
在这里插入图片描述
page PV:  ・  site PV:  ・  site UV: