[英]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.