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:flutter/material.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 0 : @protected 29 : ScreenHelper(BuildContext context, BoxConstraints constraints) { 30 0 : init(context, constraints); 31 : } 32 : 33 0 : void init(BuildContext context, BoxConstraints constraints) { 34 0 : isWide = ThemeHelper.isWideScreen(constraints); 35 0 : isBottom = ThemeHelper.isNavBottom(constraints); 36 0 : isWearable = ThemeHelper.isWearableMode(context, constraints); 37 0 : isRight = ThemeHelper.isNavRight(context, constraints); 38 0 : isLeftBar = ThemeHelper.getHeight(context) < 520; 39 0 : height = ThemeHelper.getHeight(context); 40 0 : originWidth = ThemeHelper.getWidth(context); 41 0 : width = ThemeHelper.getWidth(context, 0, constraints); 42 : } 43 : 44 0 : 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 0 : isWide: _instance!.isWide, 56 0 : isBottom: _instance!.isBottom, 57 0 : isWearable: _instance!.isWearable, 58 0 : isRight: _instance!.isRight, 59 0 : isLeftBar: _instance!.isLeftBar, 60 0 : height: _instance!.height, 61 0 : width: _instance!.width, 62 : ); 63 : 64 0 : static ScreenHelperState getInstance(BuildContext context, BoxConstraints constraints) { 65 0 : _instance ??= ScreenHelper(context, constraints); 66 0 : if (_instance?.originWidth != ThemeHelper.getWidth(context)) { 67 0 : _instance?.init(context, constraints); 68 : } 69 0 : return state(); 70 : } 71 : }