mirror of
https://github.com/gskinnerTeam/flutter-wonderous-app.git
synced 2025-08-26 11:32:26 +08:00
Add support for landscape orientation on desktop and tablets.
This commit is contained in:
@ -1,9 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:desktop_window/desktop_window.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_displaymode/flutter_displaymode.dart';
|
||||
import 'package:wonders/common_libs.dart';
|
||||
import 'package:wonders/logic/common/platform_info.dart';
|
||||
import 'package:wonders/ui/common/utils/page_routes.dart';
|
||||
|
||||
class AppLogic {
|
||||
@ -11,6 +11,17 @@ class AppLogic {
|
||||
/// The router will use this to prevent redirects while bootstrapping.
|
||||
bool isBootstrapComplete = false;
|
||||
|
||||
bool get isDesktopOrTablet => PlatformInfo.isDesktopOrWeb || deviceSize.shortestSide > 500;
|
||||
|
||||
/// Support portrait and landscape on desktop, web and tablets. Stick to portrait for phones.
|
||||
/// A return value of null indicated both orientations are supported.
|
||||
Axis? get supportedOrientations => isDesktopOrTablet ? null : Axis.vertical;
|
||||
|
||||
Size get deviceSize {
|
||||
final w = WidgetsBinding.instance.platformDispatcher.views.first;
|
||||
return w.physicalSize / w.devicePixelRatio;
|
||||
}
|
||||
|
||||
/// Initialize the app and all main actors.
|
||||
/// Loads settings, sets up services etc.
|
||||
Future<void> bootstrap() async {
|
||||
@ -18,16 +29,18 @@ class AppLogic {
|
||||
FlutterError.onError = _handleFlutterError;
|
||||
|
||||
// Set min-sizes for desktop apps
|
||||
await DesktopWindow.setMinWindowSize($styles.sizes.minAppSize);
|
||||
if (PlatformInfo.isDesktop) {
|
||||
await DesktopWindow.setMinWindowSize($styles.sizes.minAppSize);
|
||||
}
|
||||
|
||||
// Load any bitmaps the views might need
|
||||
await AppBitmaps.init();
|
||||
|
||||
// Default to only allowing portrait mode
|
||||
setDeviceOrientation(Axis.vertical);
|
||||
// Set the initial supported orientations
|
||||
setDeviceOrientation(supportedOrientations);
|
||||
|
||||
// Set preferred refresh rate to the max possible (the OS may ignore this)
|
||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||
if (PlatformInfo.isAndroid) {
|
||||
await FlutterDisplayMode.setHighRefreshRate();
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ class PlatformInfo {
|
||||
static const _mobilePlatforms = [TargetPlatform.android, TargetPlatform.iOS];
|
||||
|
||||
static bool get isDesktop => _desktopPlatforms.contains(defaultTargetPlatform);
|
||||
static bool get isDesktopOrWeb => isDesktop || kIsWeb;
|
||||
static bool get isMobile => _mobilePlatforms.contains(defaultTargetPlatform);
|
||||
|
||||
static double get pixelRatio => WidgetsBinding.instance.window.devicePixelRatio;
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:wonders/_tools/unsplash_download_service.dart';
|
||||
import 'package:wonders/logic/common/platform_info.dart';
|
||||
|
||||
@ -27,10 +26,7 @@ class UnsplashPhotoData {
|
||||
size = 1200;
|
||||
break;
|
||||
}
|
||||
bool isDesktop = defaultTargetPlatform == TargetPlatform.windows ||
|
||||
defaultTargetPlatform == TargetPlatform.macOS ||
|
||||
defaultTargetPlatform == TargetPlatform.linux;
|
||||
if (PlatformInfo.pixelRatio >= 1.5 || isDesktop) {
|
||||
if (PlatformInfo.pixelRatio >= 1.5 || PlatformInfo.isDesktop) {
|
||||
size *= 2;
|
||||
}
|
||||
return 'https://wonderous.info/unsplash/$id-$size.jpg';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:wonders/common_libs.dart';
|
||||
import 'package:wonders/logic/common/platform_info.dart';
|
||||
import 'package:wonders/logic/common/save_load_mixin.dart';
|
||||
|
||||
class SettingsLogic with ThrottledSaveLoadMixin {
|
||||
@ -10,7 +10,7 @@ class SettingsLogic with ThrottledSaveLoadMixin {
|
||||
late final hasDismissedSearchMessage = ValueNotifier<bool>(false)..addListener(scheduleSave);
|
||||
late final currentLocale = ValueNotifier<String?>(null)..addListener(scheduleSave);
|
||||
|
||||
final bool useBlurs = defaultTargetPlatform != TargetPlatform.android;
|
||||
final bool useBlurs = !PlatformInfo.isAndroid;
|
||||
|
||||
@override
|
||||
void copyFromJson(Map<String, dynamic> value) {
|
||||
|
Reference in New Issue
Block a user