【发布时间】:2021-11-10 21:30:38
【问题描述】:
我是 Flutter 的新手,正在尝试为 iOS 制作一个简单的程序。该程序将显示带有标记的谷歌地图。我需要添加搜索字符串来过滤标记。但是当我尝试将 TextField 添加到我的应用程序时 - 它会因错误“被调用的构造函数不是 const 构造函数”而崩溃。
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'src/locations.dart' as locations;
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
...
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge, overlays: []);
return MaterialApp(
home: Scaffold(
body: Stack(
children: <Widget>[
GoogleMap(
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 11.0,
),
mapType: _currentMapType,
zoomControlsEnabled: false,
myLocationEnabled: false,
onCameraMove: _onCameraMove,
markers: _rmarkers.values.toSet(),
),
Positioned(
top: 32,
left: 5,
child: Container(
margin: EdgeInsets.all(20),
height: 70,
width: 300,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(15)),
boxShadow: <BoxShadow>[
BoxShadow(
blurRadius: 10,
offset: Offset(5.0, 5.0),
color: Colors.black.withOpacity(0.8))
]),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.search, size: 36.0),
Container(
padding: EdgeInsets.all(3.0),
child: Expanded(
==> HERE child: TextField(
==> THE decoration: InputDecoration(
==> PROBLEM hintText: "What is you looking for?",
),
))),
Icon(Icons.account_circle, size: 36.0),
]),
),
),
],
),
),
);
}
}
上面没有声明任何 const。而且我在这里或通过互联网找不到任何想法,这里有什么问题。如果我愿意改变:
TextField(
decoration: InputDecoration(
hintText: "What is you looking for?",
),
)
通过
Text("What is you looking for?")
一切正常。
【问题讨论】:
标签: flutter constructor constants textfield