在一个页面中通过Scaffold>SafeArea>SingleChildScrollView>column>(container,row)布局,希望内容能超出时进行滚动,但报错RenderBox was not laid out,网上百度了几个方法试了一下,没有效果,我应该怎么解决这个问题?谢谢--
[代码]
import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/widget/m_button.dart';
import 'package:flutter_demo/widget/m_head.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key, this.params}) : super(key: key);
static const String title = "xxx";
final dynamic params;
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MHead(
title: HomePage.title,
actions: [
UnconstrainedBox(
child: MIconButton(icon: Icon(Icons.settings),text: "偏好设置",),
)
],
),
body: SafeArea(
child: SingleChildScrollView(
child: _content(context),
)
),
// body: _content(context),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
Widget _content(BuildContext context){
String htmlcontent = """
如上图所示,当用户点击绿色光点位置之后,首先我们可以根据点击事件确认被点击是哪一个Element所渲染的RenderObject;
首先我们通过globalToLocal方法将手势回调的globalPosition转换为相对于Mural的localPosition;接下来遍历MuralRenderEditable的child,寻找包含localPosition的child;
作者:闲鱼技术
链接:https://juejin.cn/post/7106732801906606116
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
""";
return Column(
// mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Image.network(
'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'),
Container(
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white
),
child: Column(
children: [
Row(
children: [
Icon(Icons.man),
Text("李白xxxx", style: TextStyle(fontSize: 18),)
],
),
SizedBox(
height: 10,
),
Row(
children: [
Padding(padding: EdgeInsets.only(right: 10),child: Text("xx"),),
Padding(padding: EdgeInsets.only(right: 10),child: Text("xx"),),
Padding(padding: EdgeInsets.only(right: 10),child: Text("xx"),),
],
),
SizedBox(
height: 10,
),
Row(
children: [
Padding(padding: EdgeInsets.only(right: 10),child: Text("xx"),),
Padding(padding: EdgeInsets.only(right: 10),child: Text("xx"),),
Padding(padding: EdgeInsets.only(right: 10),child: Text("xx"),),
],
),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(color: Colors.white),
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(bottom: 20),
child: Container(
decoration: BoxDecoration(color: Colors.green),
padding: EdgeInsets.all(10),
child: RichText(text: TextSpan(
text: htmlcontent
)),
),
)
)
],
);
}
}
SingleChildScrollView
已经可以滚动了, 把Expanded
拿掉就可以了。