Bladeren bron

Refactor: Removed some type conversions

ashilkn 2 jaren geleden
bovenliggende
commit
1e9d211a4b

+ 1 - 1
lib/core/constants.dart

@@ -60,7 +60,7 @@ const publicLinkDeviceLimits = [50, 25, 10, 5, 2, 1];
 
 const kilometersPerDegree = 111.16;
 
-const radiusValues = <double>[2, 10, 20, 40, 80, 200, 400, 1200];
+const radiusValues = <int>[2, 10, 20, 40, 80, 200, 400, 1200];
 
 const defaultRadiusValueIndex = 4;
 

+ 2 - 2
lib/ui/viewer/location/add_location_gallery_widget.dart

@@ -61,7 +61,7 @@ class _AddLocationGalleryWidgetState extends State<AddLocationGalleryWidget> {
 
   @override
   Widget build(BuildContext context) {
-    final selectedRadius = _selectedRadius().toInt();
+    final selectedRadius = _selectedRadius();
     late final int memoryCount;
     Future<FileLoadResult> filterFiles() async {
       final FileLoadResult result = await fileLoadResult;
@@ -125,7 +125,7 @@ class _AddLocationGalleryWidgetState extends State<AddLocationGalleryWidget> {
     );
   }
 
-  double _selectedRadius() {
+  int _selectedRadius() {
     return radiusValues[
         InheritedLocationTagData.of(context).selectedRadiusIndex];
   }

+ 6 - 10
lib/ui/viewer/location/radius_picker_widget.dart

@@ -28,9 +28,10 @@ class RadiusPickerWidget extends StatefulWidget {
 }
 
 class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
-  double selectedIndex = defaultRadiusValueIndex.toDouble();
+  int selectedRadiusIndex = defaultRadiusValueIndex;
   @override
   Widget build(BuildContext context) {
+    final radiusValue = radiusValues[selectedRadiusIndex];
     final textTheme = getEnteTextTheme(context);
     final colorScheme = getEnteColorScheme(context);
     return Row(
@@ -51,8 +52,8 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
               Expanded(
                 flex: 6,
                 child: Text(
-                  _selectedRadius(context).toInt().toString(),
-                  style: _selectedRadius(context) != 1200
+                  radiusValue.toString(),
+                  style: radiusValue != 1200
                       ? textTheme.largeBold
                       : textTheme.bodyBold,
                   textAlign: TextAlign.center,
@@ -100,10 +101,10 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
                     ),
                     child: RepaintBoundary(
                       child: Slider(
-                        value: selectedIndex,
+                        value: selectedRadiusIndex.toDouble(),
                         onChanged: (value) {
                           setState(() {
-                            selectedIndex = value;
+                            selectedRadiusIndex = value.toInt();
                           });
 
                           InheritedLocationTagData.of(
@@ -127,9 +128,4 @@ class _RadiusPickerWidgetState extends State<RadiusPickerWidget> {
       ],
     );
   }
-
-  double _selectedRadius(BuildContext context) {
-    return radiusValues[
-        InheritedLocationTagData.of(context).selectedRadiusIndex];
-  }
 }