簡體   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