/
main.dart
135 lines (118 loc) · 3.71 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import 'package:flutter/material.dart';
import 'package:g2x_positioned_relative_to_child/g2x_positioned_relative_to_child.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late G2xPositionedRelativeToChild g2xPositionedRelativeWithBackdrop;
var g2xPositionedRelativeWithoutBackdrop = G2xPositionedRelativeToChild();
var globalKeyWithBackdrop = GlobalKey();
var globalKeyWithoutBackdrop = GlobalKey();
var opened = false;
_fechar() {
opened = !opened;
setState(() {});
}
@override
void initState() {
g2xPositionedRelativeWithBackdrop = G2xPositionedRelativeToChild(
callbackOnHide: _fechar,
closeOnTapOutside: true,
backdropColor: Colors.black12
);
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
children: [
Text("$opened"),
ElevatedButton(
key: globalKeyWithBackdrop,
child: const Text("With Backdrop"),
onPressed: () {
g2xPositionedRelativeWithBackdrop.show(
horizontalAxis: G2xHorizontalPositionAxis.center,
context: context,
parentKey: globalKeyWithBackdrop,
offSet: const Offset(-100, 0),
child: Container(
height: 50,
width: 200,
color: Colors.red,
child:
const
Center(
child:
Text(
"Child"
)
),
)
);
opened = true;
setState(() { });
},
),
ElevatedButton(
key: globalKeyWithoutBackdrop,
child: const Text("Without Backdrop"),
onPressed: () {
if(opened) {
g2xPositionedRelativeWithoutBackdrop.hide();
opened = false;
setState(() { });
}
else {
g2xPositionedRelativeWithoutBackdrop.show(
horizontalAxis: G2xHorizontalPositionAxis.center,
context: context,
parentKey: globalKeyWithoutBackdrop,
offSet: const Offset(-100, 0),
child: Container(
height: 50,
width: 200,
color: Colors.red,
child:
const
Center(
child:
Text(
"Child"
)
),
)
);
opened = true;
setState(() { });
}
},
),
],
),
),
),
);
}
}