Advertisement
DrAungWinHtut

aircon1.dart

Sep 30th, 2023
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.91 KB | Science | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   runApp(MyApp());
  5. }
  6.  
  7. class MyApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       title: 'Heat Gain Calculator',
  12.       theme: ThemeData(
  13.         primarySwatch: Colors.blue,
  14.       ),
  15.       home: HeatGainCalculator(),
  16.     );
  17.   }
  18. }
  19.  
  20. class HeatGainCalculator extends StatefulWidget {
  21.   @override
  22.   _HeatGainCalculatorState createState() => _HeatGainCalculatorState();
  23. }
  24.  
  25. class _HeatGainCalculatorState extends State<HeatGainCalculator> {
  26.   double uValue = 0.0;
  27.   double surfaceArea = 0.0;
  28.   double initialCLTD = 0.0;
  29.   double lm = 0.0;
  30.   double tr = 0.0;
  31.   double t0 = 0.0;
  32.   double f = 0.0;
  33.   double heatGain = 0.0;
  34.  
  35.   void calculateHeatGain() {
  36.     double updatedCLTD =
  37.     ((initialCLTD + lm) * f + (78 - tr) + (t0 - 85));
  38.  
  39.     setState(() {
  40.       heatGain = uValue * surfaceArea * updatedCLTD;
  41.     });
  42.   }
  43.  
  44.   @override
  45.   Widget build(BuildContext context) {
  46.     return Scaffold(
  47.       appBar: AppBar(
  48.         title: Text('Heat Gain Calculator'),
  49.       ),
  50.       body: Padding(
  51.         padding: const EdgeInsets.all(16.0),
  52.         child: Column(
  53.           crossAxisAlignment: CrossAxisAlignment.stretch,
  54.           children: <Widget>[
  55.             TextField(
  56.               keyboardType: TextInputType.number,
  57.               decoration: InputDecoration(labelText: 'Enter U Value (U)'),
  58.               onChanged: (value) {
  59.                 setState(() {
  60.                   uValue = double.tryParse(value) ?? 0.0;
  61.                 });
  62.               },
  63.             ),
  64.             TextField(
  65.               keyboardType: TextInputType.number,
  66.               decoration: InputDecoration(labelText: 'Enter Surface Area (A)'),
  67.               onChanged: (value) {
  68.                 setState(() {
  69.                   surfaceArea = double.tryParse(value) ?? 0.0;
  70.                 });
  71.               },
  72.             ),
  73.             TextField(
  74.               keyboardType: TextInputType.number,
  75.               decoration: InputDecoration(labelText: 'Enter Initial CLTD'),
  76.               onChanged: (value) {
  77.                 setState(() {
  78.                   initialCLTD = double.tryParse(value) ?? 0.0;
  79.                 });
  80.               },
  81.             ),
  82.             TextField(
  83.               keyboardType: TextInputType.number,
  84.               decoration: InputDecoration(labelText: 'Enter LM'),
  85.               onChanged: (value) {
  86.                 setState(() {
  87.                   lm = double.tryParse(value) ?? 0.0;
  88.                 });
  89.               },
  90.             ),
  91.             TextField(
  92.               keyboardType: TextInputType.number,
  93.               decoration: InputDecoration(labelText: 'Enter Tr'),
  94.               onChanged: (value) {
  95.                 setState(() {
  96.                   tr = double.tryParse(value) ?? 0.0;
  97.                 });
  98.               },
  99.             ),
  100.             TextField(
  101.               keyboardType: TextInputType.number,
  102.               decoration: InputDecoration(labelText: 'Enter T0'),
  103.               onChanged: (value) {
  104.                 setState(() {
  105.                   t0 = double.tryParse(value) ?? 0.0;
  106.                 });
  107.               },
  108.             ),
  109.             TextField(
  110.               keyboardType: TextInputType.number,
  111.               decoration: InputDecoration(labelText: 'Enter f'),
  112.               onChanged: (value) {
  113.                 setState(() {
  114.                   f = double.tryParse(value) ?? 0.0;
  115.                 });
  116.               },
  117.             ),
  118.             SizedBox(height: 16.0),
  119.             ElevatedButton(
  120.               onPressed: calculateHeatGain,
  121.               child: Text('Calculate Heat Gain'),
  122.             ),
  123.             SizedBox(height: 16.0),
  124.             Text(
  125.               'Heat Gain: $heatGain',
  126.               style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
  127.             ),
  128.           ],
  129.         ),
  130.       ),
  131.     );
  132.   }
  133. }
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement