opt: more configurable scroll logic & edge size
This commit is contained in:
parent
bf1314f91f
commit
21eb7bd165
@ -248,6 +248,7 @@ List<Locale> supportedLocales = const [
|
|||||||
// specify CN/TW to fix CJK issue in flutter
|
// specify CN/TW to fix CJK issue in flutter
|
||||||
Locale('zh', 'CN'),
|
Locale('zh', 'CN'),
|
||||||
Locale('zh', 'TW'),
|
Locale('zh', 'TW'),
|
||||||
|
Locale('zh', 'SG'),
|
||||||
Locale('fr'),
|
Locale('fr'),
|
||||||
Locale('de'),
|
Locale('de'),
|
||||||
Locale('it'),
|
Locale('it'),
|
||||||
|
@ -60,7 +60,7 @@ class _DesktopTabPageState extends State<DesktopTabPage> {
|
|||||||
return Platform.isMacOS
|
return Platform.isMacOS
|
||||||
? tabWidget
|
? tabWidget
|
||||||
: Obx(() => DragToResizeArea(
|
: Obx(() => DragToResizeArea(
|
||||||
resizeEdgeSize: fullscreen.value ? 1.0 : 8.0, child: tabWidget));
|
resizeEdgeSize: fullscreen.value ? 1.0 : 4.0, child: tabWidget));
|
||||||
}
|
}
|
||||||
|
|
||||||
void onAddSetting() {
|
void onAddSetting() {
|
||||||
|
@ -81,6 +81,7 @@ class _FileManagerTabPageState extends State<FileManagerTabPage> {
|
|||||||
return Platform.isMacOS
|
return Platform.isMacOS
|
||||||
? tabWidget
|
? tabWidget
|
||||||
: SubWindowDragToResizeArea(
|
: SubWindowDragToResizeArea(
|
||||||
|
resizeEdgeSize: 4.0,
|
||||||
windowId: windowId(),
|
windowId: windowId(),
|
||||||
child: tabWidget,
|
child: tabWidget,
|
||||||
);
|
);
|
||||||
|
@ -92,6 +92,7 @@ class _PortForwardTabPageState extends State<PortForwardTabPage> {
|
|||||||
return Platform.isMacOS
|
return Platform.isMacOS
|
||||||
? tabWidget
|
? tabWidget
|
||||||
: SubWindowDragToResizeArea(
|
: SubWindowDragToResizeArea(
|
||||||
|
resizeEdgeSize: 4.0,
|
||||||
windowId: windowId(),
|
windowId: windowId(),
|
||||||
child: tabWidget,
|
child: tabWidget,
|
||||||
);
|
);
|
||||||
|
@ -143,7 +143,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage> {
|
|||||||
return Platform.isMacOS
|
return Platform.isMacOS
|
||||||
? tabWidget
|
? tabWidget
|
||||||
: Obx(() => SubWindowDragToResizeArea(
|
: Obx(() => SubWindowDragToResizeArea(
|
||||||
resizeEdgeSize: fullscreen.value ? 1.0 : 8.0,
|
resizeEdgeSize: fullscreen.value ? 1.0 : 4.0,
|
||||||
windowId: windowId(),
|
windowId: windowId(),
|
||||||
child: tabWidget));
|
child: tabWidget));
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hbb/desktop/widgets/scroll_wrapper.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:visibility_detector/visibility_detector.dart';
|
import 'package:visibility_detector/visibility_detector.dart';
|
||||||
@ -41,6 +42,7 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
|||||||
static const int _maxQueryCount = 3;
|
static const int _maxQueryCount = 3;
|
||||||
|
|
||||||
final _curPeers = <String>{};
|
final _curPeers = <String>{};
|
||||||
|
final _scrollController = ScrollController();
|
||||||
var _lastChangeTime = DateTime.now();
|
var _lastChangeTime = DateTime.now();
|
||||||
var _lastQueryPeers = <String>{};
|
var _lastQueryPeers = <String>{};
|
||||||
var _lastQueryTime = DateTime.now().subtract(const Duration(hours: 1));
|
var _lastQueryTime = DateTime.now().subtract(const Duration(hours: 1));
|
||||||
@ -84,53 +86,58 @@ class _PeerWidgetState extends State<_PeerWidget> with WindowListener {
|
|||||||
? Center(
|
? Center(
|
||||||
child: Text(translate("Empty")),
|
child: Text(translate("Empty")),
|
||||||
)
|
)
|
||||||
: SingleChildScrollView(
|
: DesktopScrollWrapper(
|
||||||
controller: ScrollController(),
|
scrollController: _scrollController,
|
||||||
child: ObxValue<RxString>((searchText) {
|
child: SingleChildScrollView(
|
||||||
return FutureBuilder<List<Peer>>(
|
controller: _scrollController,
|
||||||
builder: (context, snapshot) {
|
child: ObxValue<RxString>((searchText) {
|
||||||
if (snapshot.hasData) {
|
return FutureBuilder<List<Peer>>(
|
||||||
final peers = snapshot.data!;
|
builder: (context, snapshot) {
|
||||||
final cards = <Widget>[];
|
if (snapshot.hasData) {
|
||||||
for (final peer in peers) {
|
final peers = snapshot.data!;
|
||||||
cards.add(Offstage(
|
final cards = <Widget>[];
|
||||||
key: ValueKey("off${peer.id}"),
|
for (final peer in peers) {
|
||||||
offstage: widget.offstageFunc(peer),
|
cards.add(Offstage(
|
||||||
child: Obx(
|
key: ValueKey("off${peer.id}"),
|
||||||
() => SizedBox(
|
offstage: widget.offstageFunc(peer),
|
||||||
width: 220,
|
child: Obx(
|
||||||
height:
|
() => SizedBox(
|
||||||
peerCardUiType.value == PeerUiType.grid
|
width: 220,
|
||||||
? 140
|
height:
|
||||||
: 42,
|
peerCardUiType.value == PeerUiType.grid
|
||||||
child: VisibilityDetector(
|
? 140
|
||||||
key: ValueKey(peer.id),
|
: 42,
|
||||||
onVisibilityChanged: (info) {
|
child: VisibilityDetector(
|
||||||
final peerId =
|
key: ValueKey(peer.id),
|
||||||
(info.key as ValueKey).value;
|
onVisibilityChanged: (info) {
|
||||||
if (info.visibleFraction > 0.00001) {
|
final peerId =
|
||||||
_curPeers.add(peerId);
|
(info.key as ValueKey).value;
|
||||||
} else {
|
if (info.visibleFraction > 0.00001) {
|
||||||
_curPeers.remove(peerId);
|
_curPeers.add(peerId);
|
||||||
}
|
} else {
|
||||||
_lastChangeTime = DateTime.now();
|
_curPeers.remove(peerId);
|
||||||
},
|
}
|
||||||
child: widget.peerCardWidgetFunc(peer),
|
_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);
|
future: matchPeers(searchText.value, peers.peers),
|
||||||
} else {
|
);
|
||||||
return const Center(
|
}, peerSearchText),
|
||||||
child: CircularProgressIndicator(),
|
),
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
future: matchPeers(searchText.value, peers.peers),
|
|
||||||
);
|
|
||||||
}, peerSearchText),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
21
flutter/lib/desktop/widgets/scroll_wrapper.dart
Normal file
21
flutter/lib/desktop/widgets/scroll_wrapper.dart
Normal 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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -80,6 +80,7 @@ dependencies:
|
|||||||
desktop_drop: ^0.3.3
|
desktop_drop: ^0.3.3
|
||||||
scroll_pos: ^0.3.0
|
scroll_pos: ^0.3.0
|
||||||
rxdart: ^0.27.5
|
rxdart: ^0.27.5
|
||||||
|
flutter_improved_scrolling: ^0.0.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
icons_launcher: ^2.0.4
|
icons_launcher: ^2.0.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user