mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-12 02:57:22 +00:00
refact: peer card, orientation (#9235)
* refact: peer card, orientation Signed-off-by: fufesou <linlong1266@gmail.com> * Do not change landscape/portrait on Desktop Signed-off-by: fufesou <linlong1266@gmail.com> * comments Signed-off-by: fufesou <linlong1266@gmail.com> --------- Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -372,7 +372,7 @@ class App extends StatefulWidget {
|
||||
State<App> createState() => _AppState();
|
||||
}
|
||||
|
||||
class _AppState extends State<App> {
|
||||
class _AppState extends State<App> with WidgetsBindingObserver {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -396,6 +396,34 @@ class _AppState extends State<App> {
|
||||
bind.mainChangeTheme(dark: to.toShortString());
|
||||
}
|
||||
};
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _updateOrientation());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeMetrics() {
|
||||
_updateOrientation();
|
||||
}
|
||||
|
||||
void _updateOrientation() {
|
||||
if (isDesktop) return;
|
||||
|
||||
// Don't use `MediaQuery.of(context).orientation` in `didChangeMetrics()`,
|
||||
// my test (Flutter 3.19.6, Android 14) is always the reverse value.
|
||||
// https://github.com/flutter/flutter/issues/60899
|
||||
// stateGlobal.isPortrait.value =
|
||||
// MediaQuery.of(context).orientation == Orientation.portrait;
|
||||
|
||||
final orientation = View.of(context).physicalSize.aspectRatio > 1
|
||||
? Orientation.landscape
|
||||
: Orientation.portrait;
|
||||
stateGlobal.isPortrait.value = orientation == Orientation.portrait;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user