Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 未找到任何材料部件_Flutter_Widget_Material Design - Fatal编程技术网

Flutter 未找到任何材料部件

Flutter 未找到任何材料部件,flutter,widget,material-design,Flutter,Widget,Material Design,我正在尝试访问此控制器,但不知道为什么它会崩溃。作为一个错误,他告诉我: 找不到任何材料小部件 iconButtonwidget需要材质小部件 是一个简单的视图,显示带有各种保存点的地图 我是否初始化视图时出错 谁能告诉我我做错了什么 这是我使用的代码 class MapTab extends StatefulWidget { @override _MapTabState createState() => _MapTabState(); } class _MapTabState

我正在尝试访问此控制器,但不知道为什么它会崩溃。作为一个错误,他告诉我:

找不到任何材料小部件 iconButtonwidget需要材质小部件

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

我是否初始化视图时出错

谁能告诉我我做错了什么

这是我使用的代码

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);
            },
          ),
        ),
      ],
    );
  }
}
类映射选项卡扩展StatefulWidget{
@凌驾
_MapTabState createState()=>\u MapTabState();
}
类_MapTabState扩展状态{
大小(单位)大小;;
MapboxMapController\u mapController;
StreamController _bottomCardStreamController;
_onMapCreated(MapboxMapController控制器){
_mapController=控制器;
contentManager.getMerchants()。然后(
(餐厅)=>restaurants.forEach(
(餐厅)=>controller.addSymbol(
符号选项(
几何:LatLng(double.parse(restaurant.coordinates.lat),
double.parse(restaurant.coordinates.long)),
iconImage:“资产/图像/map_pin.png”,
),
restaurant.toJson(),
),
),
);
controller.onSymbolTapped.add((符号)异步{
Restaurant Restaurant=Restaurant.fromJson(symbol.data);
_toggleBottomCard(餐厅);
});
_bottomCardStreamController.stream.listen((餐厅){
如果(餐厅==null)返回;
列表更新=[
摄像机更新。zoomTo(15),
摄像机更新。新拉特林(拉特林)(
double.parse(restaurant.coordinates.lat),
double.parse(restaurant.coordinates.long),
)),
];
更新
.forEach((元素)async=>await controller.animateCamera(元素));
});
}
_toggleBottomCard(餐厅数据){
_bottomCardStreamController.sink.add(数据);
}
@凌驾
void initState(){
super.initState();
_bottomCardStreamController=StreamController.broadcast();
}
@凌驾
无效处置(){
_bottomCardStreamController.close();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
_size=MediaQuery.of(context).size;
返回堆栈(
对齐:对齐方向.center,
儿童:[
未来建设者(
future:PositionService.getCurrentPosition(),
生成器:(上下文,异步快照位置捕捉){
if(positionSnap.hasError)
返回中心(
子项:文本(本地化.err_本地化),
);
if(positionSnap.connectionState!=connectionState.done)
返回容器(
儿童:中心(
子项:循环压缩器指示器(值颜色:新的AlwaysStoppedAnimation(appColors.yellow)),
),
);
var数据=位置捕捉数据;
var latLng=latLng(数据.纬度,数据.经度);
回归未来建设者(
future:contentManager.getMapBoxKey(),
生成器:(上下文,标记捕捉){
if(tokenSnap.hasError)
返回容器(
儿童:中心(
子项:文本(本地化.err\u映射框\u键),
),
);
if(tokenSnap.connectionState!=connectionState.done)
返回容器(
儿童:中心(
子项:循环压缩器指示器(值颜色:新的AlwaysStoppedAnimation(appColors.yellow)),
),
);
返回容器(
高度:_size.height,
宽度:_size.width,
子:MapboxMap(
RotategestureEnabled:错误,
myLocationEnabled:对,
onStyleLoadedCallback:(){},
zoomGesturesEnabled:对,
onmaplick:(u,uu){
//足总杯底卡
_bottomCardStreamController.sink.add(null);
},
accessToken:tokenSnap.data,
onMapCreated:_onMapCreated,
符合条件:错误,
initialCameraPosition:CameraPosition(
目标:拉丁美洲,
缩放:15,
方位:0,,
倾斜:0,
),
),
);
});
}),
定位(
底部:10,
右:10,,
身高:50,
宽度:50,
儿童:手势检测器(
子:容器(
装饰:盒子装饰(
颜色:color.fromARGB(255,255,255,255),
形状:BoxShape.circle,
),
子:图标(图标。我的位置),
),
onTap:()异步{
var position=await PositionService.getCurrentPosition();
var latLng=latLng(位置、纬度、位置、经度);
_mapController.animateCamera(CameraUpdate.newLatLng(latLng));
},
),
),
定位(
前10名,
左:0,,
宽度:_size.width,
孩子:排(
mainAxisSize:mainAxisSize.min,
儿童:[
图标按钮(
图标:图标(
图标列表,
),
按下:(){},
),
灵活的(
儿童:手势检测器(
onTap:()异步{
等待展示搜索(
上下文:上下文,
委托:CustomSearchDelegate(),
查询:“”,
Widget build(BuidContext context){
  return  MaterialApp(
    home: Stack() // your stack and other widgets are here.
  );
}