Skip to content

Commit

Permalink
Added functionality to change style of Text of result.
Browse files Browse the repository at this point in the history
  • Loading branch information
HaroonAwan committed Nov 17, 2022
1 parent 7a12343 commit 0041b20
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 @@ -521,6 +550,7 @@ class PlacesAutocomplete {
String startText = "",
TextStyle? textStyle,
ThemeData? themeData,
TextStyle? resultTextStyle,
}) {
builder(BuildContext ctx) => PlacesAutocompleteWidget(
apiKey: apiKey,
Expand All @@ -544,6 +574,7 @@ class PlacesAutocomplete {
decoration: decoration,
textStyle: textStyle,
themeData: themeData,
resultTextStyle: resultTextStyle,
);

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

0 comments on commit 0041b20

Please sign in to comment.