Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_configs/theme_helper.dart';
5 : import 'package:material_ui/material_ui.dart';
6 :
7 : typedef ScreenHelperState = ({
8 : bool isWide,
9 : bool isBottom,
10 : bool isWearable,
11 : bool isRight,
12 : bool isLeftBar,
13 : double height,
14 : double width,
15 : });
16 :
17 : class ScreenHelper {
18 : static ScreenHelper? _instance;
19 : bool isWide = false;
20 : bool isBottom = false;
21 : bool isWearable = false;
22 : bool isRight = false;
23 : bool isLeftBar = false;
24 : double height = 0;
25 : double width = 0;
26 : double originWidth = 0;
27 :
28 6 : @protected
29 : ScreenHelper(BuildContext context, BoxConstraints constraints) {
30 6 : init(context, constraints);
31 : }
32 :
33 6 : void init(BuildContext context, BoxConstraints constraints) {
34 12 : isWide = ThemeHelper.isWideScreen(constraints);
35 12 : isBottom = ThemeHelper.isNavBottom(constraints);
36 12 : isWearable = ThemeHelper.isWearableMode(context, constraints);
37 12 : isRight = ThemeHelper.isNavRight(context, constraints);
38 12 : isLeftBar = isRight && ThemeHelper.getHeight(context) < 520;
39 12 : height = ThemeHelper.getHeight(context);
40 12 : originWidth = ThemeHelper.getWidth(context);
41 12 : width = ThemeHelper.getWidth(context, 0, constraints);
42 : }
43 :
44 6 : static ScreenHelperState state() => _instance == null
45 : ? (
46 : isWide: false,
47 : isBottom: false,
48 : isWearable: false,
49 : isRight: false,
50 : isLeftBar: false,
51 : height: 0,
52 : width: 0,
53 : )
54 : : (
55 6 : isWide: _instance!.isWide,
56 6 : isBottom: _instance!.isBottom,
57 6 : isWearable: _instance!.isWearable,
58 6 : isRight: _instance!.isRight,
59 6 : isLeftBar: _instance!.isLeftBar,
60 6 : height: _instance!.height,
61 6 : width: _instance!.width,
62 : );
63 :
64 6 : static ScreenHelperState getInstance(BuildContext context, BoxConstraints constraints) {
65 6 : _instance ??= ScreenHelper(context, constraints);
66 18 : if (_instance?.originWidth != ThemeHelper.getWidth(context)) {
67 0 : _instance?.init(context, constraints);
68 : }
69 6 : return state();
70 : }
71 : }
|