diff --git a/lib/components/text_field.dart b/lib/components/text_field.dart index 566fc08..6689959 100644 --- a/lib/components/text_field.dart +++ b/lib/components/text_field.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_spinbox/material.dart'; +import 'dart:math' as math; class CustomTextField extends StatelessWidget { const CustomTextField( @@ -10,13 +11,13 @@ class CustomTextField extends StatelessWidget { required this.defaultValue, required this.onChanged, this.enabled = true, - this.decimal}); + this.decimals}); final String labelText; final double min; final double max; final num defaultValue; - final bool? decimal; + final int? decimals; final bool enabled; final void Function(double) onChanged; @@ -26,8 +27,8 @@ class CustomTextField extends StatelessWidget { padding: const EdgeInsets.all(8.0), child: SpinBox( enabled: enabled, - step: decimal != null ? 0.1 : 1, - decimals: decimal != null ? 1 : 0, + step: decimals != null ? math.pow(10.0, -decimals!).toDouble() : 1, + decimals: decimals ?? 0, keyboardType: TextInputType.number, min: min, max: max, diff --git a/lib/layouts/aircraft.dart b/lib/layouts/aircraft.dart index b7e9394..8678a44 100644 --- a/lib/layouts/aircraft.dart +++ b/lib/layouts/aircraft.dart @@ -79,7 +79,7 @@ class _AircraftBarState extends State { listenables.speed = speed; _updateSettings(listenables); }, - decimal: true), + decimals: 1), ], ), ), diff --git a/lib/layouts/camera.dart b/lib/layouts/camera.dart index 349b048..bb157e4 100644 --- a/lib/layouts/camera.dart +++ b/lib/layouts/camera.dart @@ -104,6 +104,7 @@ class _CameraBarState extends State { child: Text(_presets[i].name), )), onChanged: (item) { + _presets = PresetManager.getPresets(); listenables.selectedCameraPreset = item ?? _presets[0]; // Update listenables @@ -188,7 +189,7 @@ class _CameraBarState extends State { _updatePreset(listenables); }, defaultValue: listenables.sensorWidth, - decimal: true, + decimals: 1, enabled: !listenables.selectedCameraPreset!.defaultPreset, ), CustomTextField( @@ -200,7 +201,7 @@ class _CameraBarState extends State { listenables.sensorHeight = mm; _updatePreset(listenables); }, - decimal: true, + decimals: 1, enabled: !listenables.selectedCameraPreset!.defaultPreset, ), CustomTextField( @@ -212,7 +213,7 @@ class _CameraBarState extends State { listenables.focalLength = mm; _updatePreset(listenables); }, - decimal: true, + decimals: 2, enabled: !listenables.selectedCameraPreset!.defaultPreset, ), ],