找不到任何材质的小部件flutter



我试图访问这个控制器,但我不知道它为什么崩溃。他给我的错误是:

找不到材料小部件iconButtonwidget需要一个材料widget

是一个简单的视图,显示了带有各种保存点的地图

我初始化视图不正确吗?

有人能告诉我我做错了什么吗?

这是我使用的代码

class MapTab extends StatefulWidget {
@override
_MapTabState createState() => _MapTabState();
}
class _MapTabState extends State<MapTab> {
Size _size;
MapboxMapController _mapController;
StreamController<Restaurant> _bottomCardStreamController;
_onMapCreated(MapboxMapController controller) {
_mapController = controller;
contentManager.getMerchants().then(
(restaurants) => restaurants.forEach(
(restaurant) => controller.addSymbol(
SymbolOptions(
geometry: LatLng(double.parse(restaurant.coordinates.lat),
double.parse(restaurant.coordinates.long)),
iconImage: "assets/images/map_pin.png",
),
restaurant.toJson(),
),
),
);
controller.onSymbolTapped.add((symbol) async {
Restaurant restaurant = Restaurant.fromJson(symbol.data);
_toggleBottomCard(restaurant);
});
_bottomCardStreamController.stream.listen((restaurant) {
if (restaurant == null) return;
List<CameraUpdate> updates = [
CameraUpdate.zoomTo(15),
CameraUpdate.newLatLng(LatLng(
double.parse(restaurant.coordinates.lat),
double.parse(restaurant.coordinates.long),
)),
];
updates
.forEach((element) async => await controller.animateCamera(element));
});
}
_toggleBottomCard(Restaurant data) {
_bottomCardStreamController.sink.add(data);
}
@override
void initState() {
super.initState();
_bottomCardStreamController = StreamController<Restaurant>.broadcast();
}
@override
void dispose() {
_bottomCardStreamController.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
_size = MediaQuery.of(context).size;
return Stack(
alignment: AlignmentDirectional.center,
children: [
FutureBuilder<Position>(
future: PositionService.getCurrentPosition(),
builder: (context, AsyncSnapshot<Position> positionSnap) {
if (positionSnap.hasError)
return Center(
child: Text(localization.err_localization),
);
if (positionSnap.connectionState != ConnectionState.done)
return Container(
child: Center(
child: CircularProgressIndicator(valueColor: new AlwaysStoppedAnimation<Color>(appColors.yellow)),
),
);
var data = positionSnap.data;
var latLng = LatLng(data.latitude, data.longitude);
return FutureBuilder<String>(
future: contentManager.getMapBoxKey(),
builder: (context, tokenSnap) {
if (tokenSnap.hasError)
return Container(
child: Center(
child: Text(localization.err_mapbox_key),
),
);
if (tokenSnap.connectionState != ConnectionState.done)
return Container(
child: Center(
child: CircularProgressIndicator(valueColor: new AlwaysStoppedAnimation<Color>(appColors.yellow)),
),
);
return Container(
height: _size.height,
width: _size.width,
child: MapboxMap(
rotateGesturesEnabled: false,
myLocationEnabled: true,
onStyleLoadedCallback: () {},
zoomGesturesEnabled: true,
onMapClick: (_, __) {
// fa scomparire la bottomCard
_bottomCardStreamController.sink.add(null);
},
accessToken: tokenSnap.data,
onMapCreated: _onMapCreated,
compassEnabled: false,
initialCameraPosition: CameraPosition(
target: latLng,
zoom: 15,
bearing: 0,
tilt: 0,
),
),
);
});
}),
Positioned(
bottom: 10,
right: 10,
height: 50,
width: 50,
child: GestureDetector(
child: Container(
decoration: BoxDecoration(
color: Color.fromARGB(255, 255, 255, 255),
shape: BoxShape.circle,
),
child: Icon(Icons.my_location),
),
onTap: () async {
var position = await PositionService.getCurrentPosition();
var latLng = LatLng(position.latitude, position.longitude);
_mapController.animateCamera(CameraUpdate.newLatLng(latLng));
},
),
),
Positioned(
top: 10,
left: 0,
width: _size.width,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: Icon(
Icons.list,
),
onPressed: () {},
),
Flexible(
child: GestureDetector(
onTap: () async {
await showSearch<Restaurant>(
context: context,
delegate: CustomSearchDelegate(),
query: "",
).then(
(value) => _bottomCardStreamController.sink.add(value),
);
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: 3,
vertical: 2,
),
child: TextField(
enabled: false,
decoration: InputDecoration(
icon: Icon(
Icons.search,
color: Colors.grey,
),
hintText: localization.find,
border: InputBorder.none,
),
),
),
),
),
),
IconButton(
icon: Icon(
Icons.filter_alt,
),
onPressed: () {},
)
],
),
),
Positioned(
bottom: 25,
width: _size.width,
child: StreamBuilder<Restaurant>(
stream: _bottomCardStreamController.stream,
builder: (_, snap) {
if (snap.data == null)
return Container();
else
return RestaurantMapCard(snap.data,
mapController: _mapController);
},
),
),
],
);
}
}

MaterialApp小部件包装根(第一个小部件(。

Widget build(BuidContext context){
return  MaterialApp(
home: Stack() // your stack and other widgets are here.
);
}

相关内容

  • 没有找到相关文章

最新更新