added tapbarview to display data

main
Julian Gegner 2022-11-07 22:12:21 +01:00
parent 827306b137
commit a60e9f968b
11 changed files with 110 additions and 149 deletions

View File

@ -1,9 +1,7 @@
import 'package:energy_bilance/models/EnergyBilanceModel.dart'; import 'package:energy_bilance/models/EnergyBilanceModel.dart';
import 'package:energy_bilance/models/MyInputModel.dart'; import 'package:energy_bilance/widgets/EnergyDisplay.dart';
import 'package:energy_bilance/widgets/MyCustomForm.dart';
import 'package:energy_bilance/widgets/MyInputWidget.dart'; import 'package:energy_bilance/widgets/MyInputWidget.dart';
import 'package:energy_bilance/widgets/MyTest.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -17,15 +15,11 @@ void main() {
child: Center( child: Center(
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: const [
const Expanded(child: MyInputWidget()), Expanded(child: MyInputWidget()),
Expanded( Divider(),
child: Consumer<EnergyBilanceModel>( Expanded(child: EnergyDisplay()),
builder: (context, model, child){
return Text('Generierte Ekin: ${model.kineticEnergy}');
}
))
], ],
) )

View File

@ -11,14 +11,26 @@ class EnergyBilanceModel extends ChangeNotifier {
double _weight = 0; double _weight = 0;
static const double _gravity = 9.81; //in m/s^2 final double _gravity = 9.81; //in m/s^2
final double _waterHeatCapacity = 4.181; //J / (g * C°)
final double _ironHeatCapacity = 0.439; //in J / (g * C°)
double _waterTemparatureStart = 20; //in °C
final int _temparatureToBoilWater = 100; //in °C
double _ironTemparatureStart = 20; //in °C
final int _temparatureToMakeIronGlow = 700; //in °C
double get deltaVelocity => _endVelocity - _startVelocity; double get deltaVelocity => _endVelocity - _startVelocity;
double get deltaHeight => _endHeight - _startHeight; double get deltaHeight => _endHeight - _startHeight;
double get potentialEnergy => _weight * _gravity * deltaHeight; double get potentialEnergy => _weight * _gravity * deltaHeight; //in Joule = m^2 kg/s^2
double get kineticEnergy => _weight * pow(deltaVelocity, 2) / 2; double get kineticEnergy => _weight * pow(deltaVelocity, 2) / 2;
double get amountOfBoilingWaterInL => (((potentialEnergy + kineticEnergy) / _waterHeatCapacity) / (_temparatureToBoilWater - _waterTemparatureStart)) / 1000; //in litre
double get amountOfGlowingIronInKg => (((potentialEnergy + kineticEnergy) / _ironHeatCapacity) / (_temparatureToMakeIronGlow - _ironTemparatureStart)) / 1000;
void setStartVelocity(double v){ void setStartVelocity(double v){
_startVelocity = v; _startVelocity = v;
notifyListeners(); notifyListeners();

View File

@ -1,12 +0,0 @@
import 'package:flutter/cupertino.dart';
class MyInputModel extends ChangeNotifier {
String _text = "Hallo Welt";
String get currentText => _text;
void changeText(String newText) {
_text = newText;
notifyListeners();
}
}

View File

@ -0,0 +1,49 @@
import 'package:energy_bilance/models/EnergyBilanceModel.dart';
import 'package:energy_bilance/widgets/TabDisplayWidget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class EnergyDisplay extends StatelessWidget {
const EnergyDisplay({super.key});
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Energie umrechnen in:'),
bottom: const TabBar(
tabs: [
Tab(text: 'Wasser', icon: Icon(Icons.anchor_sharp),),
Tab(text: 'Eisen', icon: Icon(Icons.iron)),
Tab(text: 'Energie', icon: Icon(Icons.battery_charging_full),)
]
),
),
body: TabBarView(
children: [
Consumer<EnergyBilanceModel>(
builder: (context, model, child){
return TabDisplayWidget('Wasser, das von 20 °C zum Kochen gebracht werden kann: ${double.parse((model.amountOfBoilingWaterInL).toStringAsFixed(2))} Liter');
}
),
Consumer<EnergyBilanceModel>(
builder: (context, model, child){
return TabDisplayWidget('Eisen, das von 20 °C zum Glühen gebracht werden kann: ${double.parse((model.amountOfGlowingIronInKg).toStringAsFixed(2))} Kilo');
}
),
Consumer<EnergyBilanceModel>(
builder: (context, model, child){
return TabDisplayWidget('Generierte potentielle Energie: ${model.potentialEnergy}\n'
'Generierte kinetische Energie: ${model.kineticEnergy}');
}
),
]
),
)
);
}
}

View File

@ -1,25 +0,0 @@
import 'package:flutter/material.dart';
class MyAppBar extends StatelessWidget {
const MyAppBar({required this.title, super.key});
final Widget title;
@override
Widget build(BuildContext context) {
return Container(
height: 56.0,
padding: const EdgeInsets.symmetric(horizontal: 8.0),
decoration: BoxDecoration(color: Colors.blue[500]),
child: Row(
children: [
const IconButton(onPressed: null, icon: Icon(Icons.menu), tooltip: 'Navigation Menu'),
Expanded(child: title),
const IconButton(onPressed: null, icon: Icon(Icons.search), tooltip: 'Search')
],
),
);
}
}

View File

@ -1,43 +0,0 @@
import 'package:energy_bilance/models/MyInputModel.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class MyCustomForm extends StatefulWidget {
const MyCustomForm({super.key});
@override
State<StatefulWidget> createState() {
return MyCustomFormState();
}
}
class MyCustomFormState extends State<MyCustomForm> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Form(
key: _formKey,
child: Column(
children: <Widget>[
TextFormField(
decoration: const InputDecoration(
labelText: 'Gib was ein',
hintText: 'keine Zahlen bidde'
),
validator: (String? value) {
return (value != null && value.contains('@')) ? 'Do not use the @ char.' : null;
},
onChanged: (value) {
Provider.of<MyInputModel>(context, listen: false).changeText(value);
}
)
],
),
);
}
}

View File

@ -15,7 +15,7 @@ class MyInputWidget extends StatelessWidget {
children: [ children: [
Row( Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Expanded( Expanded(

View File

@ -1,24 +0,0 @@
import 'package:energy_bilance/widgets/MyAppBar.dart';
import 'package:flutter/material.dart';
class MyScaffold extends StatelessWidget {
const MyScaffold({super.key});
@override
Widget build(BuildContext context) {
return Material(
child: Column(
children: [
MyAppBar(title: Text('MyAppBar', style: Theme.of(context).primaryTextTheme.headline6)),
const Expanded(child:
Center(
child: Text("Hello World!"),
)
)
],
),
);
}
}

View File

@ -1,30 +0,0 @@
import 'package:energy_bilance/models/MyInputModel.dart';
import 'package:energy_bilance/widgets/MyCustomForm.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class MyTest extends StatelessWidget {
const MyTest({super.key});
@override
Widget build(BuildContext context) {
return Material(
child:
ChangeNotifierProvider(create: (context) => MyInputModel(),
child: Column(
children: [
const MyCustomForm(),
Consumer<MyInputModel>(
builder: (context, input, child){
return Text('Das ist die Eingabe: ${input.currentText}');
}
),
],
),
)
);
}
}

View File

@ -0,0 +1,19 @@
import 'package:flutter/cupertino.dart';
class TabDisplayWidget extends StatelessWidget {
String _displayText = "";
TabDisplayWidget(String displayText, {super.key}) {
_displayText = displayText;
}
@override
Widget build(BuildContext context) {
return Center(
child: Text(_displayText)
);
}
}

View File

@ -0,0 +1,21 @@
import 'dart:async';
import 'package:energy_bilance/models/EnergyBilanceModel.dart';
void main() async {
//Location _locationModel;StreamController<Location> _controller;setUp(() {
_controller = StreamController<EnergyBilanceModel>();
_energyModel = EnergyBilanceModel();
});group('[Location Model]', () {
//test('[Model] Check individual values', () async {
_locationModel = Location(
city: 'London',
countryName: 'England',
country: 'England',
currency: 'GBP',
ip: '',
inEu: true,
languages: 'EN',
);// BEGIN TESTS....
expect(_locationModel.city, 'London');expect(_locationModel.countryName.runtimeType, equals(String));expect(_locationModel.country, isNotNull);expect(_locationModel.ip, isEmpty);expect(_locationModel.inEu, isTrue);expect(_locationModel.languages, contains('EN'));expect(_locationModel.currency, startsWith('G'));expect(_locationModel.country, matches('England'));
});}