From 6e0dc53fb55f3e9df62fe6458181a133a53cb63a Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Wed, 23 Nov 2022 14:35:43 +0100 Subject: [PATCH 1/2] style: apply new lint --- analysis_options.yaml | 6 +- lib/flutter_google_places.dart | 2 +- lib/src/flutter_google_places.dart | 142 +++++++++++--------- lib/src/places_autocomplete_field.dart | 46 +++---- lib/src/places_autocomplete_form_field.dart | 15 +-- pubspec.yaml | 2 +- 6 files changed, 115 insertions(+), 98 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index a3be6b8..ec7bcdb 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1 +1,5 @@ -include: package:flutter_lints/flutter.yaml \ No newline at end of file +include: package:lint/analysis_options_package.yaml + +linter: + rules: + avoid_classes_with_only_static_members: false \ No newline at end of file diff --git a/lib/flutter_google_places.dart b/lib/flutter_google_places.dart index 5def371..8872a28 100644 --- a/lib/flutter_google_places.dart +++ b/lib/flutter_google_places.dart @@ -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'; diff --git a/lib/src/flutter_google_places.dart b/lib/src/flutter_google_places.dart index d5ca17e..9f6f325 100644 --- a/lib/src/flutter_google_places.dart +++ b/lib/src/flutter_google_places.dart @@ -85,16 +85,17 @@ 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, - )), + ), + body: PlacesAutocompleteResult( + onTap: Navigator.of(context).pop, + logo: widget.logo, + ), + ), ); } else { final headerTopLeftBorderRadius = widget.overlayBorderRadius != null @@ -105,12 +106,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: [ @@ -124,14 +127,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; @@ -145,19 +151,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( @@ -182,15 +188,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; } @@ -204,10 +215,11 @@ class _PlacesAutocompleteOverlayState extends PlacesAutocompleteState { controller: _queryTextController, autofocus: true, style: 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, @@ -226,8 +238,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(), + ); } } @@ -239,10 +252,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)!; @@ -268,31 +282,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) { @@ -323,25 +340,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, - )) - ]); + ), + ) + ], + ); } } @@ -378,9 +399,7 @@ class PredictionTile extends StatelessWidget { style: Theme.of(context).textTheme.bodyText2, ), onTap: () { - if (onTap != null) { - onTap!(prediction); - } + onTap?.call(prediction); }, ); } @@ -477,9 +496,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; @@ -522,7 +539,8 @@ class PlacesAutocomplete { TextStyle? textStyle, ThemeData? themeData, }) { - builder(BuildContext ctx) => PlacesAutocompleteWidget( + PlacesAutocompleteWidget builder(BuildContext ctx) => + PlacesAutocompleteWidget( apiKey: apiKey, mode: mode, overlayBorderRadius: overlayBorderRadius, diff --git a/lib/src/places_autocomplete_field.dart b/lib/src/places_autocomplete_field.dart index d0e536b..9b3fec4 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 @@ -135,11 +134,11 @@ class PlacesAutocompleteField extends StatefulWidget { final ValueChanged? onError; @override - _LocationAutocompleteFieldState createState() => - _LocationAutocompleteFieldState(); + LocationAutocompleteFieldState createState() => + LocationAutocompleteFieldState(); } -class _LocationAutocompleteFieldState extends State { +class LocationAutocompleteFieldState extends State { TextEditingController? _controller; TextEditingController? get _effectiveController => widget.controller ?? _controller; @@ -180,19 +179,15 @@ class _LocationAutocompleteFieldState extends State { strictbounds: widget.strictbounds, ); - 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); }); } @@ -200,7 +195,7 @@ class _LocationAutocompleteFieldState extends State { Widget build(BuildContext context) { final TextEditingController controller = _effectiveController!; - var text = controller.text.isNotEmpty + final text = controller.text.isNotEmpty ? Text( controller.text, softWrap: true, @@ -219,17 +214,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() ], ); diff --git a/lib/src/places_autocomplete_form_field.dart b/lib/src/places_autocomplete_form_field.dart index 286e4cf..9526ead 100644 --- a/lib/src/places_autocomplete_form_field.dart +++ b/lib/src/places_autocomplete_form_field.dart @@ -1,9 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:flutter_google_places/src/flutter_google_places.dart'; +import 'package:flutter_google_places/src/places_autocomplete_field.dart'; import 'package:google_maps_webservice/places.dart'; -import 'flutter_google_places.dart'; -import 'places_autocomplete_field.dart'; - /// A [FormField] that contains a [PlacesAutocompleteField]. /// /// This is a convenience widget that wraps a [PlacesAutocompleteField] widget in a @@ -74,13 +73,13 @@ class PlacesAutocompleteFormField extends FormField { validator: validator, autovalidateMode: autovalidateMode, builder: (FormFieldState field) { - final _TextFormFieldState state = field as _TextFormFieldState; - final InputDecoration? effectiveDecoration = inputDecoration + final TextFormFieldState state = field as TextFormFieldState; + final InputDecoration effectiveDecoration = inputDecoration .applyDefaults(Theme.of(state.context).inputDecorationTheme); return PlacesAutocompleteField( key: key, inputDecoration: - effectiveDecoration?.copyWith(errorText: state.errorText), + effectiveDecoration.copyWith(errorText: state.errorText), controller: state._effectiveController, apiKey: apiKey, leading: leading, @@ -109,10 +108,10 @@ class PlacesAutocompleteFormField extends FormField { final TextEditingController? controller; @override - _TextFormFieldState createState() => _TextFormFieldState(); + TextFormFieldState createState() => TextFormFieldState(); } -class _TextFormFieldState extends FormFieldState { +class TextFormFieldState extends FormFieldState { TextEditingController? _controller; TextEditingController? get _effectiveController => diff --git a/pubspec.yaml b/pubspec.yaml index 30af245..2a004a3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,9 +16,9 @@ dependencies: rxdart: ^0.27.3 dev_dependencies: - flutter_lints: ^2.0.1 flutter_test: sdk: flutter + lint: ^1.10.0 flutter: assets: From 41feecdfa453e085c3f7103f8e79e946adc48445 Mon Sep 17 00:00:00 2001 From: Julian Steenbakker Date: Wed, 23 Nov 2022 14:45:26 +0100 Subject: [PATCH 2/2] 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() ], );