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

Stricter non-nullable types, renaming and general upkeep #51

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Uint8List result = await googlePlace.details.get("ChIJN1t_tDeuEmsRUsoyG83frY4",

```dart
var googlePlace = GooglePlace("Your-Key");
var result = await googlePlace.search.getNearBySearch(
var result = await googlePlace.search.getNearbySearch(
Location(lat: -33.8670522, lng: 151.1957362), 1500,
type: "restaurant", keyword: "cruise");
```
Expand Down
29 changes: 29 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include: package:flutter_lints/flutter.yaml

analyzer:
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
- "**/*.gr.dart"
- "lib/generated/**"
- "lib/firebase_options.dart"
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
invalid_annotation_target: ignore

linter:
rules:
- avoid_shadowing_type_parameters
- parameter_assignments
- require_trailing_commas
- only_throw_errors
- always_use_package_imports
- avoid_dynamic_calls
- prefer_void_to_null
- always_declare_return_types
- avoid_classes_with_only_static_members
- unnecessary_lambdas
- unnecessary_const
- avoid_void_async
20 changes: 20 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
targets:
$default:
builders:
json_serializable:
options:
# Options configure how source code is generated for every
# `@JsonSerializable`-annotated class in the package.
#
# The default value for each is listed.
any_map: false
checked: false
constructor: ""
create_factory: true
create_to_json: true
disallow_unrecognized_keys: false
explicit_to_json: false
field_rename: snake
generic_argument_factories: false
ignore_unannotated: false
include_if_null: true
110 changes: 53 additions & 57 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:google_place/google_place.dart';

void main() async {
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await DotEnv().load('.env');
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
theme: ThemeData(primarySwatch: Colors.blue),
home: const HomePage(),
);
}
}

