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

style: apply new lint #216

Merged
merged 3 commits into from
Nov 23, 2022
Merged
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: 5 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:flutter_lints/flutter.yaml
include: package:lint/analysis_options_package.yaml

linter:
rules:
avoid_classes_with_only_static_members: false
2 changes: 1 addition & 1 deletion lib/flutter_google_places.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
library flutter_google_places;

export 'src/flutter_google_places.dart';
export 'src/places_autocomplete_field.dart';
export 'src/places_autocomplete_form_field.dart';
export 'src/flutter_google_places.dart';
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
Loading