From 17a42b57c6343ba76740a50e184c6b2f15e9e0d9 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Fri, 19 Feb 2021 13:39:02 +0800 Subject: [PATCH] update fab position and hide fab button when page open --- lib/src/power_logger.dart | 91 ++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 39 deletions(-) diff --git a/lib/src/power_logger.dart b/lib/src/power_logger.dart index b29522a..5770ac4 100644 --- a/lib/src/power_logger.dart +++ b/lib/src/power_logger.dart @@ -34,6 +34,8 @@ class _LoggerFABState extends State { 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 { 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, + ), ), ), ),