Added UI
parent
98dd45efbb
commit
565a49a6c6
|
@ -1,5 +1,6 @@
|
|||
# ---> Dart
|
||||
# See https://www.dartlang.org/guides/libraries/private-files
|
||||
.idea
|
||||
|
||||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/// free fall acceleration in m/s²
|
||||
const double g = 9.81;
|
||||
const double _g = 9.81;
|
||||
|
||||
///
|
||||
/// Potential Energy = [mass] * [height] * g
|
||||
/// with [mass] in kg, [height] in m and result in m²kg/s² = Joule
|
||||
double potential(double mass, double height) {
|
||||
return mass * height * g;
|
||||
return mass * height * _g;
|
||||
}
|
||||
|
||||
double freedPotential(double mass, double hStart, double hEnd) {
|
|
@ -0,0 +1,43 @@
|
|||
import 'package:energy/widgets/energy_input_widget.dart';
|
||||
import 'package:energy/widgets/energy_widget.dart';
|
||||
import 'package:energy/widgets/heat_capacity_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'models/energy_model.dart';
|
||||
|
||||
void main() => runApp(const EnergyApp());
|
||||
|
||||
class EnergyApp extends StatelessWidget {
|
||||
const EnergyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ChangeNotifierProvider(
|
||||
create: (_) => EnergyModel(),
|
||||
child: const MaterialApp(
|
||||
home: EnergyHomePage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EnergyHomePage extends StatelessWidget {
|
||||
const EnergyHomePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final EnergyModel e = context.watch<EnergyModel>();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Energy Calculation')),
|
||||
body: Column(
|
||||
children: [
|
||||
EnergyInputWidget(e: e),
|
||||
EnergyWidget(energy: e.energy),
|
||||
HeatCapacityWidget(water: e.water, iron: e.iron),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import 'package:energy/algorithms/energy.dart';
|
||||
import 'package:energy/algorithms/heat_capacity.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EnergyModel with ChangeNotifier {
|
||||
double _mass = 0.0; // in kg
|
||||
double _hStart = 0.0; // in m
|
||||
double _hEnd = 0.0;
|
||||
double _vStart = 0.0; // in m/s
|
||||
double _vEnd = 0.0;
|
||||
|
||||
double get mass => _mass;
|
||||
double get hStart => _hStart;
|
||||
double get hEnd => _hEnd;
|
||||
double get vStart => _vStart;
|
||||
double get vEnd => _vEnd;
|
||||
|
||||
set mass(double mass) {
|
||||
_mass = mass;
|
||||
notifyListeners();
|
||||
}
|
||||
set hStart(double height) {
|
||||
_hStart = height;
|
||||
notifyListeners();
|
||||
}
|
||||
set hEnd(double height) {
|
||||
_hEnd = height;
|
||||
notifyListeners();
|
||||
}
|
||||
set vStart(double velocity) {
|
||||
_vStart = velocity;
|
||||
notifyListeners();
|
||||
}
|
||||
set vEnd(double height) {
|
||||
_vEnd = height;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
get energy => freedEnergy(_mass, _hStart, _hEnd, _vStart, _vEnd);
|
||||
get water => literWaterThatCanBeBoiled(energy);
|
||||
get iron => kgIronThatCanBeHeatetUntilRed(energy);
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
import 'package:energy/algorithms/velocity.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../models/energy_model.dart';
|
||||
|
||||
class EnergyInputWidget extends StatelessWidget {
|
||||
const EnergyInputWidget({
|
||||
super.key,
|
||||
required this.e,
|
||||
});
|
||||
|
||||
final EnergyModel e;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Text("Mass ${e.mass.round()} kg"),
|
||||
Slider(
|
||||
value: e.mass,
|
||||
max: 50000,
|
||||
divisions: 1000,
|
||||
label: "Mass",
|
||||
onChanged: (double value) {
|
||||
e.mass = value;
|
||||
},
|
||||
),
|
||||
Text("Initial Velocity ${e.vStart.round()} m/s"),
|
||||
Slider(
|
||||
value: e.vStart,
|
||||
max: 1000,
|
||||
divisions: 1000,
|
||||
onChanged: (double value) {
|
||||
e.vStart = value;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class EnergyWidget extends StatelessWidget {
|
||||
const EnergyWidget({
|
||||
super.key,
|
||||
required this.energy,
|
||||
});
|
||||
|
||||
final double energy;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Text("Energy ${_format(energy)}Joule", style: Theme.of(context).textTheme.headlineLarge,);
|
||||
}
|
||||
|
||||
String _format(double e) {
|
||||
if (e > 1000000000000) {
|
||||
return "${(energy / 1000000000000).round()} T";
|
||||
} else if (e > 1000000000) {
|
||||
return "${(energy / 1000000000).round()} G";
|
||||
} else if (e > 1000000) {
|
||||
return "${(energy / 1000000).round()} M";
|
||||
} else if ( e > 1000) {
|
||||
return "${(energy / 1000).round()} k";
|
||||
} else {
|
||||
return "${energy.round()} ";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class HeatCapacityWidget extends StatelessWidget {
|
||||
const HeatCapacityWidget({
|
||||
super.key,
|
||||
required this.water,
|
||||
required this.iron,
|
||||
});
|
||||
|
||||
final double water;
|
||||
final double iron;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: [
|
||||
Text("${water.round()} liter water can be boiled", style: Theme.of(context).textTheme.headlineLarge,),
|
||||
Text("${iron.round()} kg iron can be heated", style: Theme.of(context).textTheme.headlineLarge,),]);
|
||||
}
|
||||
}
|
|
@ -6,11 +6,12 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.18.0 <3.0.0"
|
||||
sdk: ">=2.19.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
provider: ^6.0.0
|
||||
|
||||
dev_dependencies:
|
||||
test:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:energy/models/energy.dart';
|
||||
import 'package:energy/algorithms/energy.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
|
@ -1,4 +1,4 @@
|
|||
import 'package:energy/models/heat_capacity.dart';
|
||||
import 'package:energy/algorithms/heat_capacity.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
Loading…
Reference in New Issue