我关闭并重新打开页面时未对其进行初始化。
一切正常,一切正常
当我重新打开它时,该应用程序只是空白
我还放置了一个mediaquery,用于检测它是平板电脑还是mobileview(正常处理)
final _portrait = Orientation.portrait;
final _landscape = Orientation.landscape;
_screenWidth = constraints.maxWidth;
_screenHeight = constraints.maxHeight;
isMobile = _screenWidth < 650 ? true : false;
它返回一个错误(当我关闭并重新打开该应用程序时)。这意味着该小部件未初始化。
我的代码只是一个简单的小部件树。
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Theme.of(context).backgroundColor,
alignment: Alignment.center,
child: Center(
child: SingleChildScrollView(
// shrinkWrap: true,
child: Column(
children: <Widget>[
SizedBox(
height: MediaQuery.of(context).size.height * 0.05,
),
Mylogo(),
welcomeMessage(context),
],
),
),
),
),
);
} }
Widget welcomeMessage(BuildContext context) {
final bloc = UserProvider.of(context);
double aproxPadding = MediaQuery.of(context).size.width * 0.12;
double aproxPadding2 = MediaQuery.of(context).size.width * 0.05;
double aproxPadding3 = MediaQuery.of(context).size.width * 0.08;
double aproxSizedBox0 = MediaQuery.of(context).size.height * 0.07;
double aproxSizedBox = MediaQuery.of(context).size.height * 0.03;
double aproxSizedBox2 = MediaQuery.of(context).size.height * 0.04;
double aproxSizedBox3 = MediaQuery.of(context).size.height * 0.1;
return ResponsiveTemplate(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: SizeConfiguration.isTablet ? CrossAxisAlignment.center : CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: aproxPadding, right: aproxPadding),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: aproxSizedBox0,
),
Text(
S.of(context).helloScreenInfo1 +
bloc.currentUser.username +
'!',
style: Theme.of(context).textTheme.title,
),
SizedBox(
height: aproxSizedBox,
),
Padding(
padding: EdgeInsets.only(right: aproxPadding2),
child: Text(
S.of(context).helloScreenInfo2,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
),
SizedBox(
height: aproxSizedBox,
),
Padding(
padding: EdgeInsets.only(right: aproxPadding2),
child: AutoSizeText(
S.of(context).helloScreenInfo3,
style: TextStyle(
fontSize: 16.0,
fontWeight: AppWeights.medium
),
),
),
SizedBox(
height: aproxSizedBox2,
),
],
),
),
Padding(
padding: SizeConfiguration.isTablet ? EdgeInsets.only(left: SizeConfiguration.screenWidth * 0.35, right: SizeConfiguration.screenWidth * 0.35) : EdgeInsets.only(left: aproxPadding3, right: aproxPadding3),
child: Column(
children: <Widget>[
CustomButton2(
title: S.of(context).helloScreenBtnStartShift,
asset: 'shift',
onPressed: () {
goToTableAssignmentScreen(context);
},
),
SizedBox(
height: aproxSizedBox3,
),
],
),
)
],
),
);
}