2023-04-14 04:39:08 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-11-03 05:42:18 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2023-04-14 04:39:08 +00:00
|
|
|
|
2023-11-03 05:42:18 +00:00
|
|
|
part 'responsive_layout_util.g.dart';
|
|
|
|
|
|
|
|
class _ResponsiveLayoutUtil = ResponsiveLayoutUtilBase with _$_ResponsiveLayoutUtil;
|
|
|
|
|
|
|
|
abstract class ResponsiveLayoutUtilBase with Store, WidgetsBindingObserver {
|
2024-05-23 15:21:51 +00:00
|
|
|
static const double kMobileThreshold = 550;
|
2023-04-14 04:39:08 +00:00
|
|
|
static const double kDesktopMaxWidthConstraint = 400;
|
2023-07-13 13:05:52 +00:00
|
|
|
static const double kDesktopMaxDashBoardWidthConstraint = 900;
|
2023-04-14 04:39:08 +00:00
|
|
|
static const double kPopupWidth = 400;
|
|
|
|
static const double kPopupSpaceHeight = 100;
|
|
|
|
|
2023-11-03 05:42:18 +00:00
|
|
|
ResponsiveLayoutUtilBase() {
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
final initialMediaQuery = MediaQueryData.fromView(WidgetsBinding.instance!.window);
|
|
|
|
updateDeviceInfo(initialMediaQuery);
|
2023-04-14 04:39:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-03 05:42:18 +00:00
|
|
|
@override
|
|
|
|
void didChangeMetrics() {
|
|
|
|
final mediaQuery = MediaQueryData.fromView(WidgetsBinding.instance!.window);
|
|
|
|
updateDeviceInfo(mediaQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
@observable
|
|
|
|
double screenWidth = 0.0;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
double screenHeight = 0.0;
|
|
|
|
|
|
|
|
@observable
|
|
|
|
Orientation orientation = Orientation.portrait;
|
|
|
|
|
|
|
|
@action
|
|
|
|
void updateDeviceInfo(MediaQueryData mediaQuery) {
|
|
|
|
orientation = mediaQuery.orientation;
|
|
|
|
screenWidth = mediaQuery.size.width;
|
|
|
|
screenHeight = mediaQuery.size.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
|
|
|
bool get shouldRenderMobileUI {
|
2024-05-23 15:21:51 +00:00
|
|
|
return (screenWidth <= kMobileThreshold) ||
|
2023-11-03 05:42:18 +00:00
|
|
|
(orientation == Orientation.portrait && screenWidth < screenHeight) ||
|
|
|
|
(orientation == Orientation.landscape && screenWidth < screenHeight);
|
2023-04-14 04:39:08 +00:00
|
|
|
}
|
2024-04-10 01:28:31 +00:00
|
|
|
|
|
|
|
bool get shouldRenderTabletUI {
|
2024-05-23 15:21:51 +00:00
|
|
|
return screenWidth > kMobileThreshold && screenWidth < kDesktopMaxDashBoardWidthConstraint;
|
2024-04-10 01:28:31 +00:00
|
|
|
}
|
2023-04-14 04:39:08 +00:00
|
|
|
}
|
2023-11-03 05:42:18 +00:00
|
|
|
|
|
|
|
_ResponsiveLayoutUtil _singletonResponsiveLayoutUtil = _ResponsiveLayoutUtil();
|
|
|
|
|
|
|
|
_ResponsiveLayoutUtil get responsiveLayoutUtil => _singletonResponsiveLayoutUtil;
|