Skip to content

Commit

Permalink
Merge pull request #214 from HaroonAwan/fix_b190
Browse files Browse the repository at this point in the history
Added functionality to change style of Text of result.
  • Loading branch information
juliansteenbakker authored Nov 22, 2022
2 parents 85798e8 + 306b245 commit 363b0a8
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions lib/src/flutter_google_places.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class PlacesAutocompleteWidget extends StatefulWidget {
/// or custom configuration
final BaseClient? httpClient;


/// optional - set 'resultTextStyle' value in google_maps_webservice
///
/// In case of changing the default text style of result's text
final TextStyle? resultTextStyle;

const PlacesAutocompleteWidget({
required this.apiKey,
this.mode = Mode.fullscreen,
Expand All @@ -67,6 +73,7 @@ class PlacesAutocompleteWidget extends StatefulWidget {
this.decoration,
this.textStyle,
this.themeData,
this.resultTextStyle,
}) : super(key: key);

@override
Expand Down Expand Up @@ -94,6 +101,7 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
body: PlacesAutocompleteResult(
onTap: Navigator.of(context).pop,
logo: widget.logo,
resultTextStyle: widget.resultTextStyle,
)),
);
} else {
Expand Down Expand Up @@ -173,6 +181,7 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
(p) => PredictionTile(
prediction: p,
onTap: Navigator.of(context).pop,
resultTextStyle: widget.resultTextStyle,
),
)
.toList(),
Expand Down Expand Up @@ -234,9 +243,14 @@ class _Loader extends StatelessWidget {
class PlacesAutocompleteResult extends StatefulWidget {
final ValueChanged<Prediction>? onTap;
final Widget? logo;
final TextStyle? resultTextStyle;

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

@override
_PlacesAutocompleteResult createState() => _PlacesAutocompleteResult();
Expand All @@ -260,6 +274,7 @@ class _PlacesAutocompleteResult extends State<PlacesAutocompleteResult> {
return PredictionsListView(
predictions: state._response!.predictions,
onTap: widget.onTap,
resultTextStyle: widget.resultTextStyle,
);
}
}
Expand Down Expand Up @@ -348,15 +363,24 @@ class PoweredByGoogleImage extends StatelessWidget {
class PredictionsListView extends StatelessWidget {
final List<Prediction> predictions;
final ValueChanged<Prediction>? onTap;
final TextStyle? resultTextStyle;

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

@override
Widget build(BuildContext context) {
return ListView(
children: predictions
.map((Prediction p) => PredictionTile(prediction: p, onTap: onTap))
.map((Prediction p) => PredictionTile(
prediction: p,
onTap: onTap,
resultTextStyle: resultTextStyle,
))
.toList(),
);
}
Expand All @@ -365,17 +389,22 @@ class PredictionsListView extends StatelessWidget {
class PredictionTile extends StatelessWidget {
final Prediction prediction;
final ValueChanged<Prediction>? onTap;
final TextStyle? resultTextStyle;

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

@override
Widget build(BuildContext context) {
return ListTile(
leading: const Icon(Icons.location_on),
title: Text(
prediction.description!,
style: Theme.of(context).textTheme.bodyText2,
style: resultTextStyle ?? Theme.of(context).textTheme.bodyMedium,
),
onTap: () {
if (onTap != null) {
Expand Down Expand Up @@ -522,6 +551,7 @@ class PlacesAutocomplete {
Duration transitionDuration = const Duration(seconds: 300),
TextStyle? textStyle,
ThemeData? themeData,
TextStyle? resultTextStyle,
}) {
final autoCompleteWidget = PlacesAutocompleteWidget(
apiKey: apiKey,
Expand All @@ -545,6 +575,7 @@ class PlacesAutocomplete {
decoration: decoration,
textStyle: textStyle,
themeData: themeData,
resultTextStyle: resultTextStyle,
);

if (mode == Mode.overlay) {
Expand Down

0 comments on commit 363b0a8

Please sign in to comment.