update fab position and hide fab button when page open

master
小赖 4 years ago
parent 1469b68b32
commit 17a42b57c6

@ -34,6 +34,8 @@ class _LoggerFABState extends State<LoggerFAB> {
double get screenWidth => MediaQuery.of(context).size.width;
double get screenHeight => MediaQuery.of(context).size.height;
bool _moving = false;
bool showSubPage = false;
@override
Widget build(BuildContext context) {
return AnimatedPositioned(
@ -41,45 +43,56 @@ class _LoggerFABState extends State<LoggerFAB> {
duration: _moving ? Duration.zero : Duration(milliseconds: 300),
left: _x - 25,
top: _y - 25,
child: GestureDetector(
onPanStart: (detail) {
_moving = true;
},
onPanUpdate: (details) {
setState(() {
_x = details.globalPosition.dx;
_y = details.globalPosition.dy;
});
},
onPanEnd: (detail) {
if ((_x < screenWidth / 2)) {
_x = 50;
} else
_x = screenWidth - 50;
if ((_y < screenHeight / 2)) {
_y = 70;
} else
_y = screenHeight - 50;
_moving = false;
setState(() {});
},
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => PowerLoggerView()),
),
child: ClipOval(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
decoration: BoxDecoration(
color: Colors.blueAccent.withOpacity(0.4),
borderRadius: BorderRadius.circular(25),
),
height: 50,
width: 50,
child: Icon(
Icons.code,
color: Colors.white70,
child: AnimatedOpacity(
duration: Duration(milliseconds: 300),
curve: Curves.easeInOutCubic,
opacity: showSubPage ? 0 : 1,
child: GestureDetector(
onPanStart: (detail) {
_moving = true;
},
onPanUpdate: (details) {
setState(() {
_x = details.globalPosition.dx;
_y = details.globalPosition.dy;
});
},
onPanEnd: (detail) {
if ((_x < screenWidth / 2)) {
_x = 50;
} else
_x = screenWidth - 50;
if (_y > screenHeight - 50) {
_y = screenHeight - 50;
} else if (_y < 50) _y = 50;
_moving = false;
setState(() {});
},
onTap: showSubPage
? null
: () async {
showSubPage = true;
await Navigator.push(
context,
MaterialPageRoute(builder: (context) => PowerLoggerView()),
);
showSubPage = false;
},
child: ClipOval(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
decoration: BoxDecoration(
color: Colors.blueAccent.withOpacity(0.4),
borderRadius: BorderRadius.circular(25),
),
height: 50,
width: 50,
child: Icon(
Icons.code,
color: Colors.white70,
),
),
),
),

Loading…
Cancel
Save