-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.0.1 Set up plugin and fvm iOS and Android implementations Update README.md Set min iOS Header file Correct out of scope error Correct registrar Restore MockSearchCompletion Remove header Revert "Remove header" This reverts commit a39bf1c. Update SwiftSearchCompletionPlugin.m Update search_completion.podspec Amend headers Update SwiftSearchCompletionPlugin.m Update SearchCompletionPlugin.swift Revert "Update SearchCompletionPlugin.swift" This reverts commit 4a8b705. Change to event channel Update SearchCompletionPlugin.swift Update README.md Update typing Update iOS version Natural language query Update build.gradle Update build.gradle Update build.gradle Update build.gradle Update build.gradle Update build.gradle Update build.gradle
- Loading branch information
0 parents
commit 5b5d472
Showing
98 changed files
with
2,883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/davidsmailes/fvm/versions/3.24.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"flutterSdkVersion": "3.24.4" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.24.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.24.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/davidsmailes/fvm/versions/3.24.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"flutter": "3.24.4", | ||
"flavors": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: "603104015dd692ea3403755b55d07813d5cf8965" | ||
channel: "stable" | ||
|
||
project_type: plugin | ||
|
||
# Tracks metadata for the flutter migrate command | ||
migration: | ||
platforms: | ||
- platform: root | ||
create_revision: 603104015dd692ea3403755b55d07813d5cf8965 | ||
base_revision: 603104015dd692ea3403755b55d07813d5cf8965 | ||
- platform: android | ||
create_revision: 603104015dd692ea3403755b55d07813d5cf8965 | ||
base_revision: 603104015dd692ea3403755b55d07813d5cf8965 | ||
- platform: ios | ||
create_revision: 603104015dd692ea3403755b55d07813d5cf8965 | ||
base_revision: 603104015dd692ea3403755b55d07813d5cf8965 | ||
|
||
# User provided section | ||
|
||
# List of Local paths (relative to this file) that should be | ||
# ignored by the migrate tool. | ||
# | ||
# Files that are not part of the templates will be ignored by default. | ||
unmanaged_files: | ||
- 'lib/main.dart' | ||
- 'ios/Runner.xcodeproj/project.pbxproj' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.0.1 | ||
|
||
* TODO: Describe initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO: Add your license here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,227 @@ | ||
# search_completion | ||
|
||
Wraps MapKit's MKLocalSearchCompletion for iOS and Google Places API autocomplete for Android. | ||
|
||
## Getting Started | ||
|
||
Add to your pubspec.yaml: | ||
|
||
``` | ||
search_completion: | ||
git: | ||
url: https://github.com/yourparkingspace/search_completion.git | ||
ref: main | ||
``` | ||
|
||
Required Android dependencies in build files: | ||
|
||
``` | ||
dependencies { | ||
implementation "com.google.android.libraries.places:places:3.1.0" | ||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4" | ||
} | ||
``` | ||
|
||
Required Android permissions in manifest: | ||
|
||
``` | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.search_completion"> | ||
<uses-permission android:name="android.permission.INTERNET"/> | ||
</manifest> | ||
``` | ||
|
||
## Dart implementation | ||
|
||
``` | ||
class DefaultSearchCompletionDataSource { | ||
static const MethodChannel _channel = MethodChannel('search_completion'); | ||
static const EventChannel _eventChannel = | ||
EventChannel('search_completion_events'); | ||
final _searchResultsController = | ||
StreamController<List<AutoCompleteSearchResult>>.broadcast(); | ||
Stream<List<AutoCompleteSearchResult>> get searchResults => | ||
_searchResultsController.stream; | ||
DefaultSearchCompletionDataSource() { | ||
_eventChannel.receiveBroadcastStream().listen((dynamic event) { | ||
final List<AutoCompleteSearchResult> results = (event as List) | ||
.map( | ||
(e) => | ||
AutoCompleteSearchResult.fromMap(Map<String, dynamic>.from(e)), | ||
) | ||
.toList(); | ||
_searchResultsController.add(results); | ||
}); | ||
} | ||
Future<void> initialize({String? androidApiKey}) async { | ||
if (Platform.isAndroid) { | ||
if (androidApiKey == null) { | ||
throw Exception('Android API key is required for Google Places'); | ||
} | ||
await _channel.invokeMethod('initialize', {'apiKey': androidApiKey}); | ||
} else { | ||
await _channel.invokeMethod('initialize'); | ||
} | ||
} | ||
Future<void> updateSearchTerm(String searchTerm) async { | ||
await _channel.invokeMethod('updateSearchTerm', { | ||
'searchTerm': searchTerm, | ||
}); | ||
} | ||
Future<Coordinates?> getCoordinates(AutoCompleteSearchResult result) async { | ||
final response = await _channel.invokeMethod('getCoordinates', { | ||
'title': result.title, | ||
'subtitle': result.subtitle, | ||
}); | ||
if (response == null) return null; | ||
return Coordinates( | ||
latitude: response['latitude'], | ||
longitude: response['longitude'], | ||
); | ||
} | ||
} | ||
``` | ||
|
||
## Example usage | ||
|
||
``` | ||
import 'package:flutter/material.dart'; | ||
import 'package:marketplace_flutter/features/search/domain/entities/auto_complete_search_result.dart'; | ||
import 'package:marketplace_flutter/features/search/data/default_search_completion_data_source.dart'; | ||
void main() { | ||
runApp(MyApp()); | ||
} | ||
class MyApp extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: SearchPage(), | ||
); | ||
} | ||
} | ||
class SearchPage extends StatefulWidget { | ||
@override | ||
_SearchPageState createState() => _SearchPageState(); | ||
} | ||
class _SearchPageState extends State<SearchPage> { | ||
final DefaultSearchCompletionDataSource _searchDataSource = DefaultSearchCompletionDataSource(); | ||
List<AutoCompleteSearchResult> _searchResults = []; | ||
@override | ||
void initState() { | ||
super.initState(); | ||
_initializeSearch(); | ||
_searchDataSource.searchResults.listen((results) { | ||
setState(() { | ||
_searchResults = results; | ||
}); | ||
}); | ||
} | ||
Future<void> _initializeSearch() async { | ||
try { | ||
await _searchDataSource.initialize(androidApiKey: 'YOUR_ANDROID_API_KEY'); | ||
} catch (e) { | ||
print('Error initializing search: $e'); | ||
} | ||
} | ||
Future<void> _updateSearchTerm(String searchTerm) async { | ||
try { | ||
await _searchDataSource.updateSearchTerm(searchTerm); | ||
} catch (e) { | ||
print('Error updating search term: $e'); | ||
} | ||
} | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Search'), | ||
), | ||
body: Column( | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: TextField( | ||
decoration: InputDecoration( | ||
labelText: 'Search', | ||
border: OutlineInputBorder(), | ||
), | ||
onChanged: (value) { | ||
_updateSearchTerm(value); | ||
}, | ||
), | ||
), | ||
Expanded( | ||
child: ListView.builder( | ||
itemCount: _searchResults.length, | ||
itemBuilder: (context, index) { | ||
final result = _searchResults[index]; | ||
return ListTile( | ||
title: Text(result.title), | ||
subtitle: Text(result.subtitle), | ||
onTap: () async { | ||
final coordinates = await _searchDataSource.getCoordinates(result); | ||
if (coordinates != null) { | ||
print('Coordinates: ${coordinates.latitude}, ${coordinates.longitude}'); | ||
} | ||
}, | ||
); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
class AutoCompleteSearchResult { | ||
final String id; | ||
final String title; | ||
final String subtitle; | ||
AutoCompleteSearchResult({ | ||
required this.id, | ||
required this.title, | ||
required this.subtitle, | ||
}); | ||
factory AutoCompleteSearchResult.fromMap(Map<String, dynamic> map) { | ||
return AutoCompleteSearchResult( | ||
id: map['id'], | ||
title: map['title'], | ||
subtitle: map['subtitle'], | ||
); | ||
} | ||
} | ||
class Coordinates { | ||
final double latitude; | ||
final double longitude; | ||
Coordinates({ | ||
required this.latitude, | ||
required this.longitude, | ||
}); | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include: package:flutter_lints/flutter.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.cxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
buildscript { | ||
ext.kotlin_version = "1.8.22" | ||
repositories { | ||
google() | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:8.1.0' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
} | ||
} | ||
|
||
plugins { | ||
id 'com.android.library' | ||
id 'org.jetbrains.kotlin.android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 34 | ||
namespace "com.yourparkingspace.search_completion" | ||
|
||
defaultConfig { | ||
minSdkVersion 21 | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += "src/main/kotlin" | ||
test.java.srcDirs += "src/test/kotlin" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation 'com.google.android.libraries.places:places:3.2.0' | ||
testImplementation "org.jetbrains.kotlin:kotlin-test" | ||
testImplementation "org.mockito:mockito-core:5.0.0" | ||
} | ||
|
||
repositories { | ||
google() | ||
mavenCentral() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'search_completion' |
Oops, something went wrong.