import 'package:energy_bilance/models/EnergyBilanceModel.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; class MyInputWidget extends StatelessWidget { const MyInputWidget({super.key}); @override Widget build(BuildContext context) { final model = Provider.of(context); return Column( children: [ Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: TextFormField( keyboardType: TextInputType.number, inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.]'))], onChanged: (value) { double number = double.parse(value); model.setStartVelocity(number); }, validator: (value) { if(value == null){ return null; } final number = num.tryParse(value); if(number == null){ return '"$value" ist keine Zahl'; } return null; }, decoration: const InputDecoration( labelText: 'Anfangsgeschwindigkeit', hintText: 'in m/s' ), ) ), Expanded( child: TextFormField( keyboardType: TextInputType.number, inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.]'))], onChanged: (value) { double number = double.parse(value); model.setEndVelocity(number); }, decoration: const InputDecoration( labelText: 'Endgeschwindigkeit', hintText: 'in m/s' ), ) ), ], ), Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded( child: TextFormField( keyboardType: TextInputType.number, inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.]'))], onChanged: (value) { double number = double.parse(value); model.setStartHeight(number); }, decoration: const InputDecoration( labelText: 'Anfangshöhe', hintText: 'in m' ), ) ), Expanded( child: TextFormField( keyboardType: TextInputType.number, inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.]'))], onChanged: (value) { double number = double.parse(value); model.setEndHeight(number); }, decoration: const InputDecoration( labelText: 'Endhöhe', hintText: 'in m' ), ) ), ], ), Expanded( child: TextFormField( keyboardType: TextInputType.number, inputFormatters: [FilteringTextInputFormatter.allow(RegExp('[0-9.]'))], onChanged: (value) { double? number = double.tryParse(value); if(number != null){ model.setWeight(number); } }, decoration: const InputDecoration( labelText: 'Gewicht', hintText: 'in kg' ), ) ), ] ); } }