Open unknowndev00 opened 3 years ago
+1
@unknowndev00 I migrated the example code, but had to disable DotEnv. Here you go:
`import 'dart:typed_data';
import 'package:flutter/material.dart'; // import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:google_place/google_place.dart';
void main() async { WidgetsFlutterBinding.ensureInitialized(); // await DotEnv().load('assets/.env'); runApp(MyApp()); }
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: HomePage(), ); } }
class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); }
class _HomePageState extends State
@override void initState() { // String apiKey = DotEnv().env['API_KEY']; String apiKey = "myKey"; googlePlace = GooglePlace(apiKey); super.initState(); }
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
margin: EdgeInsets.only(right: 20, left: 20, top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children:
void autoCompleteSearch(String value) async { var result = await googlePlace!.autocomplete.get(value); if (result != null && result.predictions != null && mounted) { setState(() { predictions = result.predictions; }); } } }
class DetailsPage extends StatefulWidget { final String? placeId; final GooglePlace? googlePlace;
DetailsPage({Key? key, this.placeId, this.googlePlace}) : super(key: key);
@override _DetailsPageState createState() => _DetailsPageState(this.placeId, this.googlePlace); }
class _DetailsPageState extends State
_DetailsPageState(this.placeId, this.googlePlace);
DetailsResult? detailsResult;
List
@override void initState() { getDetils(this.placeId!); super.initState(); }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Details"),
backgroundColor: Colors.blueAccent,
),
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.blueAccent,
onPressed: () {
getDetils(this.placeId!);
},
child: Icon(Icons.refresh),
),
body: SafeArea(
child: Container(
margin: EdgeInsets.only(right: 20, left: 20, top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children:
void getDetils(String placeId) async { var result = await this.googlePlace!.details.get(placeId); if (result != null && result.result != null && mounted) { setState(() { detailsResult = result.result; images = []; });
if (result.result!.photos != null) {
for (var photo in result.result!.photos!) {
getPhoto(photo.photoReference!);
}
}
}
}
void getPhoto(String photoReference) async { var result = await this.googlePlace!.photos.get(photoReference, 0, 400); if (result != null && mounted) { setState(() { images.add(result); }); } } } `
shrinkWrap: true in ListView.builder.
You updated the plugin to null-safety, but didn't update the example.