mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-18 15:54:35 +01:00
opt.: server tab navigation bar when landscape
This commit is contained in:
@@ -10,7 +10,7 @@ extension ServerX on Server {
|
||||
final cmdTemp = () {
|
||||
final val = status.customCmds['server_card_top_right'];
|
||||
if (val == null) return null;
|
||||
// This returned value is used on server card top right, so it should
|
||||
// This returned value is used on server card top right, so it should
|
||||
// be a single line string.
|
||||
return val.split('\n').lastOrNull;
|
||||
}();
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 882;
|
||||
static const int build = 884;
|
||||
static const String engine = "3.19.6";
|
||||
static const String buildAt = "2024-05-09 15:29:37";
|
||||
static const int modifications = 3;
|
||||
static const String buildAt = "2024-05-09 17:08:49";
|
||||
static const int modifications = 4;
|
||||
static const int script = 46;
|
||||
}
|
||||
|
||||
@@ -175,20 +175,19 @@ class _HomePageState extends State<HomePage>
|
||||
: ValBuilder(
|
||||
listenable: _isLandscape,
|
||||
builder: (ls) {
|
||||
if (ls) return const SizedBox();
|
||||
return ListenableBuilder(
|
||||
listenable: _selectIndex,
|
||||
builder: (_, __) => _buildBottomBar(),
|
||||
builder: (_, __) => _buildBottomBar(ls),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomBar() {
|
||||
Widget _buildBottomBar(bool ls) {
|
||||
return NavigationBar(
|
||||
selectedIndex: _selectIndex.value,
|
||||
height: kBottomNavigationBarHeight * 1.1,
|
||||
height: kBottomNavigationBarHeight * (ls ? 0.75 : 1.1),
|
||||
animationDuration: const Duration(milliseconds: 250),
|
||||
onDestinationSelected: (int index) {
|
||||
if (_selectIndex.value == index) return;
|
||||
@@ -203,7 +202,9 @@ class _HomePageState extends State<HomePage>
|
||||
_switchingPage = false;
|
||||
});
|
||||
},
|
||||
labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
|
||||
labelBehavior: ls
|
||||
? NavigationDestinationLabelBehavior.alwaysHide
|
||||
: NavigationDestinationLabelBehavior.onlyShowSelected,
|
||||
destinations: [
|
||||
NavigationDestination(
|
||||
icon: const Icon(BoxIcons.bx_server),
|
||||
|
||||
@@ -18,7 +18,7 @@ import 'package:toolbox/data/model/server/try_limiter.dart';
|
||||
import 'package:toolbox/data/res/color.dart';
|
||||
import 'package:toolbox/data/res/provider.dart';
|
||||
import 'package:toolbox/data/res/store.dart';
|
||||
import 'package:toolbox/view/widget/auto_hide_fab.dart';
|
||||
import 'package:toolbox/view/widget/auto_hide.dart';
|
||||
import 'package:toolbox/view/widget/percent_circle.dart';
|
||||
|
||||
import '../../../core/route.dart';
|
||||
@@ -101,7 +101,8 @@ class _ServerPageState extends State<ServerPage>
|
||||
return _buildBody();
|
||||
},
|
||||
),
|
||||
floatingActionButton: AutoHideFab(
|
||||
floatingActionButton: AutoHide(
|
||||
direction: AxisDirection.right,
|
||||
controller: _scrollController,
|
||||
child: FloatingActionButton(
|
||||
heroTag: 'addServer',
|
||||
|
||||
102
lib/view/widget/auto_hide.dart
Normal file
102
lib/view/widget/auto_hide.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
final class AutoHide extends StatefulWidget {
|
||||
final Widget child;
|
||||
final ScrollController controller;
|
||||
final AxisDirection direction;
|
||||
|
||||
const AutoHide({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.controller,
|
||||
required this.direction,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AutoHide> createState() => _AutoHideState();
|
||||
}
|
||||
|
||||
final class _AutoHideState extends State<AutoHide> {
|
||||
bool _visible = true;
|
||||
bool _isScrolling = false;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.addListener(_scrollListener);
|
||||
_setupTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeListener(_scrollListener);
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setupTimer() {
|
||||
_timer?.cancel();
|
||||
_timer = Timer.periodic(const Duration(seconds: 3), (_) {
|
||||
debugPrint('[AutoHideFab._timer] trigger timer');
|
||||
if (_isScrolling) return;
|
||||
if (!_visible) return;
|
||||
if (!widget.controller.positions.any((e) => e.maxScrollExtent >= 0)) {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_visible = false;
|
||||
});
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
});
|
||||
}
|
||||
|
||||
void _scrollListener() {
|
||||
if (_isScrolling) return;
|
||||
_isScrolling = true;
|
||||
|
||||
if (!_visible) {
|
||||
setState(() {
|
||||
_visible = true;
|
||||
});
|
||||
_setupTimer();
|
||||
}
|
||||
|
||||
_isScrolling = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedContainer(
|
||||
duration: Durations.medium1,
|
||||
curve: Curves.easeInOutCubic,
|
||||
transform: _transform,
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
|
||||
Matrix4? get _transform {
|
||||
switch (widget.direction) {
|
||||
case AxisDirection.down:
|
||||
return _visible
|
||||
? Matrix4.identity()
|
||||
: Matrix4.translationValues(0, 55, 0);
|
||||
case AxisDirection.up:
|
||||
return _visible
|
||||
? Matrix4.identity()
|
||||
: Matrix4.translationValues(0, -55, 0);
|
||||
case AxisDirection.left:
|
||||
return _visible
|
||||
? Matrix4.identity()
|
||||
: Matrix4.translationValues(-55, 0, 0);
|
||||
case AxisDirection.right:
|
||||
return _visible
|
||||
? Matrix4.identity()
|
||||
: Matrix4.translationValues(55, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
final class AutoHideFab extends StatefulWidget {
|
||||
final Widget child;
|
||||
final ScrollController controller;
|
||||
|
||||
const AutoHideFab({
|
||||
super.key,
|
||||
required this.child,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AutoHideFab> createState() => _AutoHideFabState();
|
||||
}
|
||||
|
||||
final class _AutoHideFabState extends State<AutoHideFab> {
|
||||
bool _visible = true;
|
||||
bool _isScrolling = false;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.controller.addListener(_scrollListener);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.controller.removeListener(_scrollListener);
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setupTimer() {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
_timer = Timer.periodic(const Duration(seconds: 3), (_) {
|
||||
if (_isScrolling) return;
|
||||
if (!_visible) return;
|
||||
if (widget.controller.position.maxScrollExtent <= 0) return;
|
||||
setState(() {
|
||||
_visible = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _scrollListener() {
|
||||
if (_isScrolling) return;
|
||||
_isScrolling = true;
|
||||
if (widget.controller.position.userScrollDirection ==
|
||||
ScrollDirection.reverse) {
|
||||
if (_visible) {
|
||||
setState(() {
|
||||
_visible = false;
|
||||
});
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
}
|
||||
} else {
|
||||
if (!_visible) {
|
||||
setState(() {
|
||||
_visible = true;
|
||||
});
|
||||
_setupTimer();
|
||||
}
|
||||
}
|
||||
_isScrolling = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedContainer(
|
||||
duration: Durations.medium1,
|
||||
curve: Curves.easeInOutCubic,
|
||||
transform: Matrix4.translationValues(_visible ? 0.0 : 55, 0.0, 0.0),
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,11 +28,12 @@ final class KvRow extends StatelessWidget {
|
||||
children: [
|
||||
kBuilder?.call() ?? Text(k, style: UIs.text12),
|
||||
UIs.width7,
|
||||
vBuilder?.call() ?? Text(
|
||||
v,
|
||||
style: UIs.text11Grey,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
vBuilder?.call() ??
|
||||
Text(
|
||||
v,
|
||||
style: UIs.text11Grey,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (onTap != null) UIs.width7,
|
||||
if (onTap != null) const Icon(Icons.keyboard_arrow_right, size: 16),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user