flutter Error: Couldn't find constructor 'HomePage'.

dart

1import 'dart:async';2import 'package:flutter/material.dart';3import 'package:geolocator/geolocator.dart';4import 'package:google_maps_flutter/google_maps_flutter.dart';5 6class HomePage extends StatefulWidget {7const HomePage({Key? key}) : super(key: key);8 910_HomePageState createState() => _HomePageState();11}12 13class _HomePageState extends State<HomePage> {14Completer<GoogleMapController> _controller = Completer();15// on below line we have specified camera position16static final CameraPosition _kGoogle = const CameraPosition(17 target: LatLng(20.42796133580664, 80.885749655962),18 zoom: 14.4746,19);20 21// on below line we have created the list of markers22final List<Marker> _markers = <Marker>[23 Marker(24 markerId: MarkerId('1'),25 position: LatLng(20.42796133580664, 75.885749655962),26 infoWindow: InfoWindow(27 title: 'My Position',28 )29),30];31 32// created method for getting user current location33Future<Position> getUserCurrentLocation() async {34 await Geolocator.requestPermission().then((value){35 }).onError((error, stackTrace) async {36 await Geolocator.requestPermission();37 print("ERROR"+error.toString());38 });39 return await Geolocator.getCurrentPosition();40}41 4243Widget build(BuildContext context) {44 return Scaffold(45 appBar: AppBar(46 backgroundColor: Color(0xFF0F9D58),47 // on below line we have given title of app48 title: Text("GFG"),49 ),50 body: Container(51 child: SafeArea(52 // on below line creating google maps53 child: GoogleMap(54 // on below line setting camera position55 initialCameraPosition: _kGoogle,56 // on below line we are setting markers on the map57 markers: Set<Marker>.of(_marker),58 // on below line specifying map type.59 mapType: MapType.normal,60 // on below line setting user location enabled.61 myLocationEnabled: true,62 // on below line setting compass enabled.63 compassEnabled: true,64 // on below line specifying controller on map complete.65 onMapCreated: (GoogleMapController controller){66 _controller.complete(controller);67 },68 ),69 ),70 ),71 // on pressing floating action button the camera will take to user current location72 floatingActionButton: FloatingActionButton(73 onPressed: () async{74 getUserCurrentLocation().then((value) async {75 print(value.latitude.toString() +" "+value.longitude.toString());76 77 // marker added for current users location78 _markers.add(79 Marker(80 markerId: MarkerId("2"),81 position: LatLng(value.latitude, value.longitude),82 infoWindow: InfoWindow(83 title: 'My Current Location',84 ),85 )86 );87 88 // specified current users location89 CameraPosition cameraPosition = new CameraPosition(90 target: LatLng(value.latitude, value.longitude),91 zoom: 14,92 );93 94 final GoogleMapController controller = await _controller.future;95 controller.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));96 setState(() {97 });98 });99 },100 child: Icon(Icons.local_activity),101 ),102 );103}104}105 106

コメントを投稿

0 コメント