Flutter 显示RenderViewport的Flatter Silver小部件应为RenderShiver类型的子项,但收到RenderRorBox类型的子项
我正在使用银色小部件显示列表,但显示错误 RenderViewport需要RenderShiver类型的子项,但收到RenderRorBox类型的子项 我想在Silver Widget中或者当我在builder中调用Widget时会出现一些问题 我的代码Flutter 显示RenderViewport的Flatter Silver小部件应为RenderShiver类型的子项,但收到RenderRorBox类型的子项,flutter,dart,Flutter,Dart,我正在使用银色小部件显示列表,但显示错误 RenderViewport需要RenderShiver类型的子项,但收到RenderRorBox类型的子项 我想在Silver Widget中或者当我在builder中调用Widget时会出现一些问题 我的代码 class _EventsState extends State<Events> { dynamic _events = []; dynamic isloader = false; @override initSta
class _EventsState extends State<Events> {
dynamic _events = [];
dynamic isloader = false;
@override
initState() {
// TODO: implement initState
super.initState();
doSomeAsyncStuff();
}
Future<void> doSomeAsyncStuff() async {
setState((){isloader = true;});
final storage = new FlutterSecureStorage();
String value = await storage.read(key: 'token');
print(value);
String url = 'http://sublimeapi.netcodesolution.com/api/NewsAndEvents/';
String token = value;
final response = await http.get(url, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
});
print('Token : ${token}');
dynamic eventData = json.decode(response.body);
print(eventData["Data"]); // this is the data need to show
setState((){
isloader = true;
var _event = eventData["Data"];
});
}
@override
Widget build(BuildContext context) {
double statusBarHeight = MediaQuery
.of(context)
.padding
.top;
return Expanded(
child: Container(
child: new CustomScrollView(
scrollDirection: Axis.vertical,
slivers: <Widget>[
new SliverAppBar(
backgroundColor: Colors.white,
expandedHeight: statusBarHeight * 5,
flexibleSpace: new FlexibleSpaceBar(
title: const Text(
'Event Lists',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20, color: Color(0xff343A40)),
),
),
),
isloader ? CircularProgressIndicator() : // user loader there
new SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
sliver: new SliverFixedExtentList(
itemExtent: 280.0,
delegate: new SliverChildBuilderDelegate(
(builder, index) => _buildListItem(index),
childCount: _events.length),
)),
],
),
),
);
}
Widget _buildListItem(int index) {
double statusBarHeight = MediaQuery.of(context).padding.top;
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return GestureDetector(
child: Center(
child: Card(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
elevation: 30,
child: Container(
child: Stack(
children: <Widget>[
Container(
width: width * 0.6,
height: height * 0.17,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/61.jpg',
),
fit: BoxFit.fill,
),
),
),
Padding(
padding: EdgeInsets.only(top: height * 0.17),
child: Container(
height: height * 0.15,
color: Colors.white,
width: MediaQuery.of(context).size.width * 0.6,
child: Padding(
padding: const EdgeInsets.only(
top: 30, bottom: 7, left: 15, right: 15),
child: Row(
children: <Widget>[
Flexible(
child: Text(
_events[index]['Description'],
style: TextStyle(
color: Color(0xff343A40),
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
],
),
),
),
),
Positioned.fill(
child: Align(
alignment: Alignment.centerLeft,
child: Container(
margin: EdgeInsets.only(left: width * 0.02),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12)),
child: Container(
height: height * 0.08,
width: width * 0.4,
color: Color(0xff343A40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
_events[index]['CreatedOn']
.substring(0, 10),
style: TextStyle(
fontSize: 20,
color: Color(0xffFFFFFF),
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold),
),
]),
),
),
)),
),
],
),
),
),
),
);
}
}
class\u事件状态扩展状态{
动态_事件=[];
动态isloader=false;
@凌驾
initState(){
//TODO:实现initState
super.initState();
doSomeAsyncStuff();
}
Future doSomeAsyncStuff()异步{
setState((){isloader=true;});
最终存储=新存储();
字符串值=wait storage.read(键:'token');
印刷品(价值);
字符串url='0http://sublimeapi.netcodesolution.com/api/NewsAndEvents/';
字符串标记=值;
最终响应=等待http.get(url,标题:{
“内容类型”:“应用程序/json”,
“接受”:“应用程序/json”,
“授权”:“持票人$token”,
});
打印('Token:${Token}');
DynamicEventData=json.decode(response.body);
打印(eventData[“Data”]);//这是需要显示的数据
设置状态(){
isloader=true;
var_event=eventData[“Data”];
});
}
@凌驾
小部件构建(构建上下文){
双statusBarHeight=MediaQuery
.of(上下文)
.填充
顶部
扩大回报(
子:容器(
子项:新自定义滚动视图(
滚动方向:轴垂直,
条子:[
新滑杆(
背景颜色:Colors.white,
扩展高度:statusBarHeight*5,
flexibleSpace:新的FlexibleSpaceBar(
标题:常量文本(
“事件列表”,
textAlign:textAlign.left,
样式:TextStyle(fontSize:20,颜色:color(0xFF343A4)),
),
),
),
isloader?CircularProgressIndicator()://此处的用户加载程序
新型轧棉机(
填充:常量边集。对称(垂直:2.0),
条子:新的条子固定扩展列表(
项目范围:280.0,
代表:新SliverChildBuilderDelegate(
(生成器,索引)=>\u buildListItem(索引),
childCount:_events.length),
)),
],
),
),
);
}
小部件_buildListItem(int索引){
double statusBarHeight=MediaQuery.of(context).padding.top;
double width=MediaQuery.of(context).size.width;
double height=MediaQuery.of(context).size.height;
返回手势检测器(
儿童:中心(
孩子:卡片(
边距:EdgeInsets.zero,
clipBehavior:Clip.antiAlias,
形状:圆形矩形边框(
边界半径:边界半径。圆形(30),
),
标高:30,
子:容器(
子:堆栈(
儿童:[
容器(
宽度:宽度*0.6,
高度:高度*0.17,
装饰:盒子装饰(
图像:装饰图像(
图片:资产评估(
“资产/图像/61.jpg”,
),
fit:BoxFit.fill,
),
),
),
填充物(
填充:仅限边缘设置(顶部:高度*0.17),
子:容器(
高度:高度*0.15,
颜色:颜色,白色,
宽度:MediaQuery.of(context).size.width*0.6,
孩子:填充(
填充:仅限常量边设置(
顶部:30,底部:7,左侧:15,右侧:15),
孩子:排(
儿童:[
灵活的(
子:文本(
_事件[索引]['Description'],
样式:TextStyle(
颜色:颜色(0xFF343A4),
fontFamily:“OpenSans”,
fontWeight:fontWeight.bold,
尺寸:15),,
),
),
],
),
),
),
),
定位填充(
子对象:对齐(
对齐:alignment.centerLeft,
子:容器(
边距:仅限边缘设置(左侧:宽度*0.02),
孩子:ClipRRect(
borderRadius:borderRadius.all(半径圆形(12)),
子:容器(
高度:高度*0.08,
宽度:宽度*0.4,
颜色:颜色(0xFF343A4),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
正文(
_事件[索引]['CreatedOn']
.子串(0,10),
样式:TextStyle(
尺寸:20,
颜色:颜色(0xFFFFFF),
fontFamily:“OpenSans”,
fontWeight:fontWeight.bold),
),
]),
),
new SliverFixedExtentList(
itemExtent: 280.0,
delegate: new SliverChildBuilderDelegate(
(builder, index) => _buildListItem(index),
childCount: _events.length),
)
class _EventsState extends State<Events> {
dynamic _events = [];
dynamic isloader = false;
@override
initState() {
// TODO: implement initState
super.initState();
doSomeAsyncStuff();
}
Future<void> doSomeAsyncStuff() async {
setState((){isloader = true;});
final storage = new FlutterSecureStorage();
String value = await storage.read(key: 'token');
print(value);
String url = 'http://sublimeapi.netcodesolution.com/api/NewsAndEvents/';
String token = value;
final response = await http.get(url, headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
});
print('Token : ${token}');
dynamic eventData = jsonDecode(response.body);
print(eventData["Data"]); // this is the data need to show
setState((){
isloader = true;
if(eventData["Data"] != null){
_events = eventData["Data"];
}
});
}
@override
Widget build(BuildContext context) {
double statusBarHeight = MediaQuery
.of(context)
.padding
.top;
return Container(
child: new CustomScrollView(
scrollDirection: Axis.vertical,
slivers: <Widget>[
new SliverAppBar(
backgroundColor: Colors.white,
expandedHeight: statusBarHeight * 5,
flexibleSpace: new FlexibleSpaceBar(
title: const Text(
'Event Lists',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20, color: Color(0xff343A40)),
),
),
),
new SliverFixedExtentList(
itemExtent: 280.0,
delegate: new SliverChildBuilderDelegate(
(builder, index) => _buildListItem(index),
childCount: _events?.length),
)// user loader there
],
),
);
}
Widget _buildListItem(int index) {
double statusBarHeight = MediaQuery.of(context).padding.top;
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return GestureDetector(
child: Center(
child: Card(
margin: EdgeInsets.zero,
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
elevation: 30,
child: Container(
child: Stack(
children: <Widget>[
Container(
width: width * 0.6,
height: height * 0.17,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/61.jpg',
),
fit: BoxFit.fill,
),
),
),
Padding(
padding: EdgeInsets.only(top: height * 0.17),
child: Container(
height: height * 0.15,
color: Colors.white,
width: MediaQuery.of(context).size.width * 0.6,
child: Padding(
padding: const EdgeInsets.only(
top: 30, bottom: 7, left: 15, right: 15),
child: Row(
children: <Widget>[
Flexible(
child: Text(
_events[index]['Description'],
style: TextStyle(
color: Color(0xff343A40),
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold,
fontSize: 15),
),
),
],
),
),
),
),
Positioned.fill(
child: Align(
alignment: Alignment.centerLeft,
child: Container(
margin: EdgeInsets.only(left: width * 0.02),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(12)),
child: Container(
height: height * 0.08,
width: width * 0.4,
color: Color(0xff343A40),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
_events[index]['CreatedOn']
.substring(0, 10),
style: TextStyle(
fontSize: 20,
color: Color(0xffFFFFFF),
fontFamily: 'OpenSans',
fontWeight: FontWeight.bold),
),
]),
),
),
)),
),
],
),
),
),
),
);
}
}