浏览代码

Start Add location flow when clicked on locationSuggestion

Neeraj Gupta 1 年之前
父节点
当前提交
4cf56a2fa2
共有 3 个文件被更改,包括 40 次插入8 次删除
  1. 12 0
      lib/services/search_service.dart
  2. 8 2
      lib/states/location_state.dart
  3. 20 6
      lib/ui/viewer/location/add_location_sheet.dart

+ 12 - 0
lib/services/search_service.dart

@@ -3,6 +3,7 @@ import "dart:math";
 import "package:flutter/cupertino.dart";
 import "package:flutter/cupertino.dart";
 import "package:intl/intl.dart";
 import "package:intl/intl.dart";
 import 'package:logging/logging.dart';
 import 'package:logging/logging.dart';
+import "package:photos/core/constants.dart";
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/core/event_bus.dart';
 import 'package:photos/data/holidays.dart';
 import 'package:photos/data/holidays.dart';
 import 'package:photos/data/months.dart';
 import 'package:photos/data/months.dart';
@@ -17,6 +18,7 @@ import "package:photos/models/file/extensions/file_props.dart";
 import 'package:photos/models/file/file.dart';
 import 'package:photos/models/file/file.dart';
 import 'package:photos/models/file/file_type.dart';
 import 'package:photos/models/file/file_type.dart';
 import "package:photos/models/local_entity_data.dart";
 import "package:photos/models/local_entity_data.dart";
+import "package:photos/models/location/location.dart";
 import "package:photos/models/location_tag/location_tag.dart";
 import "package:photos/models/location_tag/location_tag.dart";
 import 'package:photos/models/search/album_search_result.dart';
 import 'package:photos/models/search/album_search_result.dart';
 import 'package:photos/models/search/generic_search_result.dart';
 import 'package:photos/models/search/generic_search_result.dart';
@@ -25,6 +27,7 @@ import 'package:photos/services/collections_service.dart';
 import "package:photos/services/location_service.dart";
 import "package:photos/services/location_service.dart";
 import 'package:photos/services/semantic_search/semantic_search_service.dart';
 import 'package:photos/services/semantic_search/semantic_search_service.dart';
 import "package:photos/states/location_screen_state.dart";
 import "package:photos/states/location_screen_state.dart";
+import "package:photos/ui/viewer/location/add_location_sheet.dart";
 import "package:photos/ui/viewer/location/location_screen.dart";
 import "package:photos/ui/viewer/location/location_screen.dart";
 import 'package:photos/utils/date_time_util.dart';
 import 'package:photos/utils/date_time_util.dart';
 import "package:photos/utils/navigation_util.dart";
 import "package:photos/utils/navigation_util.dart";
@@ -772,6 +775,15 @@ class SearchService {
               ResultType.locationSuggestion,
               ResultType.locationSuggestion,
               city.city,
               city.city,
               results[city]!,
               results[city]!,
+              onResultTap: (ctx) {
+                Navigator.of(ctx).pop();
+                showAddLocationSheet(
+                  ctx,
+                  Location(latitude: city.lat, longitude: city.lng),
+                  name: city.city,
+                  radius: defaultCityRadius,
+                );
+              },
             ),
             ),
           );
           );
         }
         }

+ 8 - 2
lib/states/location_state.dart

