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

huangapple go评论67阅读模式
英文:

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实体(例如&quot;)转换为相应的双

英文:

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 &#39;/backend/backend.dart&#39;;
import &#39;/flutter_flow/flutter_flow_theme.dart&#39;;
import &#39;/flutter_flow/flutter_flow_util.dart&#39;;
import &#39;/custom_code/widgets/index.dart&#39;; // Imports other custom widgets
import &#39;/flutter_flow/custom_functions.dart&#39;; // Imports custom functions
import &#39;package:flutter/material.dart&#39;;
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import &#39;dart:math&#39;;
import &#39;package:google_maps_widget/google_maps_widget.dart&#39;;
class GMaps extends StatefulWidget {
const GMaps({
Key? key,
this.width,
this.height,
}) : super(key: key);
final double? width;
final double? height;
@override
_GMapsState createState() =&gt; _GMapsState();
}
class _GMapsState extends State&lt;GMaps&gt; {
final mapsWidgetController = GlobalKey&lt;GoogleMapsWidgetState&gt;();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMapsWidget(
apiKey: &quot;XXXXX&quot;,
key: mapsWidgetController,
sourceLatLng: LatLng(
40.484000837597925,
-3.369978368282318,
),
destinationLatLng: LatLng(
40.48017307700204,
-3.3618026599287987,
),
///////////////////////////////////////////////////////
//////////////    OPTIONAL PARAMETERS    //////////////
///////////////////////////////////////////////////////
routeWidth: 2,
sourceMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: &quot;This is source name&quot;,
onTapInfoWindow: (_) {
print(&quot;Tapped on source info window&quot;);
},
assetPath: &quot;assets/images/house-marker-icon.png&quot;,
),
destinationMarkerIconInfo: MarkerIconInfo(
assetPath: &quot;assets/images/restaurant-marker-icon.png&quot;,
),
driverMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: &quot;Alex&quot;,
assetPath: &quot;assets/images/driver-marker-icon.png&quot;,
onTapMarker: (currentLocation) {
print(&quot;Driver is currently at $currentLocation&quot;);
},
assetMarkerSize: Size.square(125),
rotation: 90,
),
onPolylineUpdate: (p) {
print(&quot;Polyline updated: ${p.points}&quot;);
},
updatePolylinesOnDriverLocUpdate: true,
// mock stream
driverCoordinatesStream: Stream.periodic(
Duration(milliseconds: 500),
(i) =&gt; LatLng(
40.47747872288886 + i / 10000,
-3.368043154478073 - i / 10000,
),
),
totalTimeCallback: (time) =&gt; print(time),
totalDistanceCallback: (distance) =&gt; 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(&#39;Update source&#39;),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: () async {
final googleMapsCon = await mapsWidgetController
.currentState!
.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(
MarkerIconInfo.sourceMarkerId,
);
},
child: Text(&#39;Show source info&#39;),
),
),
],
),
),
],
),
),
),
);
}
}
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&lt;GoogleMapsWidgetState&gt;();
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
body: Column(
children: [
Expanded(
child: GoogleMapsWidget(
apiKey: &quot;XXXXX&quot;,
key: mapsWidgetController,
sourceLatLng: LatLng(
40.484000837597925,
-3.369978368282318,
),
destinationLatLng: LatLng(
40.48017307700204,
-3.3618026599287987,
),
///////////////////////////////////////////////////////
//////////////    OPTIONAL PARAMETERS    //////////////
///////////////////////////////////////////////////////
routeWidth: 2,
sourceMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: &quot;This is source name&quot;,
onTapInfoWindow: (_) {
print(&quot;Tapped on source info window&quot;);
},
assetPath: &quot;assets/images/house-marker-icon.png&quot;,
),
destinationMarkerIconInfo: MarkerIconInfo(
assetPath: &quot;assets/images/restaurant-marker-icon.png&quot;,
),
driverMarkerIconInfo: MarkerIconInfo(
infoWindowTitle: &quot;Alex&quot;,
assetPath: &quot;assets/images/driver-marker-icon.png&quot;,
onTapMarker: (currentLocation) {
print(&quot;Driver is currently at $currentLocation&quot;);
},
assetMarkerSize: Size.square(125),
rotation: 90,
),
onPolylineUpdate: (p) {
print(&quot;Polyline updated: ${p.points}&quot;);
},
updatePolylinesOnDriverLocUpdate: true,
// mock stream
driverCoordinatesStream: Stream.periodic(
Duration(milliseconds: 500),
(i) =&gt; LatLng(
40.47747872288886 + i / 10000,
-3.368043154478073 - i / 10000,
),
),
totalTimeCallback: (time) =&gt; print(time),
totalDistanceCallback: (distance) =&gt; 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(&#39;Update source&#39;),
),
),
const SizedBox(width: 10),
Expanded(
child: ElevatedButton(
onPressed: () async {
final googleMapsCon = await mapsWidgetController
.currentState!
.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(
MarkerIconInfo.sourceMarkerId,
);
},
child: Text(&#39;Show source info&#39;),
),
),
],
),
),
],
),
),
),
);
}
}

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的方式,

  1. 在项目中添加flutter_map: ^0.9.0,请查看此链接以了解如何将包添加到您的项目中,并按照flutter_map包的步骤操作。
  2. 现在打开文件并导入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,

  1. Add flutter_map: ^0.9.0 to your project check this how to add package to your project follow steps with flutter_map package.
  2. Now open the file and import import &quot;package:latlong/latlong.dart&quot; as latLng;

huangapple
  • 本文由 发表于 2023年3月7日 07:17:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定