fix: click blank to show fab

This commit is contained in:
lollipopkit
2024-05-10 21:46:05 +08:00
parent 5bc28a0560
commit 6b5f98cb2d
2 changed files with 29 additions and 12 deletions

View File

@@ -57,6 +57,7 @@ class _ServerPageState extends State<ServerPage>
bool _useDoubleColumn = false; bool _useDoubleColumn = false;
final _scrollController = ScrollController(); final _scrollController = ScrollController();
final _autoHideKey = GlobalKey<AutoHideState>();
@override @override
void initState() { void initState() {
@@ -97,14 +98,19 @@ class _ServerPageState extends State<ServerPage>
Widget _buildPortrait() { Widget _buildPortrait() {
return Scaffold( return Scaffold(
appBar: _buildTagsSwitcher(Pros.server), appBar: _buildTagsSwitcher(Pros.server),
body: ListenableBuilder( body: GestureDetector(
listenable: Stores.setting.textFactor.listenable(), behavior: HitTestBehavior.opaque,
builder: (_, __) { onTap: () => _autoHideKey.currentState?.show(),
_updateTextScaler(); child: ListenableBuilder(
return _buildBody(); listenable: Stores.setting.textFactor.listenable(),
}, builder: (_, __) {
_updateTextScaler();
return _buildBody();
},
),
), ),
floatingActionButton: AutoHide( floatingActionButton: AutoHide(
key: _autoHideKey,
direction: AxisDirection.right, direction: AxisDirection.right,
controller: _scrollController, controller: _scrollController,
child: FloatingActionButton( child: FloatingActionButton(

View File

@@ -6,19 +6,21 @@ final class AutoHide extends StatefulWidget {
final Widget child; final Widget child;
final ScrollController controller; final ScrollController controller;
final AxisDirection direction; final AxisDirection direction;
final double offset;
const AutoHide({ const AutoHide({
super.key, super.key,
required this.child, required this.child,
required this.controller, required this.controller,
required this.direction, required this.direction,
this.offset = 55,
}); });
@override @override
State<AutoHide> createState() => _AutoHideState(); State<AutoHide> createState() => AutoHideState();
} }
final class _AutoHideState extends State<AutoHide> { final class AutoHideState extends State<AutoHide> {
bool _visible = true; bool _visible = true;
bool _isScrolling = false; bool _isScrolling = false;
Timer? _timer; Timer? _timer;
@@ -38,6 +40,15 @@ final class _AutoHideState extends State<AutoHide> {
super.dispose(); super.dispose();
} }
void show() {
debugPrint('show');
if (_visible) return;
setState(() {
_visible = true;
});
_setupTimer();
}
void _setupTimer() { void _setupTimer() {
_timer?.cancel(); _timer?.cancel();
_timer = Timer.periodic(const Duration(seconds: 3), (_) { _timer = Timer.periodic(const Duration(seconds: 3), (_) {
@@ -84,19 +95,19 @@ final class _AutoHideState extends State<AutoHide> {
case AxisDirection.down: case AxisDirection.down:
return _visible return _visible
? Matrix4.identity() ? Matrix4.identity()
: Matrix4.translationValues(0, 55, 0); : Matrix4.translationValues(0, widget.offset, 0);
case AxisDirection.up: case AxisDirection.up:
return _visible return _visible
? Matrix4.identity() ? Matrix4.identity()
: Matrix4.translationValues(0, -55, 0); : Matrix4.translationValues(0, -widget.offset, 0);
case AxisDirection.left: case AxisDirection.left:
return _visible return _visible
? Matrix4.identity() ? Matrix4.identity()
: Matrix4.translationValues(-55, 0, 0); : Matrix4.translationValues(-widget.offset, 0, 0);
case AxisDirection.right: case AxisDirection.right:
return _visible return _visible
? Matrix4.identity() ? Matrix4.identity()
: Matrix4.translationValues(55, 0, 0); : Matrix4.translationValues(widget.offset, 0, 0);
} }
} }
} }