黑屏颤抖并带有堆栈

时间:2019-09-04 19:04:06

标签: flutter flutter-layout

我一直在使用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")
                        }),...

1 个答案:

答案 0 :(得分:0)

似乎您的代码缺少Material Widget。尝试在Scaffold中添加body来覆盖小部件(Scaffold是“材料小部件”的一种)。如下。

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