Skip to content

Commit

Permalink
style: apply new lint
Browse files Browse the repository at this point in the history
  • Loading branch information
juliansteenbakker committed Nov 23, 2022
1 parent 4fa25bc commit 41feecd
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 95 deletions.
154 changes: 86 additions & 68 deletions lib/src/flutter_google_places.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ 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
Expand Down Expand Up @@ -92,17 +91,18 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
return Theme(
data: theme,
child: Scaffold(
appBar: AppBar(
title: AppBarPlacesAutoCompleteTextField(
textDecoration: widget.decoration,
textStyle: widget.textStyle,
),
appBar: AppBar(
title: AppBarPlacesAutoCompleteTextField(
textDecoration: widget.decoration,
textStyle: widget.textStyle,
),
body: PlacesAutocompleteResult(
onTap: Navigator.of(context).pop,
logo: widget.logo,
resultTextStyle: widget.resultTextStyle,
)),
),
body: PlacesAutocompleteResult(
onTap: Navigator.of(context).pop,
logo: widget.logo,
resultTextStyle: widget.resultTextStyle,
),
),
);
} else {
final headerTopLeftBorderRadius = widget.overlayBorderRadius != null
Expand All @@ -113,12 +113,14 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
? widget.overlayBorderRadius!.topRight
: const Radius.circular(2);

final header = Column(children: <Widget>[
Material(
final header = Column(
children: <Widget>[
Material(
color: theme.dialogBackgroundColor,
borderRadius: BorderRadius.only(
topLeft: headerTopLeftBorderRadius,
topRight: headerTopRightBorderRadius),
topLeft: headerTopLeftBorderRadius,
topRight: headerTopRightBorderRadius,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expand All @@ -132,14 +134,17 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
},
),
Expanded(
child: Padding(
child: _textField(context),
padding: const EdgeInsets.only(right: 8.0),
)),
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: _textField(context),
),
),
],
)),
const Divider()
]);
),
),
const Divider()
],
);

Widget body;

Expand All @@ -153,19 +158,19 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {

if (_searching) {
body = Stack(
children: <Widget>[_Loader()],
alignment: FractionalOffset.bottomCenter,
children: <Widget>[_Loader()],
);
} else if (_queryTextController!.text.isEmpty ||
_response == null ||
_response!.predictions.isEmpty) {
body = Material(
color: theme.dialogBackgroundColor,
child: widget.logo ?? const PoweredByGoogleImage(),
borderRadius: BorderRadius.only(
bottomLeft: bodyBottomLeftBorderRadius,
bottomRight: bodyBottomRightBorderRadius,
),
child: widget.logo ?? const PoweredByGoogleImage(),
);
} else {
body = SingleChildScrollView(
Expand All @@ -191,15 +196,20 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
}

final container = Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 30.0),
child: Stack(children: <Widget>[
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),
]));
],
),
);

if (Theme.of(context).platform == TargetPlatform.iOS) {
return Padding(
padding: const EdgeInsets.only(top: 8.0), child: container);
padding: const EdgeInsets.only(top: 8.0),
child: container,
);
}
return container;
}
Expand All @@ -214,10 +224,11 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState {
autofocus: true,
style: widget.textStyle ??
TextStyle(
color: Theme.of(context).brightness == Brightness.light
? Colors.black87
: null,
fontSize: 16.0),
color: Theme.of(context).brightness == Brightness.light
? Colors.black87
: null,
fontSize: 16.0,
),
decoration: widget.decoration ??
InputDecoration(
hintText: widget.hint,
Expand All @@ -236,8 +247,9 @@ class _Loader extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
constraints: const BoxConstraints(maxHeight: 2.0),
child: const LinearProgressIndicator());
constraints: const BoxConstraints(maxHeight: 2.0),
child: const LinearProgressIndicator(),
);
}
}

Expand All @@ -254,10 +266,11 @@ class PlacesAutocompleteResult extends StatefulWidget {
}) : super(key: key);

@override
_PlacesAutocompleteResult createState() => _PlacesAutocompleteResult();
PlacesAutocompleteResultState createState() =>
PlacesAutocompleteResultState();
}

