diff options
Diffstat (limited to 'lib/page_hvac.dart')
-rw-r--r-- | lib/page_hvac.dart | 168 |
1 files changed, 80 insertions, 88 deletions
diff --git a/lib/page_hvac.dart b/lib/page_hvac.dart index ea6dd3b..d416a1b 100644 --- a/lib/page_hvac.dart +++ b/lib/page_hvac.dart @@ -1,6 +1,5 @@ -import 'dart:math'; - import 'package:flutter/material.dart'; +import 'package:flutter_homescreen/layout_size_helper.dart'; import 'package:numberpicker/numberpicker.dart'; class HVACPageContainer extends StatelessWidget { @@ -16,9 +15,7 @@ class HVACPageContainer extends StatelessWidget { } class _TemperatureSelector extends StatefulWidget { -final double referenceFontSize = 24; - - _TemperatureSelector({Key? key, referenceFontSize}) : super(key: key); + _TemperatureSelector({Key? key}) : super(key: key); @override _TemperatureSelectorState createState() => _TemperatureSelectorState(); @@ -29,6 +26,7 @@ class _TemperatureSelectorState extends State<_TemperatureSelector> { @override Widget build(BuildContext context) { + var sizeHelper = LayoutSizeHelper(context); return Column( children: <Widget>[ NumberPicker( @@ -38,14 +36,14 @@ class _TemperatureSelectorState extends State<_TemperatureSelector> { onChanged: (value) => setState(() => _currentValue = value), textStyle: DefaultTextStyle.of(context).style.copyWith( color: Colors.teal.shade200, - fontSize: widget.referenceFontSize, + fontSize: sizeHelper.baseFontSize, ), selectedTextStyle: DefaultTextStyle.of(context).style.copyWith( color: Colors.white, - fontSize: widget.referenceFontSize * 1.5, + fontSize: sizeHelper.baseFontSize * 1.5, ), - itemHeight: widget.referenceFontSize * 3, - itemWidth: widget.referenceFontSize * 6, + itemHeight: sizeHelper.baseFontSize * 3, + itemWidth: sizeHelper.baseFontSize * 6, ), ], ); @@ -72,16 +70,16 @@ class _HVACFanSpeedState extends State<HVACFanSpeed> { inactiveTrackColor: Colors.blueGrey.shade200, ), child: Slider( - value: _currentSliderValue, - min: 0, - max: 300, - label: _currentSliderValue.round().toString(), - onChanged: (double value) { - setState(() { - _currentSliderValue = value; - }); - }, - ), + value: _currentSliderValue, + min: 0, + max: 300, + label: _currentSliderValue.round().toString(), + onChanged: (double value) { + setState(() { + _currentSliderValue = value; + }); + }, + ), ); } } @@ -102,82 +100,75 @@ bool selected = true; // Get from API class _HVACPageState extends State<HVACPage> { final double fanSpeed = 20; - Widget _buildLayout(BuildContext context, BoxConstraints constraints) { - // describe the layout in terms of fractions of the container size - double mainDimension = max(constraints.maxWidth, constraints.maxHeight); - double minDimension = min(constraints.maxWidth, constraints.maxHeight); - double iconSize = mainDimension / 12.0; - double largeIconSize = mainDimension / 8.0; - double spacingSize = minDimension / 48.0; - double buttonWidth = constraints.maxWidth / 6.0; - double buttonHeight = constraints.maxHeight / 6.0; - double defaultFontSize = constraints.maxHeight / 24.0; + @override + Widget build(BuildContext context) { + var sizeHelper = LayoutSizeHelper(context); TextStyle buttonTextStyle = DefaultTextStyle.of(context).style.copyWith( color: Colors.white, - fontSize: defaultFontSize, + fontSize: sizeHelper.baseFontSize, ); Widget fanSpeedControl = Container( padding: EdgeInsets.symmetric( - vertical: spacingSize, - horizontal: 3 * spacingSize, + vertical: sizeHelper.defaultPadding, + horizontal: 3.0 * sizeHelper.defaultPadding, ), child: Row( children: [ Expanded(flex: 4, child: const HVACFanSpeed()), - SizedBox(width: spacingSize), + SizedBox(width: sizeHelper.defaultPadding), Expanded( flex: 1, child: Image.asset('images/HMI_HVAC_Fan_Icon.png', - width: iconSize, height: iconSize, fit: BoxFit.contain)), + width: sizeHelper.defaultIconSize, + height: sizeHelper.defaultIconSize, + fit: BoxFit.contain)), ], ), ); Widget rightSeat = Container( - padding: EdgeInsets.all(spacingSize), + padding: EdgeInsets.all(sizeHelper.defaultPadding), child: Column( children: [ IconButton( - iconSize: largeIconSize, + iconSize: sizeHelper.largeIconSize, icon: Image.asset(selected ? chairOn : chairOff, - width: largeIconSize, - height: largeIconSize, + width: sizeHelper.largeIconSize, + height: sizeHelper.largeIconSize, fit: BoxFit.contain), onPressed: () { selected = !selected; }, ), - SizedBox(height: spacingSize), - _TemperatureSelector( - referenceFontSize: defaultFontSize, - ), + SizedBox(height: sizeHelper.defaultPadding), + _TemperatureSelector(), ], ), ); Widget leftSeat = Container( - padding: EdgeInsets.all(spacingSize), + padding: EdgeInsets.all(sizeHelper.defaultPadding), child: Column( children: [ Image.asset('images/HMI_HVAC_Right_Chair_ON.png', - width: largeIconSize, height: largeIconSize, fit: BoxFit.contain), - SizedBox(height: spacingSize), - _TemperatureSelector( - referenceFontSize: defaultFontSize, - ), + width: sizeHelper.largeIconSize, + height: sizeHelper.largeIconSize, + fit: BoxFit.contain), + SizedBox(height: sizeHelper.defaultPadding), + _TemperatureSelector(), ], ), ); Widget centerView = Container( - padding: EdgeInsets.all(spacingSize), + padding: EdgeInsets.all(sizeHelper.defaultPadding), child: Column( children: [ Container( - width: buttonWidth, - height: buttonHeight, - margin: EdgeInsets.all(spacingSize), + width: sizeHelper.defaultButtonWidth, + height: sizeHelper.defaultButtonHeight, + margin: EdgeInsets.all(sizeHelper.defaultPadding), decoration: BoxDecoration( border: Border.all(color: Colors.green), borderRadius: BorderRadius.circular(20)), @@ -189,9 +180,9 @@ class _HVACPageState extends State<HVACPage> { ), ), Container( - width: buttonWidth, - height: buttonHeight, - margin: EdgeInsets.all(spacingSize), + width: sizeHelper.defaultButtonWidth, + height: sizeHelper.defaultButtonHeight, + margin: EdgeInsets.all(sizeHelper.defaultPadding), decoration: BoxDecoration( border: Border.all(color: Colors.green), borderRadius: BorderRadius.circular(20)), @@ -203,9 +194,9 @@ class _HVACPageState extends State<HVACPage> { ), ), Container( - width: buttonWidth, - height: buttonHeight, - margin: EdgeInsets.all(spacingSize), + width: sizeHelper.defaultButtonWidth, + height: sizeHelper.defaultButtonHeight, + margin: EdgeInsets.all(sizeHelper.defaultPadding), decoration: BoxDecoration( border: Border.all(color: Colors.green), borderRadius: BorderRadius.circular(20)), @@ -214,56 +205,57 @@ class _HVACPageState extends State<HVACPage> { // Respond to button press }, child: Image.asset('images/HMI_HVAC_Circulation_Inactive.png', - width: iconSize, height: iconSize, fit: BoxFit.contain)), + width: sizeHelper.defaultIconSize, + height: sizeHelper.defaultIconSize, + fit: BoxFit.contain)), ), ], ), ); Widget actions = Container( - padding: EdgeInsets.all(spacingSize), + padding: EdgeInsets.all(sizeHelper.defaultPadding), child: Column( children: [ Image.asset('images/HMI_HVAC_AirDown_Inactive.png', - width: iconSize, height: iconSize, fit: BoxFit.contain), - SizedBox(height: spacingSize), + width: sizeHelper.defaultIconSize, + height: sizeHelper.defaultIconSize, + fit: BoxFit.contain), + SizedBox(height: sizeHelper.defaultPadding), Image.asset('images/HMI_HVAC_AirUp_Inactive.png', - width: iconSize, height: iconSize, fit: BoxFit.contain), - SizedBox(height: spacingSize), + width: sizeHelper.defaultIconSize, + height: sizeHelper.defaultIconSize, + fit: BoxFit.contain), + SizedBox(height: sizeHelper.defaultPadding), Image.asset('images/HMI_HVAC_Front_Inactive.png', - width: iconSize, height: iconSize, fit: BoxFit.contain), - SizedBox(height: spacingSize), + width: sizeHelper.defaultIconSize, + height: sizeHelper.defaultIconSize, + fit: BoxFit.contain), + SizedBox(height: sizeHelper.defaultPadding), Image.asset('images/HMI_HVAC_Rear_Active.png', - width: iconSize, height: iconSize, fit: BoxFit.contain), + width: sizeHelper.defaultIconSize, + height: sizeHelper.defaultIconSize, + fit: BoxFit.contain), ], - ), ); - return Column( - mainAxisAlignment: MainAxisAlignment.center, - children: <Widget>[ - fanSpeedControl, - Row(children: [ - Expanded(flex: 1, child: rightSeat), - Expanded(flex: 1, child: centerView), - Expanded(flex: 1, child: leftSeat), - Expanded(flex: 1, child: actions) - ]) - ], - ); - } - - @override - Widget build(BuildContext context) { return Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topRight, end: Alignment.bottomLeft, colors: [Colors.blueGrey.shade900, Colors.grey.shade900])), - child: Center( - child: LayoutBuilder( - builder: _buildLayout, - ))); + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: <Widget>[ + fanSpeedControl, + Row(children: [ + Expanded(flex: 1, child: rightSeat), + Expanded(flex: 1, child: centerView), + Expanded(flex: 1, child: leftSeat), + Expanded(flex: 1, child: actions) + ]) + ], + )); } } |