class HomePage extends StatefulWidget {
const HomePage({Key key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}
Expand All @@ -44,12 +46,12 @@ class _HomePageState extends State<HomePage> {
return Scaffold(
body: SafeArea(
child: Container(
margin: EdgeInsets.only(right: 20, left: 20, top: 20),
margin: const EdgeInsets.only(right: 20, left: 20, top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: "Search",
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
Expand All @@ -68,23 +70,21 @@ class _HomePageState extends State<HomePage> {
if (value.isNotEmpty) {
autoCompleteSearch(value);
} else {
if (predictions.length > 0 && mounted) {
if (predictions.isNotEmpty && mounted) {
setState(() {
predictions = [];
});
}
}
},
),
SizedBox(
height: 10,
),
const SizedBox(height: 10),
Expanded(
child: ListView.builder(
itemCount: predictions.length,
itemBuilder: (context, index) {
return ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(
Icons.pin_drop,
color: Colors.white,
Expand All @@ -93,7 +93,7 @@ class _HomePageState extends State<HomePage> {
title: Text(predictions[index].description),
onTap: () {
debugPrint(predictions[index].placeId);
Navigator.push(
Navigator.push<void>(
context,
MaterialPageRoute(
builder: (context) => DetailsPage(
Expand All @@ -108,7 +108,7 @@ class _HomePageState extends State<HomePage> {
),
),
Container(
margin: EdgeInsets.only(top: 10, bottom: 10),
margin: const EdgeInsets.only(top: 10, bottom: 10),
child: Image.asset("assets/powered_by_google.png"),
),
],
Expand All @@ -118,7 +118,7 @@ class _HomePageState extends State<HomePage> {
);
}

void autoCompleteSearch(String value) async {
Future<void> autoCompleteSearch(String value) async {
var result = await googlePlace.autocomplete.get(value);
if (result != null && result.predictions != null && mounted) {
setState(() {
Expand All @@ -129,58 +129,55 @@ class _HomePageState extends State<HomePage> {
}

class DetailsPage extends StatefulWidget {
const DetailsPage({Key key, this.placeId, this.googlePlace})
: super(key: key);

final String placeId;
final GooglePlace googlePlace;

DetailsPage({Key key, this.placeId, this.googlePlace}) : super(key: key);
final GooglePlace googlePlace;

@override
_DetailsPageState createState() =>
_DetailsPageState(this.placeId, this.googlePlace);
State<DetailsPage> createState() => _DetailsPageState();
}

class _DetailsPageState extends State<DetailsPage> {
final String placeId;
final GooglePlace googlePlace;
Place detailsResult;

_DetailsPageState(this.placeId, this.googlePlace);

DetailsResult detailsResult;
List<Uint8List> images = [];

@override
void initState() {
getDetils(this.placeId);
getDetails(widget.placeId);
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Details"),
title: const Text("Details"),
backgroundColor: Colors.blueAccent,
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.blueAccent,
onPressed: () {
getDetils(this.placeId);
getDetails(widget.placeId);
},
child: Icon(Icons.refresh),
child: const Icon(Icons.refresh),
),
body: SafeArea(
child: Container(
margin: EdgeInsets.only(right: 20, left: 20, top: 20),
margin: const EdgeInsets.only(right: 20, left: 20, top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
SizedBox(
height: 200,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: images.length,
itemBuilder: (context, index) {
return Container(
return SizedBox(
width: 250,
child: Card(
elevation: 4,
Expand All @@ -199,9 +196,7 @@ class _DetailsPageState extends State<DetailsPage> {
},
),
),
SizedBox(
height: 10,
),
const SizedBox(height: 10),
Expanded(
child: Card(
elevation: 4,
Expand All @@ -211,8 +206,8 @@ class _DetailsPageState extends State<DetailsPage> {
child: ListView(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 15, top: 10),
child: Text(
margin: const EdgeInsets.only(left: 15, top: 10),
child: const Text(
"Details",
style: TextStyle(
fontSize: 20,
Expand All @@ -222,18 +217,18 @@ class _DetailsPageState extends State<DetailsPage> {
),
detailsResult != null && detailsResult.types != null
? Container(
margin: EdgeInsets.only(left: 15, top: 10),
margin: const EdgeInsets.only(left: 15, top: 10),
height: 50,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: detailsResult.types.length,
itemBuilder: (context, index) {
return Container(
margin: EdgeInsets.only(right: 10),
margin: const EdgeInsets.only(right: 10),
child: Chip(
label: Text(
detailsResult.types[index],
style: TextStyle(
style: const TextStyle(
color: Colors.white,
),
),
Expand All @@ -245,9 +240,9 @@ class _DetailsPageState extends State<DetailsPage> {
)
: Container(),
Container(
margin: EdgeInsets.only(left: 15, top: 10),
margin: const EdgeInsets.only(left: 15, top: 10),
child: ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(Icons.location_on),
),
title: Text(
Expand All @@ -259,9 +254,9 @@ class _DetailsPageState extends State<DetailsPage> {
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10),
margin: const EdgeInsets.only(left: 15, top: 10),
child: ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(Icons.location_searching),
),
title: Text(
Expand All @@ -274,9 +269,9 @@ class _DetailsPageState extends State<DetailsPage> {
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10),
margin: const EdgeInsets.only(left: 15, top: 10),
child: ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(Icons.timelapse),
),
title: Text(
Expand All @@ -288,9 +283,9 @@ class _DetailsPageState extends State<DetailsPage> {
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10),
margin: const EdgeInsets.only(left: 15, top: 10),
child: ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(Icons.rate_review),
),
title: Text(
Expand All @@ -302,9 +297,9 @@ class _DetailsPageState extends State<DetailsPage> {
),
),
Container(
margin: EdgeInsets.only(left: 15, top: 10),
margin: const EdgeInsets.only(left: 15, top: 10),
child: ListTile(
leading: CircleAvatar(
leading: const CircleAvatar(
child: Icon(Icons.attach_money),
),
title: Text(
Expand All @@ -320,7 +315,7 @@ class _DetailsPageState extends State<DetailsPage> {
),
),
Container(
margin: EdgeInsets.only(top: 20, bottom: 10),
margin: const EdgeInsets.only(top: 20, bottom: 10),
child: Image.asset("assets/powered_by_google.png"),
),
],
Expand All @@ -330,8 +325,8 @@ class _DetailsPageState extends State<DetailsPage> {
);
}

void getDetils(String placeId) async {
var result = await this.googlePlace.details.get(placeId);
Future<void> getDetails(String placeId) async {
final result = await widget.googlePlace.details.get(widget.placeId);
if (result != null && result.result != null && mounted) {
setState(() {
detailsResult = result.result;
Expand All @@ -346,11 +341,12 @@ class _DetailsPageState extends State<DetailsPage> {
}
}

void getPhoto(String photoReference) async {
var result = await this.googlePlace.photos.get(photoReference, null, 400);
if (result != null && mounted) {
Future<void> getPhoto(String photoReference) async {
final response =
await widget.googlePlace.photos.get(photoReference, null, 400);
if (response != null && mounted) {
setState(() {
images.add(result);
images.add(Uint8List.fromList(response.body.codeUnits));
});
}
}
Expand Down
Loading