I am trying to add google maps to my app. but I'm getting method isn't defined error.
ERRORS: The method 'RippleIndicator' isn't defined for the type '_MyCardWidgetState'. Try correcting the name to the name of an existing method, or defining a method named 'RippleIndicator'. The method 'mapWidget' isn't defined for the type '_MyCardWidgetState'. Try correcting the name to the name of an existing method, or defining a method named 'mapWidget'. The value of the field '_child' isn't used. Try removing the field, or using it.
Full code of my dart file
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'add_new.dart';
class CompanyDataBody extends StatelessWidget {
CompanyDataBody({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: Colors.white,
centerTitle: true,
leading: Padding(
padding: EdgeInsets.only(left: 12),
child: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddNewBody()),
),
),
),
title: Text(
"COMPANY DATA",
style: TextStyle(
color: Color(4293492024),
),
),
actions: <Widget>[
IconButton(
icon: Image.asset('assets/icons/download_logo.png'),
tooltip: 'Download logo',
onPressed: () {},
),
],
),
//backgroundColor: Colors.yellow,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/main_bottom.png"),
alignment: Alignment.bottomCenter,
fit: BoxFit.cover,
),
),
child: MyCardWidget(),
),
),
);
}
}
/// This is the stateless widget that the main application instantiates.
class MyCardWidget extends StatefulWidget {
MyCardWidget({Key key}) : super(key: key);
@override
_MyCardWidgetState createState() => _MyCardWidgetState();
}
class _MyCardWidgetState extends State<MyCardWidget> {
Set<Marker> _createMarker() {
return <Marker>[
Marker(
markerId: MarkerId("current_location"),
position: LatLng(position.latitude, position.longitude),
icon: BitmapDescriptor.defaultMarker,
infoWindow: InfoWindow(title: "Current Location"),
),
].toSet();
}
// ignore: unused_field
GoogleMapController _controller;
Position position;
Widget _child;
@override
void initState() {
//Todo: implement initState
_child = RippleIndicator("Getting Location");
getCurrentLocation();
super.initState();
}
void getCurrentLocation() async {
Position res = await Geolocator().getCurrentPosition();
setState(() {
position = res;
_child = mapWidget();
});
}
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Container(
alignment: Alignment.topCenter,
child: Padding(
padding: const EdgeInsets.only(top: 10, left: 50.0),
child: Column(
children: [
SizedBox(
child: Row(
children: [
Text(
'Company Data',
style: TextStyle(
fontFamily: 'Arial',
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.black,
height: 2,
),
textAlign: TextAlign.center,
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0),
child: Container(
margin: EdgeInsets.only(top: 10),
height: 3.0,
width: 200.0,
color: Color(4293492024),
),
),
],
),
),
],
),
),
),
Column(
children: [
MaterialButton(
onPressed: () {},
color: Color(4293492024),
textColor: Colors.white,
child: Icon(
Icons.camera_alt,
size: 24,
),
padding: EdgeInsets.all(16),
shape: CircleBorder(),
),
Text(
"Add Logo",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
color: Colors.black,
),
),
],
),
SizedBox(
height: 20,
),
Column(
children: [
Text(
"Project Name",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Container(
width: 300,
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Color(4293492024), width: 3.0),
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
child: TextField(
decoration: InputDecoration(
hintText: 'Project Name',
border: InputBorder.none,
),
),
),
Text(
"Project Number",
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Container(
width: 300,
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Color(4293492024), width: 3.0),
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
child: TextField(
decoration: InputDecoration(
hintText: 'Number of workers',
border: InputBorder.none,
),
),
),
],
),
Container(
height: 200,
width: 400,
child: GoogleMap(
mapType: MapType.normal,
markers: _createMarker(),
initialCameraPosition: CameraPosition(
target: LatLng(position.latitude, position.longitude),
zoom: 12.0,
),
onMapCreated: (GoogleMapController controller) {
_controller = controller;
},
),
),
ElevatedButton(
child: Text("Next"),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddNewBody()),
),
style: ElevatedButton.styleFrom(
primary: Color(4293492024),
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
)
],
),
);
}
}
I have added all dependencies. pubspec.yaml file
dependencies:
google_maps_flutter: 0.5.30
geolocator: 5.1.2
location: 3.0.2
url_launcher: 5.7.5
flappy_search_bar: 1.4.1