gpt4 book ai didi

android - 打开 Flutter 应用后出现空白白屏

转载 作者:行者123 更新时间:2023-12-03 03:56:21 27 4
gpt4 key购买 nike

我对 Flutter 很陌生,我最近在在线类(class)的帮助下创建了一个天气应用程序。该应用程序在 android 模拟器上以及当我在手机上运行时运行良好。但我想分享应用程序,所以我使用 flutter build apk --split-per-abi 创建了一个发布 apk但是在他们的手机上安装应用程序后,第一个屏幕加载并立即出现一个空白的白色屏幕,没有任何 react 。
当我在 android studio 中运行应用程序时不会出现此类错误

我的第一个加载屏幕页面

import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../services/weather.dart';
import 'location_screen.dart';
import 'package:location_permissions/location_permissions.dart';

class LoadingScreen extends StatefulWidget {
@override
_LoadingScreenState createState() => _LoadingScreenState();
}

class _LoadingScreenState extends State<LoadingScreen> {

@override
void initState() {
getWeatherData();
super.initState();
}

void getWeatherData () async {
PermissionStatus permission = await LocationPermissions().requestPermissions();
var weatherData = await WeatherModel().getWeather();
Navigator.push(context, MaterialPageRoute(builder: (context){
return LocationScreen(weatherData: weatherData);
}));
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SpinKitFoldingCube(
color: Colors.blueAccent,
size: 100,
),
)
);
}
}

我的第二个天气位置屏幕
import 'package:clima/services/weather.dart';
import 'package:flutter/material.dart';
import 'package:clima/utilities/constants.dart';
import 'city_screen.dart';
import '../services/weather.dart';

class LocationScreen extends StatefulWidget {
final weatherData;
LocationScreen({this.weatherData});
@override
_LocationScreenState createState() => _LocationScreenState();
}

class _LocationScreenState extends State<LocationScreen> {
int temperature;
String icon;
String message;
String cityName;
String summary;

TimeOfDay t = TimeOfDay.now();
@override
void initState() {
super.initState();
updateScreen(widget.weatherData);
}

AssetImage setBackground(){
print(t.hour);
if(t.hour >18 || t.hour < 6)
return AssetImage("images/night.png");
else
return AssetImage('images/after_noon.png');
}
void updateScreen(dynamic weatherData) {
setState(() {
if (weatherData == null) {
temperature = 0;
icon = 'error';
message = 'Sorry Coudnt load Weather ';
cityName = '';
summary='';
} else {
double temp = (weatherData['main']['temp']);
temperature = temp.toInt();
icon = WeatherModel().getWeatherIcon(weatherData['weather'][0]['id']);
message = WeatherModel().getMessage(temperature);
cityName = weatherData['name'];
summary=weatherData['weather'][0]['description'];
}
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: setBackground(),
fit: BoxFit.cover,
colorFilter: ColorFilter.mode(
Colors.white.withOpacity(0.8), BlendMode.dstATop),
),
),
constraints: BoxConstraints.expand(),
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
FlatButton(
onPressed: () async {
updateScreen(WeatherModel().getWeather());
},
child: Icon(
Icons.near_me,
size: 50.0,
),
),
FlatButton(
onPressed: () async{
var cityName = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return CityScreen();
},
),
);

if(cityName != null)
{
var weatherData = await WeatherModel().getCityWeather(cityName);
updateScreen(weatherData);
}
},
child: Icon(
Icons.location_city,
size: 50.0,
),
),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 15.0),
child: Row(
children: <Widget>[
Text(
'$temperature',
style: kTempTextStyle,
),
Text(
'$icon',
style: kConditionTextStyle,
),
],
),
),
Padding(
padding: EdgeInsets.only(left: 15.0),
child: Text(
"$summary",
style: TextStyle(
fontSize: 30,
fontFamily: 'Spartan MB',
fontStyle: FontStyle.italic,
),
),
),
],
),
Padding(
padding: EdgeInsets.only(right: 15.0),
child: Text(
"$message in $cityName",
textAlign: TextAlign.right,
style: kMessageTextStyle,
),
),
],
),
),
),
);
}
}

最佳答案

您需要在根路由或主页中导入后调用以下函数

void main() => runApp(LoadingScreen());

关于android - 打开 Flutter 应用后出现空白白屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60957810/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com