diff --git a/android/app/src/main/AndroidManifestBase.xml b/android/app/src/main/AndroidManifestBase.xml index 64adea1e7..bc189f92c 100644 --- a/android/app/src/main/AndroidManifestBase.xml +++ b/android/app/src/main/AndroidManifestBase.xml @@ -22,7 +22,6 @@ android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize" - android:screenOrientation="portrait" android:exported="true"> with SingleTickerProviderStateMixin { - AppState() : yatStore = getIt.get() { - SystemChrome.setPreferredOrientations( - ResponsiveLayoutUtil.instance.isIpad ? - [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight] : - [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); - } + AppState() : yatStore = getIt.get(); YatStore yatStore; StreamSubscription? stream; @@ -290,7 +285,43 @@ class AppState extends State with SingleTickerProviderStateMixin { locale: Locale(settingsStore.languageCode), onGenerateRoute: (settings) => Router.createRoute(settings), initialRoute: initialRoute, + home: _Home(), )); }); } } + +class _Home extends StatefulWidget { + const _Home(); + + @override + State<_Home> createState() => _HomeState(); +} + +class _HomeState extends State<_Home> { + @override + void didChangeDependencies() { + if(!ResponsiveLayoutUtil.instance.isMobile){ + _setOrientation(context); + } + super.didChangeDependencies(); + } + + + void _setOrientation(BuildContext context){ + final orientation = MediaQuery.of(context).orientation; + final width = MediaQuery.of(context).size.width; + final height = MediaQuery.of(context).size.height; + if (orientation == Orientation.portrait && width < height) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]); + } else if (orientation == Orientation.landscape && width > height) { + SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]); + } + + } + + @override + Widget build(BuildContext context) { + return const SizedBox.shrink(); + } +} diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index 71dfda356..0c46aaf25 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -4,6 +4,7 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/main_actions.dart'; import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart'; import 'package:cake_wallet/src/screens/dashboard/widgets/market_place_page.dart'; +import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/version_comparator.dart'; import 'package:cake_wallet/view_model/dashboard/market_place_view_model.dart'; import 'package:cake_wallet/generated/i18n.dart'; @@ -42,15 +43,30 @@ class DashboardPage extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - body: ResponsiveLayoutUtil.instance.isMobile - ? _DashboardPageView( + return Scaffold(body: LayoutBuilder( + builder: (context, constraints) { + if (DeviceInfo.instance.isDesktop) { + if (constraints.maxWidth > ResponsiveLayoutUtil.kDesktopMaxDashBoardWidthConstraint) { + return getIt.get(); + } else { + return _DashboardPageView( balancePage: balancePage, dashboardViewModel: dashboardViewModel, addressListViewModel: addressListViewModel, - ) - : getIt.get(), - ); + ); + } + } else if (ResponsiveLayoutUtil.instance.shouldRenderMobileUI()) { + return _DashboardPageView( + balancePage: balancePage, + dashboardViewModel: dashboardViewModel, + addressListViewModel: addressListViewModel, + ); + } else { + return getIt.get(); + } + + }, + )); } } @@ -251,7 +267,7 @@ class _DashboardPageView extends BasePage { pages.add(Semantics( label: S.of(context).market_place, child: MarketPlacePage( - dashboardViewModel: dashboardViewModel, + dashboardViewModel: dashboardViewModel, marketPlaceViewModel: getIt.get(), ), ), diff --git a/lib/src/screens/dashboard/widgets/present_receive_option_picker.dart b/lib/src/screens/dashboard/widgets/present_receive_option_picker.dart index c29442450..cf2ae7e3d 100644 --- a/lib/src/screens/dashboard/widgets/present_receive_option_picker.dart +++ b/lib/src/screens/dashboard/widgets/present_receive_option_picker.dart @@ -138,7 +138,7 @@ class PresentReceiveOptionPicker extends StatelessWidget { Container( margin: EdgeInsets.only(bottom: 40), child: InkWell( - onTap: () => Navigator.pop(context), + onTap: () => Navigator.pop(popUpContext), child: CircleAvatar( child: Icon( Icons.close, diff --git a/lib/src/screens/receive/anonpay_invoice_page.dart b/lib/src/screens/receive/anonpay_invoice_page.dart index f8df3eeb3..88547e483 100644 --- a/lib/src/screens/receive/anonpay_invoice_page.dart +++ b/lib/src/screens/receive/anonpay_invoice_page.dart @@ -8,7 +8,6 @@ import 'package:cake_wallet/src/screens/dashboard/widgets/present_receive_option import 'package:cake_wallet/src/screens/receive/widgets/anonpay_input_form.dart'; import 'package:cake_wallet/src/widgets/alert_with_one_action.dart'; import 'package:cake_wallet/src/widgets/keyboard_done_button.dart'; -import 'package:cake_wallet/utils/device_info.dart'; import 'package:cake_wallet/utils/responsive_layout_util.dart'; import 'package:cake_wallet/view_model/anon_invoice_page_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/receive_option_view_model.dart'; @@ -54,9 +53,7 @@ class AnonPayInvoicePage extends BasePage { AppBarStyle get appBarStyle => AppBarStyle.transparent; @override - void onClose(BuildContext context) { - Navigator.popUntil(context, ModalRoute.withName(Routes.dashboard)); - } + void onClose(BuildContext context) => Navigator.popUntil(context, (route) => route.isFirst); @override Widget middle(BuildContext context) => diff --git a/lib/src/screens/receive/anonpay_receive_page.dart b/lib/src/screens/receive/anonpay_receive_page.dart index 0c175eb19..4deae7972 100644 --- a/lib/src/screens/receive/anonpay_receive_page.dart +++ b/lib/src/screens/receive/anonpay_receive_page.dart @@ -32,28 +32,7 @@ class AnonPayReceivePage extends BasePage { bool get resizeToAvoidBottomInset => false; @override - Widget leading(BuildContext context) { - final _backButton = Icon( - Icons.arrow_back_ios, - color: Theme.of(context) - .accentTextTheme! - .displayMedium! - .backgroundColor!, - size: 16, - ); - - return SizedBox( - height: 37, - width: 37, - child: ButtonTheme( - minWidth: double.minPositive, - child: TextButton( - onPressed: () => - Navigator.pushNamedAndRemoveUntil(context, Routes.dashboard, (route) => false), - child: _backButton), - ), - ); - } + void onClose(BuildContext context) => Navigator.popUntil(context, (route) => route.isFirst); @override Widget middle(BuildContext context) { diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 4c903abf1..c1f684898 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -220,7 +220,7 @@ class WalletListBodyState extends State { await hideProgressText(); // only pop the wallets route in mobile as it will go back to dashboard page // in desktop platforms the navigation tree is different - if (ResponsiveLayoutUtil.instance.isMobile) { + if (ResponsiveLayoutUtil.instance.shouldRenderMobileUI()) { WidgetsBinding.instance.addPostFrameCallback((_) { Navigator.of(context).pop(); }); diff --git a/lib/utils/responsive_layout_util.dart b/lib/utils/responsive_layout_util.dart index 99c722887..4c06b7a3c 100644 --- a/lib/utils/responsive_layout_util.dart +++ b/lib/utils/responsive_layout_util.dart @@ -1,22 +1,32 @@ import 'package:flutter/material.dart'; class ResponsiveLayoutUtil { - static const double _kMobileThreshold = 768; + static const double _kMobileThreshold = 550; static const double kDesktopMaxWidthConstraint = 400; + static const double kDesktopMaxDashBoardWidthConstraint = 900; static const double kPopupWidth = 400; static const double kPopupSpaceHeight = 100; - static const _kIpadMaxWidth = 2560.0; const ResponsiveLayoutUtil._(); static final instance = ResponsiveLayoutUtil._(); bool get isMobile => - MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.width < _kMobileThreshold; + MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.shortestSide <= + _kMobileThreshold; - bool get isIpad { - final width = MediaQueryData.fromWindow(WidgetsBinding.instance.window).size.width; - return width >= _kMobileThreshold && !(width > _kIpadMaxWidth); + bool shouldRenderMobileUI() { + final mediaQuery = MediaQueryData.fromWindow(WidgetsBinding.instance.window); + final orientation = mediaQuery.orientation; + final width = mediaQuery.size.width; + final height = mediaQuery.size.height; + if (isMobile || + (orientation == Orientation.portrait && width < height) || + (orientation == Orientation.landscape && width < height)) { + return true; + } else { + return false; + } } /// Returns dynamic size.