Skip to content

Commit 11980f1

Browse files
authored
Merge pull request #69 from ketanchoyal/feat/v4
Feat/v4
2 parents 1095c63 + 36d6505 commit 11980f1

31 files changed

+1937
-264
lines changed

CHANGELOG.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# [4.0.0-beta.1] - 25 April 2023
2+
## Breaking Changes
3+
- PlaceSearch and ReverseGeoCoding classes are now merged into one class called GeoCoding with two methods `getPlaces` and `getAddress` since both of them are using the same API.
4+
5+
## New Features
6+
- MapBox's new [SearchBox API](https://docs.mapbox.com/api/search/search-box/) is added to the package.
7+
- Overal code refactoring
8+
19
# [3.2.0] - 21 April 2023
210
- Added BBox in Forward Geododing API (As per MapBox API we can use BBox to get the results in a specific area)
311

@@ -17,7 +25,7 @@
1725
- Homepage URL fixed
1826

1927
## [3.0.1] - 14 Sep 2021
20-
- Added [Places type]((https://docs.mapbox.com/api/search/geocoding/#data-types)) to filter Search [PR #48]
28+
- Added [Places type](https://docs.mapbox.com/api/search/geocoding/#data-types) to filter Search [PR #48]
2129

2230
## [3.0.0-nullsafety.0] - 07 Mar 2021
2331
- Migrate to null safety [Pull Request #43]

README.md

+46-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
[![Pub](https://img.shields.io/pub/v/mapbox_search)](https://pub.dev/packages/mapbox_search)
22
# About
33

4+
## Note: Breaking Changes in 4.x.x
5+
6+
- PlaceSearch and ReverseGeoCoding classes are now merged into one class called GeoCoding with two methods `getPlaces` and `getAddress` since both of them are using the same API.
7+
- MapBox's new [SearchBox API](https://docs.mapbox.com/api/search/search-box/) is added to the package.
8+
49
This package provides easy api calls to MapBox Search API.
510

6-
Also, it contains an static map image generator 😆.
11+
Also, it contains an static map image generator.
712

813
[Maki Icons](https://labs.mapbox.com/maki-icons/) can be used now in marker icon
914

@@ -26,9 +31,36 @@ Then, add the following to your `pubspec.yaml` file:
2631

2732
# Examples
2833

34+
### SearchBox API
35+
```dart
36+
SearchBoxAPI search = SearchBoxAPI(
37+
apiKey: MAPBOX_KEY,
38+
limit: 6,
39+
);
40+
```
41+
##### Get Suggestions
42+
```dart
43+
SuggestionResponse searchPlace = await search.getSuggestions(
44+
"central",
45+
);
46+
```
47+
48+
##### Get mapbox_id
49+
- From SuggestionResponse
50+
```dart
51+
String mapboxId = searchPlace.suggestions[0].mapboxId;
52+
```
53+
54+
##### Get Place Details
55+
```dart
56+
RetrieveResonse searchPlace = await search.getPlace(mapboxId);
57+
```
58+
59+
60+
2961
### Reverse GeoCoding
3062
```dart
31-
var reverseGeoCoding = ReverseGeoCoding(
63+
var reverseGeoCoding = GeoCoding(
3264
apiKey: 'API Key',
3365
limit: 5,
3466
);
@@ -38,16 +70,24 @@ Future<List<MapBoxPlace>> geAddress() =>
3870
Location(lat: 72.0, lng: 76.00),
3971
);
4072
```
41-
42-
### Places Seach
73+
74+
### Forward GeoCoding Seach
4375
```dart
44-
var placesSearch = PlacesSearch(
76+
var geocoding = GeoCoding(
4577
apiKey: 'API Key',
78+
country: "BR",
4679
limit: 5,
80+
types: [PlaceType.address, PlaceType.place],
4781
);
4882
4983
Future<List<MapBoxPlace>> getPlaces() =>
50-
placesSearch.getPlaces("New York");
84+
geocoding.getPlaces(
85+
"central park",
86+
proximity: Location(
87+
lat: -19.984634,
88+
lng: -43.9502958,
89+
),
90+
);
5191
```
5292

5393
### Static Image
@@ -108,8 +148,3 @@ String getStaticImageWithoutMarker() => staticImage.getStaticUrlWithoutMarker(
108148

109149
<img src="https://github.com/ketanchoyal/mapbox_search/raw/dev/Screenshots/staticImages.png" alt="Static Map Image"/>
110150

111-
## Search Widget
112-
113-
<img src="https://github.com/ketanchoyal/mapbox_search/raw/dev/Screenshots/search2.png" alt="Demo"/>
114-
115-
<img src="https://github.com/ketanchoyal/mapbox_search/raw/dev/Screenshots/search1.png" alt="Demo"/>

Screenshots/search1.png

-176 KB
Binary file not shown.

Screenshots/search2.png

-53.4 KB
Binary file not shown.

example/main.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
import 'dart:core';
2+
13
import 'package:mapbox_search/mapbox_search.dart';
24

35
// import 'credentials.dart';
46
final MAPBOX_KEY = '';
57

68
Future<void> main() async {
7-
String apiKey = MAPBOX_KEY; //Set up a test api key before running
9+
final apiKey = MAPBOX_KEY; //Set up a test api key before running
810

911
await geoCoding(apiKey).catchError(print);
1012
await placesSearch(apiKey).catchError(print);
1113
}
1214

1315
///Reverse GeoCoding sample call
1416
Future geoCoding(String apiKey) async {
15-
var geoCodingService = ReverseGeoCoding(
17+
var geoCodingService = GeoCoding(
1618
apiKey: apiKey,
1719
country: "BR",
1820
limit: 5,
@@ -28,15 +30,15 @@ Future geoCoding(String apiKey) async {
2830

2931
///Places search sample call
3032
Future placesSearch(String apiKey) async {
31-
var placesService = PlacesSearch(
33+
var placesService = GeoCoding(
3234
apiKey: apiKey,
3335
country: "BR",
3436
limit: 5,
3537
);
3638

3739
var places = await placesService.getPlaces(
3840
"patio",
39-
location: Location(
41+
proximity: Location(
4042
lat: -19.984634,
4143
lng: -43.9502958,
4244
),

example/pubspec.lock

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Generated by pub
2+
# See https://dart.dev/tools/pub/glossary#lockfile
3+
packages:
4+
async:
5+
dependency: transitive
6+
description:
7+
name: async
8+
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
9+
url: "https://pub.dev"
10+
source: hosted
11+
version: "2.11.0"
12+
collection:
13+
dependency: transitive
14+
description:
15+
name: collection
16+
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
17+
url: "https://pub.dev"
18+
source: hosted
19+
version: "1.17.1"
20+
crypto:
21+
dependency: transitive
22+
description:
23+
name: crypto
24+
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
25+
url: "https://pub.dev"
26+
source: hosted
27+
version: "3.0.2"
28+
http:
29+
dependency: transitive
30+
description:
31+
name: http
32+
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
33+
url: "https://pub.dev"
34+
source: hosted
35+
version: "0.13.5"
36+
http_parser:
37+
dependency: transitive
38+
description:
39+
name: http_parser
40+
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
41+
url: "https://pub.dev"
42+
source: hosted
43+
version: "4.0.2"
44+
mapbox_search:
45+
dependency: "direct main"
46+
description:
47+
path: ".."
48+
relative: true
49+
source: path
50+
version: "3.2.0"
51+
meta:
52+
dependency: transitive
53+
description:
54+
name: meta
55+
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
56+
url: "https://pub.dev"
57+
source: hosted
58+
version: "1.9.1"
59+
path:
60+
dependency: transitive
61+
description:
62+
name: path
63+
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
64+
url: "https://pub.dev"
65+
source: hosted
66+
version: "1.8.3"
67+
source_span:
68+
dependency: transitive
69+
description:
70+
name: source_span
71+
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
72+
url: "https://pub.dev"
73+
source: hosted
74+
version: "1.10.0"
75+
string_scanner:
76+
dependency: transitive
77+
description:
78+
name: string_scanner
79+
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
80+
url: "https://pub.dev"
81+
source: hosted
82+
version: "1.2.0"
83+
term_glyph:
84+
dependency: transitive
85+
description:
86+
name: term_glyph
87+
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
88+
url: "https://pub.dev"
89+
source: hosted
90+
version: "1.2.1"
91+
typed_data:
92+
dependency: transitive
93+
description:
94+
name: typed_data
95+
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
96+
url: "https://pub.dev"
97+
source: hosted
98+
version: "1.3.1"
99+
uuid:
100+
dependency: transitive
101+
description:
102+
name: uuid
103+
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
104+
url: "https://pub.dev"
105+
source: hosted
106+
version: "3.0.7"
107+
sdks:
108+
dart: ">=2.18.0 <3.0.0"

example/pubspec.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: example
2+
description: A Flutter package for place search using MapBox Api and for Static map image
3+
version: 1.0.0
4+
publish_to: "none" # Remove this line if you wish to publish to pub.dev
5+
6+
homepage: https://github.com/ketanchoyal/mapbox_search
7+
8+
environment:
9+
sdk: ">=2.17.0 <3.0.0"
10+
11+
dependencies:
12+
mapbox_search:
13+
path: ../

lib/colors/cielab_color.dart

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
part of color;
22

3+
/// A color in the CIELAB color space.
34
class CielabColor extends Color {
45
final num l;
56
final num a;
@@ -12,10 +13,13 @@ class CielabColor extends Color {
1213
return xyz.toRgbColor();
1314
}
1415

16+
/// Converts the color to HSL color space.
1517
HslColor toHslColor() => this.toRgbColor().toHslColor();
1618

19+
/// Converts the color to HSV color space.
1720
HsvColor toHsvColor() => this.toRgbColor().toHsvColor();
1821

22+
/// Converts the color to XYZ color space.
1923
XyzColor toXyzColor() {
2024
Map<String, num> xyz = {
2125
'x': a / 500 + (l + 16) / 116,
@@ -36,6 +40,7 @@ class CielabColor extends Color {
3640
return XyzColor(xyz['x']!, xyz['y']!, xyz['z']!);
3741
}
3842

43+
// Returns a CielabColor with the same color values as this Color.
3944
CielabColor toCielabColor() => this;
4045

4146
String toString() => "l: $l, a: $a, b: $b";

lib/colors/color.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ abstract class Color {
5050
return 256 * 256 * rgb.r.toInt() + 256 * rgb.g.toInt() + rgb.b.toInt();
5151
}
5252

53-
operator ==(Object other) => other is Color && this.hashCode == other.hashCode;
53+
operator ==(Object other) =>
54+
other is Color && this.hashCode == other.hashCode;
5455

5556
operator [](String key) => this.toMap()[key];
5657

lib/colors/color_filter.dart

+13-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ class ColorFilter {
1111
/**
1212
* Makes the color lighter by the percentage specified in the first argument, or by 10% if no percentage is specified. Percentages should be specified as a float, e.g. an argument of 0.25 will result in a color 25% lighter than the original. The lightening conversion is performed by adjusting the y component of the color in XYZ color space.
1313
*/
14-
static ColorFilter lighten = new ColorFilter((Color inputColor, [List? args]) {
14+
static ColorFilter lighten =
15+
new ColorFilter((Color inputColor, [List? args]) {
1516
CielabColor color = inputColor.toCielabColor();
1617
num percent = 0.1;
17-
if (args is List && args.length > 0 && args[0] is num) {
18+
if (args is List && args.isNotEmpty && args[0] is num) {
1819
percent = args[0];
1920
}
2021
return new CielabColor(color.l * (1 + percent), color.a, color.b);
@@ -37,15 +38,21 @@ class ColorFilter {
3738
*/
3839
static ColorFilter sepia = new ColorFilter((Color baseColor, [List? args]) {
3940
RgbColor color = baseColor.toRgbColor();
40-
return new RgbColor(min(RgbColor.rMax, (color.r * 0.393 + color.g * 0.769 + color.b * 0.189)),
41-
min(RgbColor.gMax, (color.r * 0.349 + color.g * 0.686 + color.b * 0.168)),
42-
min(RgbColor.bMax, (color.r * 0.272 + color.g * 0.534 + color.b * 0.131))).toCielabColor();
41+
return new RgbColor(
42+
min(RgbColor.rMax,
43+
(color.r * 0.393 + color.g * 0.769 + color.b * 0.189)),
44+
min(RgbColor.gMax,
45+
(color.r * 0.349 + color.g * 0.686 + color.b * 0.168)),
46+
min(RgbColor.bMax,
47+
(color.r * 0.272 + color.g * 0.534 + color.b * 0.131)))
48+
.toCielabColor();
4349
}, RgbColor);
4450

4551
/**
4652
* Creates a greyscale color with the same perceived luminance as the source color (as given by the L* value of the color in the CieLAB color space).
4753
*/
48-
static ColorFilter greyscale = new ColorFilter((Color inputColor, [List? args]) {
54+
static ColorFilter greyscale =
55+
new ColorFilter((Color inputColor, [List? args]) {
4956
CielabColor color = inputColor.toCielabColor();
5057
num rgbLevel = color.l * 255 / 100;
5158
return new RgbColor(rgbLevel, rgbLevel, rgbLevel).toCielabColor();

0 commit comments

Comments
 (0)