opt: more configurable scroll logic & edge size

This commit is contained in:
Kingtous 2022-09-19 16:06:03 +08:00
parent bf1314f91f
commit 21eb7bd165
8 changed files with 79 additions and 47 deletions

View File

@ -248,6 +248,7 @@ List<Locale> supportedLocales = const [
// specify CN/TW to fix CJK issue in flutter
Locale('zh', 'CN'),
Locale('zh', 'TW'),
Locale('zh', 'SG'),
Locale('fr'),
Locale('de'),
Locale('it'),

View File

@ -60,7 +60,7 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
return Platform.isMacOS
? tabWidget
: Obx(() => DragToResizeArea(
resizeEdgeSize: fullscreen.value ? 1.0 : 8.0, child: tabWidget));
resizeEdgeSize: fullscreen.value ? 1.0 : 4.0, child: tabWidget));
}
void onAddSetting() {

View File

@ -81,6 +81,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
return Platform.isMacOS
? tabWidget
: SubWindowDragToResizeArea(
resizeEdgeSize: 4.0,
windowId: windowId(),
child: tabWidget,
);

View File

@ -92,6 +92,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
return Platform.isMacOS
? tabWidget
: SubWindowDragToResizeArea(
resizeEdgeSize: 4.0,
windowId: windowId(),
child: tabWidget,
);

View File

@ -143,7 +143,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
return Platform.isMacOS
? tabWidget
: Obx(() => SubWindowDragToResizeArea(
resizeEdgeSize: fullscreen.value ? 1.0 : 8.0,
resizeEdgeSize: fullscreen.value ? 1.0 : 4.0,
windowId: windowId(),
child: tabWidget));
}

View File

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hbb/desktop/widgets/scroll_wrapper.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:visibility_detector/visibility_detector.dart';
@ -41,6 +42,7 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
static const int _maxQueryCount = 3;
final _curPeers = <String>{};
final _scrollController = ScrollController();
var _lastChangeTime = DateTime.now();
var _lastQueryPeers = <String>{};
var _lastQueryTime = DateTime.now().subtract(const Duration(hours: 1));
@ -84,53 +86,58 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
? Center(
child: Text(translate("Empty")),
)
: SingleChildScrollView(
controller: ScrollController(),
child: ObxValue<RxString>((searchText) {
return FutureBuilder<List<Peer>>(
builder: (context, snapshot) {
if (snapshot.hasData) {
final peers = snapshot.data!;
final cards = <Widget>[];
for (final peer in peers) {
cards.add(Offstage(
key: ValueKey("off${peer.id}"),
offstage: widget.offstageFunc(peer),
child: Obx(
() => SizedBox(
width: 220,
height:
peerCardUiType.value == PeerUiType.grid
? 140
: 42,
child: VisibilityDetector(
key: ValueKey(peer.id),
onVisibilityChanged: (info) {
final peerId =
(info.key as ValueKey).value;
if (info.visibleFraction > 0.00001) {
_curPeers.add(peerId);
} else {
_curPeers.remove(peerId);
}
_lastChangeTime = DateTime.now();
},
child: widget.peerCardWidgetFunc(peer),
: DesktopScrollWrapper(
scrollController: _scrollController,
child: SingleChildScrollView(
controller: _scrollController,
child: ObxValue<RxString>((searchText) {
return FutureBuilder<List<Peer>>(
builder: (context, snapshot) {
if (snapshot.hasData) {
final peers = snapshot.data!;
final cards = <Widget>[];
for (final peer in peers) {
cards.add(Offstage(
key: ValueKey("off${peer.id}"),
offstage: widget.offstageFunc(peer),
child: Obx(
() => SizedBox(
width: 220,
height:
peerCardUiType.value == PeerUiType.grid
? 140
: 42,
child: VisibilityDetector(
key: ValueKey(peer.id),
onVisibilityChanged: (info) {
final peerId =
(info.key as ValueKey).value;
if (info.visibleFraction > 0.00001) {
_curPeers.add(peerId);
} else {
_curPeers.remove(peerId);
}
_lastChangeTime = DateTime.now();
},
child: widget.peerCardWidgetFunc(peer),
),
),
),
)));
)));
}
return Wrap(
spacing: space,
runSpacing: space,
children: cards);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
return Wrap(
spacing: space, runSpacing: space, children: cards);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
},
future: matchPeers(searchText.value, peers.peers),
);
}, peerSearchText),
},
future: matchPeers(searchText.value, peers.peers),
);
}, peerSearchText),
),
),
),
);

View File

@ -0,0 +1,21 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_improved_scrolling/flutter_improved_scrolling.dart';
class DesktopScrollWrapper extends StatelessWidget {
final ScrollController scrollController;
final Widget child;
const DesktopScrollWrapper(
{Key? key, required this.scrollController, required this.child})
: super(key: key);
@override
Widget build(BuildContext context) {
return ImprovedScrolling(
scrollController: scrollController,
enableCustomMouseWheelScrolling: false,
customMouseWheelScrollConfig:
const CustomMouseWheelScrollConfig(scrollAmountMultiplier: 3.0),
child: child,
);
}
}

View File

@ -80,6 +80,7 @@ dependencies:
desktop_drop: ^0.3.3
scroll_pos: ^0.3.0
rxdart: ^0.27.5
flutter_improved_scrolling: ^0.0.3
dev_dependencies:
icons_launcher: ^2.0.4