Skip to content

Commit

Permalink
Fixed #6
Browse files Browse the repository at this point in the history
  • Loading branch information
YarosMallorca committed Sep 4, 2024
1 parent 6a9e43f commit e31e3fc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions lib/components/text_field.dart
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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;

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/layouts/aircraft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class _AircraftBarState extends State<AircraftBar> {
listenables.speed = speed;
_updateSettings(listenables);
},
decimal: true),
decimals: 1),
],
),
),
Expand Down
7 changes: 4 additions & 3 deletions lib/layouts/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class _CameraBarState extends State<CameraBar> {
child: Text(_presets[i].name),
)),
onChanged: (item) {
_presets = PresetManager.getPresets();
listenables.selectedCameraPreset = item ?? _presets[0];

// Update listenables
Expand Down Expand Up @@ -188,7 +189,7 @@ class _CameraBarState extends State<CameraBar> {
_updatePreset(listenables);
},
defaultValue: listenables.sensorWidth,
decimal: true,
decimals: 1,
enabled: !listenables.selectedCameraPreset!.defaultPreset,
),
CustomTextField(
Expand All @@ -200,7 +201,7 @@ class _CameraBarState extends State<CameraBar> {
listenables.sensorHeight = mm;
_updatePreset(listenables);
},
decimal: true,
decimals: 1,
enabled: !listenables.selectedCameraPreset!.defaultPreset,
),
CustomTextField(
Expand All @@ -212,7 +213,7 @@ class _CameraBarState extends State<CameraBar> {
listenables.focalLength = mm;
_updatePreset(listenables);
},
decimal: true,
decimals: 2,
enabled: !listenables.selectedCameraPreset!.defaultPreset,
),
],
Expand Down

0 comments on commit e31e3fc

Please sign in to comment.