Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extra customizations for overlay mode - Very useful for Web #227

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
6 changes: 3 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:async';
import 'dart:math';

import 'package:google_api_headers/google_api_headers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_api_headers/google_api_headers.dart';
import 'package:google_maps_webservice/places.dart';

const kGoogleApiKey = "API_KEY";
Expand Down Expand Up @@ -173,8 +173,8 @@ class _CustomSearchScaffoldState extends PlacesAutocompleteState {
onTap: (p) {
displayPrediction(p, context);
},
logo: Row(
children: const [FlutterLogo()],
logo: const Row(
children: [FlutterLogo()],
mainAxisAlignment: MainAxisAlignment.center,
),
);
Expand Down
2 changes: 0 additions & 2 deletions lib/flutter_google_places.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library flutter_google_places;

export 'src/flutter_google_places.dart';
export 'src/places_autocomplete_field.dart';
export 'src/places_autocomplete_form_field.dart';
87 changes: 62 additions & 25 deletions lib/src/flutter_google_places.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library flutter_google_places.src;

import 'dart:async';

import 'package:flutter/material.dart';
Expand Down Expand Up @@ -29,6 +27,13 @@ class PlacesAutocompleteWidget extends StatefulWidget {
final InputDecoration? decoration;
final TextStyle? textStyle;
final ThemeData? themeData;
final double? width;
final double? height;
final EdgeInsetsGeometry? padding;
final EdgeInsetsGeometry? margin;
final bool showContainerBackground;
final Color? backgroundColor;
final BorderRadius? borderRadius;

/// optional - sets 'proxy' value in google_maps_webservice
///
Expand Down Expand Up @@ -64,7 +69,7 @@ class PlacesAutocompleteWidget extends StatefulWidget {
this.region,
this.logo,
this.onError,
Key? key,
super.key,
this.proxyBaseUrl,
this.httpClient,
this.startText,
Expand All @@ -73,7 +78,14 @@ class PlacesAutocompleteWidget extends StatefulWidget {
this.textStyle,
this.themeData,
this.resultTextStyle,
}) : super(key: key);
this.height,
this.width,
this.margin = const EdgeInsets.symmetric(horizontal: 16.0, vertical: 30.0),
this.padding,
this.showContainerBackground = false,
this.backgroundColor,
this.borderRadius,
});

@override
State<PlacesAutocompleteWidget> createState() =>
Expand All @@ -87,6 +99,8 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
@override
Widget build(BuildContext context) {
final theme = widget.themeData ?? Theme.of(context);
final Color backgroundColor =
widget.backgroundColor ?? theme.dialogBackgroundColor;
if (widget.mode == Mode.fullscreen) {
return Theme(
data: theme,
Expand Down Expand Up @@ -116,7 +130,7 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
final header = Column(
children: <Widget>[
Material(
color: theme.dialogBackgroundColor,
color: backgroundColor,
borderRadius: BorderRadius.only(
topLeft: headerTopLeftBorderRadius,
topRight: headerTopRightBorderRadius,
Expand All @@ -142,7 +156,7 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
],
),
),
const Divider()
const Divider(),
],
);

Expand All @@ -165,7 +179,7 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
_response == null ||
_response!.predictions.isEmpty) {
body = Material(
color: theme.dialogBackgroundColor,
color: backgroundColor,
borderRadius: BorderRadius.only(
bottomLeft: bodyBottomLeftBorderRadius,
bottomRight: bodyBottomRightBorderRadius,
Expand All @@ -179,7 +193,7 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
bottomLeft: bodyBottomLeftBorderRadius,
bottomRight: bodyBottomRightBorderRadius,
),
color: theme.dialogBackgroundColor,
color: backgroundColor,
child: ListBody(
children: _response!.predictions
.map(
Expand All @@ -195,13 +209,22 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
);
}

final container = Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 30.0),
child: Stack(
children: <Widget>[
header,
Padding(padding: const EdgeInsets.only(top: 48.0), child: body),
],
final container = Center(
child: Container(
width: widget.width,
height: widget.height,
padding: widget.padding,
margin: widget.margin,
decoration: BoxDecoration(
color: widget.showContainerBackground ? backgroundColor : null,
borderRadius: widget.borderRadius,
),
child: Stack(
children: <Widget>[
header,
Padding(padding: const EdgeInsets.only(top: 48.0), child: body),
],
),
),
);

Expand Down Expand Up @@ -259,11 +282,11 @@ class PlacesAutocompleteResult extends StatefulWidget {
final TextStyle? resultTextStyle;

const PlacesAutocompleteResult({
Key? key,
super.key,
this.onTap,
this.logo,
this.resultTextStyle,
}) : super(key: key);
});

@override
PlacesAutocompleteResultState createState() =>
Expand Down Expand Up @@ -298,10 +321,10 @@ class AppBarPlacesAutoCompleteTextField extends StatefulWidget {
final TextStyle? textStyle;

const AppBarPlacesAutoCompleteTextField({
Key? key,
super.key,
this.textDecoration,
this.textStyle,
}) : super(key: key);
});

@override
AppBarPlacesAutoCompleteTextFieldState createState() =>
Expand Down Expand Up @@ -360,7 +383,7 @@ class PoweredByGoogleImage extends StatelessWidget {
static const _poweredByGoogleBlack =
"packages/flutter_google_places/assets/google_black.png";

const PoweredByGoogleImage({Key? key}) : super(key: key);
const PoweredByGoogleImage({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -375,7 +398,7 @@ class PoweredByGoogleImage extends StatelessWidget {
: _poweredByGoogleBlack,
scale: 2.5,
),
)
),
],
);
}
Expand All @@ -387,11 +410,11 @@ class PredictionsListView extends StatelessWidget {
final TextStyle? resultTextStyle;

const PredictionsListView({
Key? key,
super.key,
required this.predictions,
this.onTap,
this.resultTextStyle,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand All @@ -415,11 +438,11 @@ class PredictionTile extends StatelessWidget {
final TextStyle? resultTextStyle;

const PredictionTile({
Key? key,
super.key,
required this.prediction,
this.onTap,
this.resultTextStyle,
}) : super(key: key);
});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -571,6 +594,13 @@ class PlacesAutocomplete {
TextStyle? textStyle,
ThemeData? themeData,
TextStyle? resultTextStyle,
double? width,
double? height,
EdgeInsetsGeometry? padding,
EdgeInsetsGeometry? margin,
bool showContainerBackgrond = false,
Color? backgroundColor,
BorderRadius? borderRadius,
}) {
final autoCompleteWidget = PlacesAutocompleteWidget(
apiKey: apiKey,
Expand All @@ -595,6 +625,13 @@ class PlacesAutocomplete {
textStyle: textStyle,
themeData: themeData,
resultTextStyle: resultTextStyle,
width: width,
height: height,
padding: padding,
margin: margin,
showContainerBackground: showContainerBackgrond,
backgroundColor: backgroundColor,
borderRadius: borderRadius,
);

if (mode == Mode.overlay) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/places_autocomplete_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PlacesAutocompleteField extends StatefulWidget {
/// by the decoration to save space for the labels), set the [decoration] to
/// null.
const PlacesAutocompleteField({
Key? key,
super.key,
required this.apiKey,
this.controller,
this.leading,
Expand All @@ -59,7 +59,7 @@ class PlacesAutocompleteField extends StatefulWidget {
this.overlayBorderRadius,
this.textStyle,
this.textStyleFormField,
}) : super(key: key);
});

/// Controls the text being edited.
///
Expand Down Expand Up @@ -239,7 +239,7 @@ class LocationAutocompleteFieldState extends State<PlacesAutocompleteField> {
),
)
else
const SizedBox()
const SizedBox(),
],
);

