英文:
trying to build an app using Flutterflow, I'm stuck with adding a custom widget to my app, I get 2 errors on multiple lines
问题
我是你的中文翻译,以下是代码的翻译部分:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:math';
import 'package:google_maps_widget/google_maps_widget.dart';
class GMaps extends StatefulWidget {
const GMaps({
Key? key,
this.width,
this.height,
}) : super(key: key);
final double? width;
final double? height;
@override
_GMapsState createState() => _GMapsState();
}
class _GMapsState extends State<GMaps> {
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMapsWidget(
apiKey: "XXXXX",
key: mapsWidgetController,
sourceLatLng: LatLng(
40.484000837597925,
-3.369978368282318,
),
destinationLatLng: LatLng(
40.48017307700204,
-3.3618026599287987,
),
///////////////////////////////////////////////////////
////////////// OPTIONAL PARAMETERS //////////////
///////////////////////////////////////////////////////
routeWidth: 2,
sourceMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "This is source name",
onTapInfoWindow: (_) {
print("Tapped on source info window");
},
assetPath: "assets/images/house-marker-icon.png",
),
destinationMarkerIconInfo: MarkerIconInfo(
assetPath: "assets/images/restaurant-marker-icon.png",
),
driverMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "Alex",
assetPath: "assets/images/driver-marker-icon.png",
onTapMarker: (currentLocation) {
print("Driver is currently at $currentLocation");
},
assetMarkerSize: Size.square(125),
rotation: 90,
),
onPolylineUpdate: (p) {
print("Polyline updated: ${p.points}");
},
updatePolylinesOnDriverLocUpdate: true,
// mock stream
driverCoordinatesStream: Stream.periodic(
Duration(milliseconds: 500),
(i) => LatLng(
40.47747872288886 + i / 10000,
-3.368043154478073 - i / 10000,
),
),
totalTimeCallback: (time) => print(time),
totalDistanceCallback: (distance) => print(distance),
),
),
// demonstrates how to interact with the controller
Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
mapsWidgetController.currentState!.setSourceLatLng(
LatLng(
40.484000837597925 * (Random().nextDouble()),
-3.369978368282318,
),
);
},
child: Text('Update source'),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: () async {
final googleMapsCon = await mapsWidgetController
.currentState!
.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(
MarkerIconInfo.sourceMarkerId,
);
},
child: Text('Show source info'),
),
),
],
),
),
],
),
),
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// can create a controller, and call methods to update source loc,
// destination loc, interact with the google maps controller to
// show/hide markers programmatically etc.
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMapsWidget(
apiKey: "XXXXX",
key: mapsWidgetController,
sourceLatLng: LatLng(
40.484000837597925,
-3.369978368282318,
),
destinationLatLng: LatLng(
40.48017307700204,
-3.3618026599287987,
),
///////////////////////////////////////////////////////
////////////// OPTIONAL PARAMETERS //////////////
///////////////////////////////////////////////////////
routeWidth: 2,
sourceMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "This is source name",
onTapInfoWindow: (_) {
print("Tapped on source info window");
},
assetPath: "assets/images/house-marker-icon.png",
),
destinationMarkerIconInfo: MarkerIconInfo(
assetPath: "assets/images/restaurant-marker-icon.png",
),
driverMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "Alex",
assetPath: "assets/images/driver-marker-icon.png",
onTapMarker: (currentLocation) {
print("Driver is currently at $currentLocation");
},
assetMarkerSize: Size.square(125),
rotation: 90,
),
onPolylineUpdate: (p) {
print("Polyline updated: ${p.points}");
},
updatePolylinesOnDriverLocUpdate: true,
// mock stream
driverCoordinatesStream: Stream.periodic(
Duration(milliseconds: 500),
(i) => LatLng(
40.47747872288886 + i / 10000,
-3.368043154478073 - i / 10000,
),
),
totalTimeCallback: (time) => print(time),
totalDistanceCallback: (distance) => print(distance),
),
),
// demonstrates how to interact with the controller
Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
mapsWidgetController.currentState!.setSourceLatLng(
LatLng(
40.484000837597925 * (Random().nextDouble()),
-3.369978368282318,
),
);
},
child: Text('Update source'),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: () async {
final googleMapsCon = await mapsWidgetController
.currentState!
.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(
MarkerIconInfo.sourceMarkerId,
);
},
child: Text('Show source info'),
),
),
],
),
),
],
),
),
),
);
}
}
请注意,我已将HTML实体(例如"
)转换为相应的双
英文:
same 2 errors I get on multiple lines
I'm a super noob and don't know anything when it comes to programming, I really would appreciate someone sorting this out for me.
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:math';
import 'package:google_maps_widget/google_maps_widget.dart';
class GMaps extends StatefulWidget {
const GMaps({
Key? key,
this.width,
this.height,
}) : super(key: key);
final double? width;
final double? height;
@override
_GMapsState createState() => _GMapsState();
}
class _GMapsState extends State<GMaps> {
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMapsWidget(
apiKey: "XXXXX",
key: mapsWidgetController,
sourceLatLng: LatLng(
40.484000837597925,
-3.369978368282318,
),
destinationLatLng: LatLng(
40.48017307700204,
-3.3618026599287987,
),
///////////////////////////////////////////////////////
////////////// OPTIONAL PARAMETERS //////////////
///////////////////////////////////////////////////////
routeWidth: 2,
sourceMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "This is source name",
onTapInfoWindow: (_) {
print("Tapped on source info window");
},
assetPath: "assets/images/house-marker-icon.png",
),
destinationMarkerIconInfo: MarkerIconInfo(
assetPath: "assets/images/restaurant-marker-icon.png",
),
driverMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "Alex",
assetPath: "assets/images/driver-marker-icon.png",
onTapMarker: (currentLocation) {
print("Driver is currently at $currentLocation");
},
assetMarkerSize: Size.square(125),
rotation: 90,
),
onPolylineUpdate: (p) {
print("Polyline updated: ${p.points}");
},
updatePolylinesOnDriverLocUpdate: true,
// mock stream
driverCoordinatesStream: Stream.periodic(
Duration(milliseconds: 500),
(i) => LatLng(
40.47747872288886 + i / 10000,
-3.368043154478073 - i / 10000,
),
),
totalTimeCallback: (time) => print(time),
totalDistanceCallback: (distance) => print(distance),
),
),
// demonstrates how to interact with the controller
Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
mapsWidgetController.currentState!.setSourceLatLng(
LatLng(
40.484000837597925 * (Random().nextDouble()),
-3.369978368282318,
),
);
},
child: Text('Update source'),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: () async {
final googleMapsCon = await mapsWidgetController
.currentState!
.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(
MarkerIconInfo.sourceMarkerId,
);
},
child: Text('Show source info'),
),
),
],
),
),
],
),
),
),
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// can create a controller, and call methods to update source loc,
// destination loc, interact with the google maps controller to
// show/hide markers programmatically etc.
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMapsWidget(
apiKey: "XXXXX",
key: mapsWidgetController,
sourceLatLng: LatLng(
40.484000837597925,
-3.369978368282318,
),
destinationLatLng: LatLng(
40.48017307700204,
-3.3618026599287987,
),
///////////////////////////////////////////////////////
////////////// OPTIONAL PARAMETERS //////////////
///////////////////////////////////////////////////////
routeWidth: 2,
sourceMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "This is source name",
onTapInfoWindow: (_) {
print("Tapped on source info window");
},
assetPath: "assets/images/house-marker-icon.png",
),
destinationMarkerIconInfo: MarkerIconInfo(
assetPath: "assets/images/restaurant-marker-icon.png",
),
driverMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: "Alex",
assetPath: "assets/images/driver-marker-icon.png",
onTapMarker: (currentLocation) {
print("Driver is currently at $currentLocation");
},
assetMarkerSize: Size.square(125),
rotation: 90,
),
onPolylineUpdate: (p) {
print("Polyline updated: ${p.points}");
},
updatePolylinesOnDriverLocUpdate: true,
// mock stream
driverCoordinatesStream: Stream.periodic(
Duration(milliseconds: 500),
(i) => LatLng(
40.47747872288886 + i / 10000,
-3.368043154478073 - i / 10000,
),
),
totalTimeCallback: (time) => print(time),
totalDistanceCallback: (distance) => print(distance),
),
),
// demonstrates how to interact with the controller
Padding(
padding: const EdgeInsets.all(10),
child: Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () {
mapsWidgetController.currentState!.setSourceLatLng(
LatLng(
40.484000837597925 * (Random().nextDouble()),
-3.369978368282318,
),
);
},
child: Text('Update source'),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: () async {
final googleMapsCon = await mapsWidgetController
.currentState!
.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(
MarkerIconInfo.sourceMarkerId,
);
},
child: Text('Show source info'),
),
),
],
),
),
],
),
),
),
);
}
}
same 2 errors I get on multiple lines
I'm a super noob and don't know anything when it comes to programming,I really would appreciate someone sorting this out for me.
答案1
得分: 1
只是基本上忘记导入LatLng或创建它,
这是编译器无法识别LatLng的方式,
- 在项目中添加
flutter_map: ^0.9.0
,请查看此链接以了解如何将包添加到您的项目中,并按照flutter_map包的步骤操作。 - 现在打开文件并导入
import "package:latlong/latlong.dart" as latLng;
。
英文:
You just basically forget to import LatLng or create it,
That's the way the compiler doesn't recognize LatLng,
- Add
flutter_map: ^0.9.0
to your project check this how to add package to your project follow steps with flutter_map package. - Now open the file and import
import "package:latlong/latlong.dart" as latLng;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论