flutter_desktop: fullscreen ok

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-08-16 20:48:36 +08:00
parent f797125ae2
commit 82b72e5fdd
3 changed files with 230 additions and 190 deletions

View File

@ -27,6 +27,7 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
RxList<TabInfo> tabs = RxList<TabInfo>.empty(growable: true); RxList<TabInfo> tabs = RxList<TabInfo>.empty(growable: true);
late Rx<TabController> tabController; late Rx<TabController> tabController;
static final Rx<int> _selected = 0.obs; static final Rx<int> _selected = 0.obs;
static final Rx<String> _fullscreenID = "".obs;
IconData icon = Icons.desktop_windows_sharp; IconData icon = Icons.desktop_windows_sharp;
var connectionMap = RxList<Widget>.empty(growable: true); var connectionMap = RxList<Widget>.empty(growable: true);
@ -70,24 +71,32 @@ class _ConnectionTabPageState extends State<ConnectionTabPage>
return Scaffold( return Scaffold(
body: Column( body: Column(
children: [ children: [
DesktopTabBar( Obx(() => Visibility(
controller: tabController, visible: _fullscreenID.value.isEmpty,
tabs: tabs, child: DesktopTabBar(
onTabClose: onRemoveId, controller: tabController,
selected: _selected, tabs: tabs,
dark: isDarkTheme(), onTabClose: onRemoveId,
mainTab: false, selected: _selected,
), dark: isDarkTheme(),
Expanded( mainTab: false,
child: Obx(() => TabBarView( ))),
controller: tabController.value, Expanded(child: Obx(() {
children: tabs WindowController.fromWindowId(windowId())
.map((tab) => RemotePage( .setFullscreen(_fullscreenID.value.isNotEmpty);
key: ValueKey(tab.label), return TabBarView(
id: tab.label, controller: tabController.value,
tabBarHeight: kDesktopRemoteTabBarHeight, children: tabs
)) //RemotePage(key: ValueKey(e), id: e)) .map((tab) => RemotePage(
.toList()))), key: ValueKey(tab.label),
id: tab.label,
tabBarHeight: _fullscreenID.value.isNotEmpty
? 0
: kDesktopRemoteTabBarHeight,
fullscreenID: _fullscreenID,
)) //RemotePage(key: ValueKey(e), id: e))
.toList());
})),
], ],
), ),
); );

View File

@ -9,6 +9,7 @@ import 'package:flutter_hbb/models/chat_model.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:wakelock/wakelock.dart'; import 'package:wakelock/wakelock.dart';
import 'package:desktop_multi_window/desktop_multi_window.dart';
// import 'package:window_manager/window_manager.dart'; // import 'package:window_manager/window_manager.dart';
@ -21,11 +22,16 @@ import '../../models/platform_model.dart';
final initText = '\1' * 1024; final initText = '\1' * 1024;
class RemotePage extends StatefulWidget { class RemotePage extends StatefulWidget {
RemotePage({Key? key, required this.id, required this.tabBarHeight}) RemotePage(
{Key? key,
required this.id,
required this.tabBarHeight,
required this.fullscreenID})
: super(key: key); : super(key: key);
final String id; final String id;
final double tabBarHeight; final double tabBarHeight;
final Rx<String> fullscreenID;
@override @override
_RemotePageState createState() => _RemotePageState(); _RemotePageState createState() => _RemotePageState();
@ -41,6 +47,7 @@ class _RemotePageState extends State<RemotePage>
final FocusNode _mobileFocusNode = FocusNode(); final FocusNode _mobileFocusNode = FocusNode();
final FocusNode _physicalFocusNode = FocusNode(); final FocusNode _physicalFocusNode = FocusNode();
var _isPhysicalMouse = false; var _isPhysicalMouse = false;
var _imageFocused = false;
late FFI _ffi; late FFI _ffi;
@ -238,6 +245,9 @@ class _RemotePageState extends State<RemotePage>
autofocus: true, autofocus: true,
canRequestFocus: true, canRequestFocus: true,
focusNode: _physicalFocusNode, focusNode: _physicalFocusNode,
onFocusChange: (bool v) {
_imageFocused = v;
},
onKey: (data, e) { onKey: (data, e) {
final key = e.logicalKey; final key = e.logicalKey;
if (e is RawKeyDownEvent) { if (e is RawKeyDownEvent) {
@ -307,6 +317,24 @@ class _RemotePageState extends State<RemotePage>
}, },
) )
] + ] +
(isWebDesktop
? []
: <Widget>[
IconButton(
color: Colors.white,
icon: Icon(widget.fullscreenID.value.isEmpty
? Icons.fullscreen
: Icons.close_fullscreen),
onPressed: () {
setState(() => _showEdit = false);
if (widget.fullscreenID.value.isEmpty) {
widget.fullscreenID.value = widget.id;
} else {
widget.fullscreenID.value = "";
}
},
)
]) +
(isWebDesktop (isWebDesktop
? [] ? []
: _ffi.ffiModel.isPeerAndroid : _ffi.ffiModel.isPeerAndroid
@ -434,6 +462,9 @@ class _RemotePageState extends State<RemotePage>
onPointerSignal: _onPointerSignalImage, onPointerSignal: _onPointerSignalImage,
child: MouseRegion( child: MouseRegion(
onEnter: (evt) { onEnter: (evt) {
if (!_imageFocused) {
_physicalFocusNode.requestFocus();
}
_cursorOverImage.value = true; _cursorOverImage.value = true;
}, },
onExit: (evt) { onExit: (evt) {

File diff suppressed because it is too large Load Diff