总结:
我正在尝试使用 pub.dev 中的 flutter_map 包在 FlutterFlow 中构建自定义小部件。我认为我已经非常接近基本构建的工作,但它抛出了一个我不明白如何修复的错误(请参阅下面的错误)。此错误来自底部附近的自定义小部件中的“layers”参数。
我看过一些关于在 Flutter 应用程序中实现此包的教程,他们能够毫无问题地使用“layers”参数。这是一个示例:https://www.youtube.com/watch?v=hZwrcOTxDJI&t=391s
请帮忙:')如果我在这里提供的内容还不够,我非常乐意提供更多信息。
错误: “未定义命名参数‘layers’。尝试将名称更正为现有命名参数的名称,或使用名称‘layers’定义命名参数。”
自定义代码”
// Automatic FlutterFlow imports
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 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart' as ltlng;
class FlutterMapTest extends StatefulWidget {
const FlutterMapTest({Key? key, this.width, this.height, this.layers})
: super(key: key);
final double? width;
final double? height;
@override
_FlutterMapTestState createState() => _FlutterMapTestState();
}
class _FlutterMapTestState extends State<FlutterMapTest> {
@override
Widget build(BuildContext context) {
return Column(children: <Widget>[
FlutterMap(
mapController: MapController(),
options: MapOptions(),
children: [],
layers: TileLayer(
urlTemplate:
"***",
additionalOptions: {
'accessToken':
"***",
},
))
]);
}
}
Pubspec 依赖项 flutter_map:^4.0.0
我尝试创建一个名为“layers”的参数,将该参数添加到代码中,但它没有解决任何问题。老实说,这真是一次黑暗中的尝试。
如果将来有人遇到此问题,解决方案是删除“layers”参数并将 TileLayer 块移动到“children”参数内。我必须重写一些代码才能做到这一点,但我已经设法在我的 FlutterFlow 应用程序中内置了一个功能正常的动态 Mapbox 地图。
这是更新后的代码:
class _FlutterMapWidgetState extends State<FlutterMapWidget> {
@override
Widget build(BuildContext context) {
return Container(
width: widget.width,
height: widget.height,
child: FlutterMap(
mapController: MapController(),
options: MapOptions(
center: ltlng.LatLng(34.6, -92.4),
zoom: 7.0,
minZoom: 7.0,
),
children: [
TileLayer(
urlTemplate:
"***",
additionalOptions: {
'accessToken':
"***",
}, //additionalOptions
) //TileLayer
], //children
) //FlutterMap
);
}
}