Expand Down
14 changes: 5 additions & 9 deletions lib/src/places_autocomplete_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class PlacesAutocompleteFormField extends FormField<String> {
/// to [initalValue] or the empty string.
///
/// For documentation about the various parameters, see the [PlacesAutocompleteField] class
/// and [new PlacesAutocompleteField], the constructor.
/// and [PlacesAutocompleteField.new], the constructor.
PlacesAutocompleteFormField({
Key? key,
super.key,
required String apiKey,
this.controller,
Icon? leading,
Expand All @@ -61,17 +61,13 @@ class PlacesAutocompleteFormField extends FormField<String> {
bool? strictbounds,
ValueChanged<PlacesAutocompleteResponse>? onError,
InputDecoration inputDecoration = const InputDecoration(),
AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
FormFieldSetter<String>? onSaved,
FormFieldValidator<String>? validator,
AutovalidateMode super.autovalidateMode = AutovalidateMode.disabled,
super.onSaved,
super.validator,
}) : assert(initialValue == null || controller == null),
super(
key: key,
initialValue:
controller != null ? controller.text : (initialValue ?? ''),
onSaved: onSaved,
validator: validator,
autovalidateMode: autovalidateMode,
builder: (FormFieldState<String> field) {
final TextFormFieldState state = field as TextFormFieldState;
final InputDecoration effectiveDecoration = inputDecoration
Expand Down
16 changes: 8 additions & 8 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: flutter_google_places
description: Google places autocomplete widgets for flutter. No wrapper, use https://pub.dev/packages/google_maps_webservice
description: Google places autocomplete widgets for flutter. No wrapper, use
https://pub.dev/packages/google_maps_webservice
version: 0.4.0
repository: https://github.com/fluttercommunity/flutter_google_places

environment:
sdk: '>=2.12.0 <3.0.0'
flutter: ">=1.17.0"
sdk: ">=3.2.3 <4.0.0"

dependencies:
flutter:
sdk: flutter
google_api_headers: ^1.3.0
google_maps_webservice: ^0.0.20-nullsafety.5
http: ^0.13.4
rxdart: ^0.27.5
google_api_headers: 4.0.3
google_maps_webservice: ^0.0.19
http: ^0.13.6
rxdart: ^0.28.0

dev_dependencies:
flutter_test:
sdk: flutter
lint: ^1.10.0
lint: ^2.3.0

flutter:
assets:
Expand Down