这是我在android studio(Windows系统)中的代码。
如何解决这个问题,我已经使用了单一的滚动视图,但得到的RenderFlex孩子有非零
error......?
另外,我已经用小工具包装,但同样的问题......?
下面是我的代码:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'ubuntu',
),
home: MyHomePage(),
routes: {
'/MainPage' : (context)=>MainPage(),
},
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: purple,
body: SingleChildScrollView(
child: Column(
children: [
Container(
width: 100,
height: 50,
margin: EdgeInsets.only(top: 40),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/logo.png')
)
),
),
SizedBox(height: 30,),
Text("Clean Home\nClean Life", style: TextStyle(
fontSize: 40,
color: Colors.white,
fontWeight: FontWeight.w900
),textAlign: TextAlign.center,),
SizedBox(height: 30,),
Text("Book Cleans At The Comfort \nOf Your Home", style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.w400,
), textAlign: TextAlign.center,),
SizedBox(height: 60,),
Container(
height: 350,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/splash.png'),
fit: BoxFit.cover
)
),
),
Expanded(
child: Container(),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell(
onTap: openMainPage,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 60, vertical: 30),
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(20)),
color: Colors.white
),
child: Text('Continue..', style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: purple
),),
),
)
],
)
],
),
),
);
}
void openMainPage()
{
Navigator.pushNamed(context, '/MainPage');
}
}
........
发布于 2020-11-28 11:12:31
要使内容可滚动,它必须溢出视口高度。由于您在使用Row
之前使用Expanded
,因此您的Column
将扩展到最大高度,并且不会有任何滚动。如果您从Container
中删除Expanded
并设置Container
高度(例如500.0),那么您的内容将溢出视口并变为可滚动。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
fontFamily: 'ubuntu',
),
home: MyHomePage(),
// routes: {
// '/MainPage' : (context)=>MainPage(),
// },
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.purple,
body: SingleChildScrollView(
child: Column(
children: [
Container(
width: 100,
height: 50,
margin: EdgeInsets.only(top: 40),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://2.bp.blogspot.com/-3VnKmSv5FXg/XCc1YFehs-I/AAAAAAAAPt4/zxnpIVoYSvQFGtIVeNqTILDsCaIg8Ql-wCLcBGAs/s1600/Mirillis%2B-%2BSplash%2BPremium%2BFull%2Bversion.png'))),
),
SizedBox(
height: 30,
),
Text(
"Clean Home\nClean Life",
style: TextStyle(
fontSize: 40,
color: Colors.white,
fontWeight: FontWeight.w900),
textAlign: TextAlign.center,
),
SizedBox(
height: 30,
),
Text(
"Book Cleans At The Comfort \nOf Your Home",
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.w400,
),
textAlign: TextAlign.center,
),
SizedBox(
height: 60,
),
Container(
height: 350,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://2.bp.blogspot.com/-3VnKmSv5FXg/XCc1YFehs-I/AAAAAAAAPt4/zxnpIVoYSvQFGtIVeNqTILDsCaIg8Ql-wCLcBGAs/s1600/Mirillis%2B-%2BSplash%2BPremium%2BFull%2Bversion.png'),
fit: BoxFit.cover)),
),
//! Comment this
// Expanded(
// child: Container(),
// ),
//! Add height here
Container(
height: 500,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell(
onTap: openMainPage,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 60, vertical: 30),
decoration: BoxDecoration(
borderRadius:
BorderRadius.only(topLeft: Radius.circular(20)),
color: Colors.white),
child: Text(
'Continue..',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Colors.purple),
),
),
)
],
)
],
),
),
);
}
void openMainPage() {
Navigator.pushNamed(context, '/MainPage');
}
}
另外,我用NetworkImage
替换了AssetImage
,因为我没有你的图片。
https://stackoverflow.com/questions/65047993
复制相似问题