Explorar o código

Add location search interface

Vishnu Mohandas %!s(int64=5) %!d(string=hai) anos
pai
achega
768afb10db
Modificáronse 3 ficheiros con 98 adicións e 10 borrados
  1. 82 9
      lib/ui/search_page.dart
  2. 14 0
      pubspec.lock
  3. 2 1
      pubspec.yaml

+ 82 - 9
lib/ui/search_page.dart

@@ -1,4 +1,6 @@
+import 'package:dio/dio.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter_typeahead/flutter_typeahead.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/core/configuration.dart';
 import 'package:photos/face_search_manager.dart';
 import 'package:photos/face_search_manager.dart';
 import 'package:photos/models/face.dart';
 import 'package:photos/models/face.dart';
@@ -6,22 +8,58 @@ import 'package:photos/ui/circular_network_image_widget.dart';
 import 'package:photos/ui/face_search_results_page.dart';
 import 'package:photos/ui/face_search_results_page.dart';
 import 'package:photos/ui/loading_widget.dart';
 import 'package:photos/ui/loading_widget.dart';
 
 
-class SearchPage extends StatelessWidget {
+class SearchPage extends StatefulWidget {
+  @override
+  _SearchPageState createState() => _SearchPageState();
+}
+
+class _SearchPageState extends State<SearchPage> {
   final FaceSearchManager _faceSearchManager = FaceSearchManager.instance;
   final FaceSearchManager _faceSearchManager = FaceSearchManager.instance;
+  String _searchString = "";
+
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
     return Scaffold(
     return Scaffold(
       appBar: AppBar(
       appBar: AppBar(
-        title: TextField(
-          autofocus: true,
-          decoration: InputDecoration(
-            border: InputBorder.none,
-            hintText: 'Search your photos',
-            contentPadding: const EdgeInsets.all(0.0),
+        title: TypeAheadField(
+          textFieldConfiguration: TextFieldConfiguration(
+            autofocus: true,
+            decoration: InputDecoration(
+              border: InputBorder.none,
+              hintText: 'Search your photos',
+              contentPadding: const EdgeInsets.all(0.0),
+            ),
           ),
           ),
+          hideOnEmpty: true,
+          hideOnLoading: true,
+          loadingBuilder: (context) {
+            return loadWidget;
+          },
+          debounceDuration: Duration(milliseconds: 100),
+          suggestionsCallback: (pattern) async {
+            if (pattern.isEmpty) {
+              return null;
+            }
+            return (await Dio().get(
+                    "https://maps.googleapis.com/maps/api/place/textsearch/json",
+                    queryParameters: {
+                  "query": pattern,
+                  "key": "AIzaSyC9lAYIERrNFsCkdLxX6DmZfPhybTKod8U",
+                }))
+                .data["results"];
+          },
+          itemBuilder: (context, suggestion) {
+            if (suggestion == null) {
+              return null;
+            }
+            return LocationSearchResultWidget(suggestion['name']);
+          },
+          onSuggestionSelected: (suggestion) {
+            // Navigator.of(context).push(MaterialPageRoute(
+            //     builder: (context) => ProductPage(product: suggestion)));
+          },
         ),
         ),
         actions: <Widget>[
         actions: <Widget>[
-          // action button
           IconButton(
           IconButton(
             icon: Icon(Icons.search),
             icon: Icon(Icons.search),
             onPressed: () {},
             onPressed: () {},
@@ -29,7 +67,7 @@ class SearchPage extends StatelessWidget {
         ],
         ],
       ),
       ),
       body: Container(
       body: Container(
-        child: _getSearchSuggestions(),
+        child: _searchString.isEmpty ? _getSearchSuggestions() : Container(),
       ),
       ),
     );
     );
   }
   }
@@ -82,3 +120,38 @@ class SearchPage extends StatelessWidget {
     );
     );
   }
   }
 }
 }
+
+class LocationSearchResultWidget extends StatelessWidget {
+  final String name;
+  const LocationSearchResultWidget(
+    this.name, {
+    Key key,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      padding: new EdgeInsets.symmetric(vertical: 6.0, horizontal: 6.0),
+      margin: EdgeInsets.symmetric(vertical: 6.0),
+      child: Column(children: <Widget>[
+        Row(
+          mainAxisAlignment: MainAxisAlignment.start,
+          children: <Widget>[
+            Icon(
+              Icons.location_on,
+            ),
+            Padding(padding: EdgeInsets.only(left: 20.0)),
+            Flexible(
+              child: Container(
+                child: Text(
+                  name,
+                  overflow: TextOverflow.clip,
+                ),
+              ),
+            ),
+          ],
+        ),
+      ]),
+    );
+  }
+}

+ 14 - 0
pubspec.lock

@@ -139,6 +139,13 @@ packages:
       url: "https://pub.dartlang.org"
       url: "https://pub.dartlang.org"
     source: hosted
     source: hosted
     version: "0.6.8"
     version: "0.6.8"
+  flutter_keyboard_visibility:
+    dependency: transitive
+    description:
+      name: flutter_keyboard_visibility
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.7.0"
   flutter_launcher_icons:
   flutter_launcher_icons:
     dependency: "direct dev"
     dependency: "direct dev"
     description:
     description:
@@ -151,6 +158,13 @@ packages:
     description: flutter
     description: flutter
     source: sdk
     source: sdk
     version: "0.0.0"
     version: "0.0.0"
+  flutter_typeahead:
+    dependency: "direct main"
+    description:
+      name: flutter_typeahead
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.8.1"
   flutter_web_plugins:
   flutter_web_plugins:
     dependency: transitive
     dependency: transitive
     description: flutter
     description: flutter

+ 2 - 1
pubspec.yaml

@@ -46,7 +46,8 @@ dependencies:
   flutter_email_sender: ^3.0.1
   flutter_email_sender: ^3.0.1
   like_button: ^0.2.0
   like_button: ^0.2.0
   logging: ^0.11.4
   logging: ^0.11.4
-  flutter_image_compress: ^0.6.5+1 
+  flutter_image_compress: ^0.6.5+1
+  flutter_typeahead: ^1.8.1
 
 
 dev_dependencies:
 dev_dependencies:
   flutter_test:
   flutter_test: