Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ class _HomePageState extends State<HomePage> {
]
],
),
ElevatedButton(
child: const Text("Load Place Picker"),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return PlacePicker.searchBuilder(
searchBuilder: ((c, d) => Row(
children: [
const SizedBox(
width: 10,
),
const Icon(Icons.pin_drop_outlined),
const SizedBox(width: 10),
SearchbarTextField(
controller: d,
contentPadding:
const EdgeInsets.only(bottom: 0),
focus: FocusNode(),
hintText: "Search here",
),
const Icon(Icons.mic),
const SizedBox(width: 10)
],
)),
apiKey: Platform.isAndroid
? APIKeys.androidApiKey
: APIKeys.iosApiKey,
onPlacePicked: (result) {
print(result.adrAddress);
Navigator.of(context).pop();
},
initialPosition: HomePage.kInitialPosition,
useCurrentLocation: true,
resizeToAvoidBottomInset:
false, // only works in page mode, less flickery, remove if wrong offsets
);
}),
);
}),

!_showPlacePickerInContainer
? ElevatedButton(
child: Text("Load Place Picker"),
Expand Down
26 changes: 13 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -291,10 +291,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
nested:
dependency: transitive
description:
Expand Down Expand Up @@ -376,18 +376,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
stream_transform:
dependency: transitive
description:
Expand Down Expand Up @@ -416,10 +416,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.6.1"
tuple:
dependency: transitive
description:
Expand Down Expand Up @@ -456,10 +456,10 @@ packages:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "0.3.0"
win32:
dependency: transitive
description:
Expand All @@ -469,5 +469,5 @@ packages:
source: hosted
version: "5.0.5"
sdks:
dart: ">=3.1.0 <4.0.0"
dart: ">=3.2.0-194.0.dev <4.0.0"
flutter: ">=3.13.0"
1 change: 1 addition & 0 deletions lib/google_maps_place_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export 'src/components/floating_card.dart';
export 'src/components/rounded_frame.dart';
export 'src/models/circle_area.dart';
export 'src/place_picker.dart';
export 'src/components/searchbar_text_field.dart';
113 changes: 67 additions & 46 deletions lib/src/autocomplete_search.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: must_be_immutable

import 'dart:async';

import 'package:flutter/material.dart';
Expand All @@ -9,31 +11,35 @@ import 'package:google_maps_place_picker_mb/src/controllers/autocomplete_search_
import 'package:flutter_google_maps_webservices/places.dart';
import 'package:provider/provider.dart';

typedef Row AutoCompleteSearchBuilder(
BuildContext context, TextEditingController controller);

class AutoCompleteSearch extends StatefulWidget {
const AutoCompleteSearch(
{Key? key,
required this.sessionToken,
required this.onPicked,
required this.appBarKey,
this.hintText = "Search here",
this.searchingText = "Searching...",
this.hidden = false,
this.height = 40,
this.contentPadding = EdgeInsets.zero,
this.debounceMilliseconds,
this.onSearchFailed,
required this.searchBarController,
this.autocompleteOffset,
this.autocompleteRadius,
this.autocompleteLanguage,
this.autocompleteComponents,
this.autocompleteTypes,
this.strictbounds,
this.region,
this.initialSearchString,
this.searchForInitialValue,
this.autocompleteOnTrailingWhitespace})
: super(key: key);
AutoCompleteSearch({
Key? key,
required this.sessionToken,
required this.onPicked,
required this.appBarKey,
this.hintText = "Search here",
this.searchingText = "Searching...",
this.hidden = false,
this.height = 40,
this.contentPadding = EdgeInsets.zero,
this.debounceMilliseconds,
this.onSearchFailed,
required this.searchBarController,
this.autocompleteOffset,
this.autocompleteRadius,
this.autocompleteLanguage,
this.autocompleteComponents,
this.autocompleteTypes,
this.strictbounds,
this.region,
this.initialSearchString,
this.searchForInitialValue,
this.autocompleteOnTrailingWhitespace,
this.builder,
}) : super(key: key);

final String? sessionToken;
final String? hintText;
Expand All @@ -56,6 +62,7 @@ class AutoCompleteSearch extends StatefulWidget {
final String? initialSearchString;
final bool? searchForInitialValue;
final bool? autocompleteOnTrailingWhitespace;
late AutoCompleteSearchBuilder? builder;

@override
AutoCompleteSearchState createState() => AutoCompleteSearchState();
Expand Down Expand Up @@ -109,35 +116,47 @@ class AutoCompleteSearchState extends State<AutoCompleteSearch> {
: Colors.white,
borderRadius: BorderRadius.circular(20),
elevation: 4.0,
child: Row(
children: <Widget>[
SizedBox(width: 10),
Icon(Icons.search),
SizedBox(width: 10),
Expanded(child: _buildSearchTextField()),
_buildTextClearIcon(),
],
),
child: widget.builder == null
? _buildSearchBoxContent()
: _buildSearchBoxContentWithBuilder(),
),
)
: Container();
}

Widget _buildSearchBoxContentWithBuilder() {
var child = widget.builder!(context, controller);

assert(child.children.any((element) => element is SearchbarTextField));

child.children.forEach((t) {
if (t is SearchbarTextField) {
assert(t.controller != null,
"The controller parameter must be passed if the searchBuilder is being used.");
}
});

return child;
}

Widget _buildSearchBoxContent({Widget? prefix, Widget? suffix}) {
return Row(
children: <Widget>[
SizedBox(width: 10),
prefix != null ? prefix : Icon(Icons.search),
SizedBox(width: 10),
_buildSearchTextField(),
suffix != null ? suffix : _buildTextClearIcon(),
],
);
}

Widget _buildSearchTextField() {
return TextField(
return SearchbarTextField(
controller: controller,
focusNode: focus,
decoration: InputDecoration(
hintText: widget.hintText,
border: InputBorder.none,
errorBorder: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
isDense: true,
contentPadding: widget.contentPadding,
),
contentPadding: widget.contentPadding,
focus: focus,
hintText: widget.hintText,
);
}

Expand All @@ -157,6 +176,8 @@ class AutoCompleteSearchState extends State<AutoCompleteSearch> {
),
onTap: () {
clearText();

//add a callbackaction here after clearing the text
},
),
);
Expand Down
44 changes: 44 additions & 0 deletions lib/src/components/searchbar_text_field.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';

class SearchbarTextField extends StatefulWidget {
final TextEditingController? controller;

final FocusNode focus;

final String? hintText;

final EdgeInsetsGeometry contentPadding;

const SearchbarTextField(
{super.key,
this.controller,
required this.focus,
this.hintText,
required this.contentPadding});

@override
State<SearchbarTextField> createState() => _SearchbarTextFieldState();
}

class _SearchbarTextFieldState extends State<SearchbarTextField> {
@override
Widget build(BuildContext context) {
return Expanded(
child: TextField(
controller: widget.controller,
focusNode: widget.focus,
decoration: InputDecoration(
hintText: widget.hintText,
border: InputBorder.none,
errorBorder: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
disabledBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
isDense: true,
contentPadding: widget.contentPadding,
),
),
);
}
}
Loading