From 41feecdfa453e085c3f7103f8e79e946adc48445 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Wed, 23 Nov 2022 14:45:26 +0100 Subject: [PATCH] style: apply new lint --- lib/src/flutter_google_places.dart | 154 ++++++++++++++----------- lib/src/places_autocomplete_field.dart | 52 ++++----- 2 files changed, 111 insertions(+), 95 deletions(-) diff --git a/lib/src/flutter_google_places.dart b/lib/src/flutter_google_places.dart index 38184a1..a451c36 100644 --- a/lib/src/flutter_google_places.dart +++ b/lib/src/flutter_google_places.dart @@ -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 @@ -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 @@ -113,12 +113,14 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState { ? widget.overlayBorderRadius!.topRight : const Radius.circular(2); - final header = Column(children: [ - Material( + final header = Column( + children: [ + Material( color: theme.dialogBackgroundColor, borderRadius: BorderRadius.only( - topLeft: headerTopLeftBorderRadius, - topRight: headerTopRightBorderRadius), + topLeft: headerTopLeftBorderRadius, + topRight: headerTopRightBorderRadius, + ), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -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; @@ -153,19 +158,19 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState { if (_searching) { body = Stack( - children: [_Loader()], alignment: FractionalOffset.bottomCenter, + children: [_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( @@ -191,15 +196,20 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState { } final container = Container( - margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 30.0), - child: Stack(children: [ + margin: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 30.0), + child: Stack( + children: [ 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; } @@ -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, @@ -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(), + ); } } @@ -254,10 +266,11 @@ class PlacesAutocompleteResult extends StatefulWidget { }) : super(key: key); @override - _PlacesAutocompleteResult createState() => _PlacesAutocompleteResult(); + PlacesAutocompleteResultState createState() => + PlacesAutocompleteResultState(); } -class _PlacesAutocompleteResult extends State { +class PlacesAutocompleteResultState extends State { @override Widget build(BuildContext context) { final state = PlacesAutocompleteWidget.of(context)!; @@ -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 { @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) { @@ -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: [ - Padding( + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Padding( padding: const EdgeInsets.all(16.0), child: Image.asset( Theme.of(context).brightness == Brightness.light ? _poweredByGoogleWhite : _poweredByGoogleBlack, scale: 2.5, - )) - ]); + ), + ) + ], + ); } } @@ -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(), ); } @@ -408,9 +430,7 @@ class PredictionTile extends StatelessWidget { style: resultTextStyle ?? Theme.of(context).textTheme.bodyMedium, ), onTap: () { - if (onTap != null) { - onTap!(prediction); - } + onTap?.call(prediction); }, ); } @@ -507,9 +527,7 @@ abstract class PlacesAutocompleteState extends State { void onResponseError(PlacesAutocompleteResponse res) { if (!mounted) return; - if (widget.onError != null) { - widget.onError!(res); - } + widget.onError?.call(res); setState(() { _response = null; _searching = false; diff --git a/lib/src/places_autocomplete_field.dart b/lib/src/places_autocomplete_field.dart index 80c0c5d..cd16a99 100644 --- a/lib/src/places_autocomplete_field.dart +++ b/lib/src/places_autocomplete_field.dart @@ -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 @@ -144,11 +143,11 @@ class PlacesAutocompleteField extends StatefulWidget { final TextStyle? textStyleFormField; @override - _LocationAutocompleteFieldState createState() => - _LocationAutocompleteFieldState(); + LocationAutocompleteFieldState createState() => + LocationAutocompleteFieldState(); } -class _LocationAutocompleteFieldState extends State { +class LocationAutocompleteFieldState extends State { TextEditingController? _controller; TextEditingController? get _effectiveController => widget.controller ?? _controller; @@ -191,19 +190,15 @@ class _LocationAutocompleteFieldState extends State { textStyle: widget.textStyle, ); - void _handleTap() async { - Prediction? p = await _showAutocomplete(); + Future _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); }); } @@ -211,11 +206,13 @@ class _LocationAutocompleteFieldState extends State { 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 ?? @@ -231,17 +228,18 @@ class _LocationAutocompleteFieldState extends State { 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() ], );