繁体   English   中英

带堆栈的黑屏颤动

[英]Black screen flutter with stack

我一直在使用stack小部件并positioned在一起,经过几次构建后,我在使用routes时出现黑屏,但是当我使用其他小部件时,例如我没有出现黑屏。 我正在使用Navigator.popAndPushNamed(...)推送路线

drawer:Drawer(...)
 body: Stack(
    children: <Widget>[
      Positioned.fill(
        child: GoogleMap(
          myLocationEnabled: true,
          mapType: MapType.normal,
          onMapCreated: _onMapCreated,
          compassEnabled: true,
          //trackCameraPosition: true,
          initialCameraPosition: CameraPosition(
            target: _center,
            zoom: 12.0,
          ),
        ),
      ),
      Positioned(
          bottom: 50,
          right: -17,
          child: FloatingActionButton.extended(
              label: Text(""),
              icon: Icon(
                Icons.my_location,
                color: Colors.greenAccent,
                size: 30,
              ),
              backgroundColor: Colors.white,
              onPressed: () async {
                Map<PermissionGroup, PermissionStatus> permisions =
                    await PermissionHandler()
                        .requestPermissions([PermissionGroup.location]);
                print(permisions);
                if (permisions[PermissionGroup.location] ==
                    PermissionStatus.granted) {
                  //start qr
                  _currentLocation();
                  setState(() {
                    isOk = true;
                  });
                }
                _currentLocation();
              })),
      Positioned(
          bottom: 110,
          right: -17,
          child: FloatingActionButton.extended(
              label: Text(""),
              icon: Icon(
                Icons.refresh,
                color: Colors.greenAccent,
                size: 30,
              ),
              backgroundColor: Colors.white,
              onPressed: () async {
                Map<PermissionGroup, PermissionStatus> permisions =
                    await PermissionHandler()
                        .requestPermissions([PermissionGroup.location]);
                print(permisions);
                if (permisions[PermissionGroup.location] ==
                    PermissionStatus.granted) {
                  //start qr
                  _currentLocation();
                  setState(() {
                    isOk = true;
                  });
                }
                _currentLocation();
              })),
      Positioned(
          bottom: 50,
          left: 2,
          child: FloatingActionButton(
              child: Icon(
                Icons.report_problem,
                color: Colors.greenAccent,
                size: 30,
              ),

              // Icon(Icons.report_problem, color: Colors.greenAccent),
              backgroundColor: Colors.white,
              onPressed: () {
                _reportBottomSheet(context);
              })),

], ),

//这是我使用location插件获取当前位置

//get current location 
void _currentLocation() async {
    final GoogleMapController controller = await mapController;
    LocationData currentLocation;
    var location = new Location();
    try {
      currentLocation = await location.getLocation();
    } on Exception {
      currentLocation = null;
    }

    controller.animateCamera(CameraUpdate.newCameraPosition(
      CameraPosition(
        bearing: 0,
        target: LatLng(currentLocation.latitude, currentLocation.longitude),
        zoom: 16.0,
      ),
    ));
  }

//report
 void _reportBottomSheet(context) {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext bc) {
          return Container(
            padding: EdgeInsets.all(12.0),
            child: new Wrap(
              children: <Widget>[
                Text(
                  "Report a problem",
                  style: TextStyle(
                      fontSize: 15,
                      color: Colors.greenAccent,
                      fontStyle: FontStyle.normal,
                      fontWeight: FontWeight.bold),
                ),
                ListTile(
                    leading: Tab(
                      icon: Image.asset("assets/icons/il.png"),
                    ),
                    title: new Text('il'),
                    onTap: () => {
                          Navigator.popAndPushNamed(context, "/ill")
                        }),...

您的代码似乎缺少 Material Widget。 尝试在您的body添加Scaffold以覆盖您的小部件( Scaffold是一种材质小部件)。 东西如下..

return Scaffold(
  body: Stack(...),
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM