我正在设置一个具有内部水平listview的布局
布局结构如下
容器-父级
ListView Builder-外部列表
SizedBox-外部列表项目
ListView-水平内部列表视图
即时通讯在垂直或水平滚动时,我的应用程序冻结并停止
它说异常暂停
我收到这个错误
Click here
我是扑朔迷离的初学者,对不起编码结构 以下是我的代码
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'dart:convert';
import 'package:cached_network_image/cached_network_image.dart';
class Categories extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return CategoriesState();
}
}
class CategoriesState extends State<Categories>
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
List categories = new List();
bool showProgress = true;
@override
void initState() {
super.initState();
getJson();
}
@override
Widget build(BuildContext context) {
return Container(
child: showProgress == false
? new ListView.builder(
itemCount: categories.length,
itemBuilder: (BuildContext context, int categoryIndex) {
return SizedBox(
width: MediaQuery.of(context).size.width,
height: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: EdgeInsets.all(16),
child: Text(
categories[categoryIndex]["category"],
style: TextStyle(fontFamily: "Ubuntu", fontSize: 18),
),
),
Flexible(
child: new ListView.builder(
scrollDirection: Axis.horizontal,
itemCount:
categories[categoryIndex]["subcategory"].length,
itemBuilder: (BuildContext context, int index) {
return Stack(
children: <Widget>[
Center(
child: Text(categories[categoryIndex]
["subcategory"][index]["name"])),
Image(
height:100,
width:200,
image:new CachedNetworkImageProvider(categories[categoryIndex]
["subcategory"][index]["url"])
)
],
);
}),
)
],
),
);
})
: Center(
child: CircularProgressIndicator(),
),
);
}
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
void getJson() async {
final data =
await DefaultAssetBundle.of(context).loadString('assets/data.json');
var decoded = json.decode(data);
print(decoded);
setState(() {
showProgress = false;
categories = decoded as List;
});
}
}