@@ -14,11 +14,14 @@ import "package:photos/utils/debouncer.dart";
 class LocationTagStateProvider extends StatefulWidget {
 class LocationTagStateProvider extends StatefulWidget {
   final LocalEntity<LocationTag>? locationTagEntity;
   final LocalEntity<LocationTag>? locationTagEntity;
   final Location? centerPoint;
   final Location? centerPoint;
+  final double? radius;
   final Widget child;
   final Widget child;
   const LocationTagStateProvider(
   const LocationTagStateProvider(
     this.child, {
     this.child, {
     this.centerPoint,
     this.centerPoint,
     this.locationTagEntity,
     this.locationTagEntity,
+    // if the locationTagEntity is null, we use the centerPoint and radius
+    this.radius,
     super.key,
     super.key,
   });
   });
 
 
@@ -47,9 +50,12 @@ class _LocationTagStateProviderState extends State<LocationTagStateProvider> {
     ///If the location tag has a custom radius value, we add the custom radius
     ///If the location tag has a custom radius value, we add the custom radius
     ///value to the list of default radius values only for this location tag and
     ///value to the list of default radius values only for this location tag and
     ///keep it in the state of this widget.
     ///keep it in the state of this widget.
-    _radiusValues = _getRadiusValuesOfLocTag(_locationTagEntity?.item.radius);
+    _radiusValues = _getRadiusValuesOfLocTag(
+      _locationTagEntity?.item.radius ?? widget.radius,
+    );
 
 
-    _selectedRadius = _locationTagEntity?.item.radius ?? defaultRadiusValue;
+    _selectedRadius =
+        _locationTagEntity?.item.radius ?? widget.radius ?? defaultRadiusValue;
 
 
     _locTagEntityListener =
     _locTagEntityListener =
         Bus.instance.on<LocationTagUpdatedEvent>().listen((event) {
         Bus.instance.on<LocationTagUpdatedEvent>().listen((event) {

+ 20 - 6
lib/ui/viewer/location/add_location_sheet.dart

@@ -22,14 +22,20 @@ import "package:photos/ui/viewer/location/radius_picker_widget.dart";
 
 
 showAddLocationSheet(
 showAddLocationSheet(
   BuildContext context,
   BuildContext context,
-  Location coordinates,
-) {
+  Location coordinates, {
+  String name = '',
+  double radius = defaultRadiusValue,
+}) {
   showBarModalBottomSheet(
   showBarModalBottomSheet(
     context: context,
     context: context,
     builder: (context) {
     builder: (context) {
       return LocationTagStateProvider(
       return LocationTagStateProvider(
         centerPoint: coordinates,
         centerPoint: coordinates,
-        const AddLocationSheet(),
+        AddLocationSheet(
+          radius: radius,
+          name: name,
+        ),
+        radius: radius,
       );
       );
     },
     },
     shape: const RoundedRectangleBorder(
     shape: const RoundedRectangleBorder(
@@ -45,7 +51,13 @@ showAddLocationSheet(
 }
 }
 
 
 class AddLocationSheet extends StatefulWidget {
 class AddLocationSheet extends StatefulWidget {
-  const AddLocationSheet({super.key});
+  final double radius;
+  final String name;
+  const AddLocationSheet({
+    super.key,
+    this.radius = defaultRadiusValue,
+    this.name = '',
+  });
 
 
   @override
   @override
   State<AddLocationSheet> createState() => _AddLocationSheetState();
   State<AddLocationSheet> createState() => _AddLocationSheetState();
@@ -61,8 +73,7 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
   final ValueNotifier<bool> _submitNotifer = ValueNotifier(false);
   final ValueNotifier<bool> _submitNotifer = ValueNotifier(false);
 
 
   final ValueNotifier<bool> _cancelNotifier = ValueNotifier(false);
   final ValueNotifier<bool> _cancelNotifier = ValueNotifier(false);
-  final ValueNotifier<double> _selectedRadiusNotifier =
-      ValueNotifier(defaultRadiusValue);
+  late ValueNotifier<double> _selectedRadiusNotifier;
   final _focusNode = FocusNode();
   final _focusNode = FocusNode();
   final _textEditingController = TextEditingController();
   final _textEditingController = TextEditingController();
   final _isEmptyNotifier = ValueNotifier(true);
   final _isEmptyNotifier = ValueNotifier(true);
@@ -70,8 +81,11 @@ class _AddLocationSheetState extends State<AddLocationSheet> {
 
 
   @override
   @override
   void initState() {
   void initState() {
+    _textEditingController.text = widget.name;
     _focusNode.addListener(_focusNodeListener);
     _focusNode.addListener(_focusNodeListener);
+    _selectedRadiusNotifier = ValueNotifier(widget.radius);
     _selectedRadiusNotifier.addListener(_selectedRadiusListener);
     _selectedRadiusNotifier.addListener(_selectedRadiusListener);
+
     super.initState();
     super.initState();
   }
   }