为什么此代码在 运行 时显示空白屏幕?
Why does this code display a blank screen when running?
在显示代码之前,我检查了以下内容以避免出现类似的答案:
android:extratNativeLibs="true"
已连接 Jsonfile firebase
routegenerator 和 initialroute 在主文件中检查并且
生成器文件
。我喜欢避免使用 mediaQuery 而使用百分比,这就是我使用 FractionallySizedBox 的原因。这是初始路线的代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Start extends StatelessWidget {
const Start({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.center,
child: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
FractionallySizedBox(widthFactor: 0.15, heightFactor: 0.15, child: Image.asset('assets/crown.png')),
FractionallySizedBox(
widthFactor: 0.40,
heightFactor: 0.20,
child: TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/items');
},
child: Container(
decoration: BoxDecoration(color: Colors.purple),
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
const Text('Start shopping',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 25,
)),
Image.asset('assets/crown.png')
]))))
])))));
}
}
用 Expanded
扭曲你的 FractionallySizedBox
Expanded(
child: FractionallySizedBox(
widthFactor: 0.15,
heightFactor: 0.15,
child: Image.asset('assets/crown.png')),
),
Expanded(
child: FractionallySizedBox(
widthFactor: 0.40,
heightFactor: 0.20,
child: TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/items');
},
child: Container(
decoration: BoxDecoration(color: Colors.purple),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Start shopping',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 25,
)),
Image.asset('assets/crown.png')
],
),
),
),
),
),
在显示代码之前,我检查了以下内容以避免出现类似的答案:
android:extratNativeLibs="true"
已连接 Jsonfile firebase
routegenerator 和 initialroute 在主文件中检查并且
生成器文件
。我喜欢避免使用 mediaQuery 而使用百分比,这就是我使用 FractionallySizedBox 的原因。这是初始路线的代码:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Start extends StatelessWidget {
const Start({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Align(
alignment: Alignment.center,
child: Center(
child: Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
FractionallySizedBox(widthFactor: 0.15, heightFactor: 0.15, child: Image.asset('assets/crown.png')),
FractionallySizedBox(
widthFactor: 0.40,
heightFactor: 0.20,
child: TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/items');
},
child: Container(
decoration: BoxDecoration(color: Colors.purple),
child: Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
const Text('Start shopping',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 25,
)),
Image.asset('assets/crown.png')
]))))
])))));
}
}
用 Expanded
FractionallySizedBox
Expanded(
child: FractionallySizedBox(
widthFactor: 0.15,
heightFactor: 0.15,
child: Image.asset('assets/crown.png')),
),
Expanded(
child: FractionallySizedBox(
widthFactor: 0.40,
heightFactor: 0.20,
child: TextButton(
onPressed: () {
Navigator.of(context).pushNamed('/items');
},
child: Container(
decoration: BoxDecoration(color: Colors.purple),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('Start shopping',
style: TextStyle(
color: Colors.white,
fontStyle: FontStyle.italic,
fontSize: 25,
)),
Image.asset('assets/crown.png')
],
),
),
),
),
),