class _PlacesAutocompleteResult extends State<PlacesAutocompleteResult> {
class PlacesAutocompleteResultState extends State<PlacesAutocompleteResult> {
@override
Widget build(BuildContext context) {
final state = PlacesAutocompleteWidget.of(context)!;
Expand All @@ -284,31 +297,34 @@ class AppBarPlacesAutoCompleteTextField extends StatefulWidget {
final InputDecoration? textDecoration;
final TextStyle? textStyle;

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

@override
_AppBarPlacesAutoCompleteTextFieldState createState() =>
_AppBarPlacesAutoCompleteTextFieldState();
AppBarPlacesAutoCompleteTextFieldState createState() =>
AppBarPlacesAutoCompleteTextFieldState();
}

class _AppBarPlacesAutoCompleteTextFieldState
class AppBarPlacesAutoCompleteTextFieldState
extends State<AppBarPlacesAutoCompleteTextField> {
@override
Widget build(BuildContext context) {
final state = PlacesAutocompleteWidget.of(context)!;

return Container(
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(top: 4.0),
child: TextField(
controller: state._queryTextController,
autofocus: true,
style: widget.textStyle ?? _defaultStyle(),
decoration:
widget.textDecoration ?? _defaultDecoration(state.widget.hint),
));
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(top: 4.0),
child: TextField(
controller: state._queryTextController,
autofocus: true,
style: widget.textStyle ?? _defaultStyle(),
decoration:
widget.textDecoration ?? _defaultDecoration(state.widget.hint),
),
);
}

InputDecoration _defaultDecoration(String hint) {
Expand Down Expand Up @@ -339,25 +355,29 @@ class _AppBarPlacesAutoCompleteTextFieldState
}

class PoweredByGoogleImage extends StatelessWidget {
final _poweredByGoogleWhite =
static const _poweredByGoogleWhite =
"packages/flutter_google_places/assets/google_white.png";
final _poweredByGoogleBlack =
static const _poweredByGoogleBlack =
"packages/flutter_google_places/assets/google_black.png";

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

@override
Widget build(BuildContext context) {
return Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
Padding(
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Image.asset(
Theme.of(context).brightness == Brightness.light
? _poweredByGoogleWhite
: _poweredByGoogleBlack,
scale: 2.5,
))
]);
),
)
],
);
}
}

Expand All @@ -377,11 +397,13 @@ class PredictionsListView extends StatelessWidget {
Widget build(BuildContext context) {
return ListView(
children: predictions
.map((Prediction p) => PredictionTile(
prediction: p,
onTap: onTap,
resultTextStyle: resultTextStyle,
))
.map(
(Prediction p) => PredictionTile(
prediction: p,
onTap: onTap,
resultTextStyle: resultTextStyle,
),
)
.toList(),
);
}
Expand All @@ -408,9 +430,7 @@ class PredictionTile extends StatelessWidget {
style: resultTextStyle ?? Theme.of(context).textTheme.bodyMedium,
),
onTap: () {
if (onTap != null) {
onTap!(prediction);
}
onTap?.call(prediction);
},
);
}
Expand Down Expand Up @@ -507,9 +527,7 @@ abstract class PlacesAutocompleteState extends State<PlacesAutocompleteWidget> {
void onResponseError(PlacesAutocompleteResponse res) {
if (!mounted) return;

if (widget.onError != null) {
widget.onError!(res);
}
widget.onError?.call(res);
setState(() {
_response = null;
_searching = false;
Expand Down
52 changes: 25 additions & 27 deletions lib/src/places_autocomplete_field.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:async';

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

import 'flutter_google_places.dart';

/// A text field like widget to input places with autocomplete.
///
/// The autocomplete field calls [onChanged] with the new address line
Expand Down Expand Up @@ -144,11 +143,11 @@ class PlacesAutocompleteField extends StatefulWidget {
final TextStyle? textStyleFormField;

@override
_LocationAutocompleteFieldState createState() =>
_LocationAutocompleteFieldState();
LocationAutocompleteFieldState createState() =>
LocationAutocompleteFieldState();
}

class _LocationAutocompleteFieldState extends State<PlacesAutocompleteField> {
class LocationAutocompleteFieldState extends State<PlacesAutocompleteField> {
TextEditingController? _controller;
TextEditingController? get _effectiveController =>
widget.controller ?? _controller;
Expand Down Expand Up @@ -191,31 +190,29 @@ class _LocationAutocompleteFieldState extends State<PlacesAutocompleteField> {
textStyle: widget.textStyle,
);

void _handleTap() async {
Prediction? p = await _showAutocomplete();
Future<void> _handleTap() async {
final Prediction? p = await _showAutocomplete();

if (p == null) return;

setState(() {
_effectiveController!.text = p.description!;
if (widget.onChanged != null) {
widget.onChanged!(p.description);
}
if (widget.onSelected != null) {
widget.onSelected!(p);
}
widget.onChanged?.call(p.description);
widget.onSelected?.call(p);
});
}

@override
Widget build(BuildContext context) {
final TextEditingController controller = _effectiveController!;

var text = controller.text.isNotEmpty
? Text(controller.text,
final text = controller.text.isNotEmpty
? Text(
controller.text,
softWrap: true,
style: widget.textStyleFormField ??
const TextStyle(color: Colors.black38))
const TextStyle(color: Colors.black38),
)
: Text(
widget.hint,
style: widget.textStyleFormField ??
Expand All @@ -231,17 +228,18 @@ class _LocationAutocompleteFieldState extends State<PlacesAutocompleteField> {
Expanded(
child: text,
),
widget.trailing != null
? GestureDetector(
onTap: widget.trailingOnTap,
child: widget.trailingOnTap != null
? widget.trailing
: Icon(
widget.trailing!.icon,
color: Colors.grey,
),
)
: const SizedBox()
if (widget.trailing != null)
GestureDetector(
onTap: widget.trailingOnTap,
child: widget.trailingOnTap != null
? widget.trailing
: Icon(
widget.trailing!.icon,
color: Colors.grey,
),
)
else
const SizedBox()
],
);

Expand Down

0 comments on commit 41feecd

Please sign in to comment.