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

View File

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