Closed tiantianaixuexi closed 4 years ago
`// Future<List> loadAssets(BuildContext context) async {
List<AssetEntity> entity = await PhotoPicker.pickAsset( context:context, pickType: PickType.onlyImage, loadingDelegate: this, badgeDelegate: const DurationBadgeDelegate(), ); for(int i =0;i<entity.length;i++){ images.add(await entity[i].file); } return images;
}
@override Widget build(BuildContext context) { return Scaffold( body: FutureBuilder( future: loadAssets(context), builder: (BuildContext context, AsyncSnapshot<List> snapshot) { if (snapshot.hasData) { return Container( child: Column( children: [ Text( "发帖子", style: TextStyle(fontSize: ScreenUtil().getSp(30)), ), TextField( maxLines: 10, controller: widget.postContentController, decoration: const InputDecoration( border: InputBorder.none, //去掉输入框的下滑线 hintText: "请输入要发送的文本~,不能为空", fillColor: Color(0XFFFFF8F4), filled: true, ), onChanged: (str) { PostProperty_Future().contentString = str; }, ), Expanded( child: buildGridView(snapshot.data), ), Divider( color: Colors.red, ), PostDownPage() ], ), ); } else { return Text('fuck'); } })); }`
See example. Selecting images is usually triggered within a button clicked. It should not be used with FutureBuilder
`// Future<List> loadAssets(BuildContext context) async {
}
@override Widget build(BuildContext context) { return Scaffold( body: FutureBuilder( future: loadAssets(context), builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
if (snapshot.hasData) {
return Container(
child: Column(
children: [
Text(
"发帖子",
style: TextStyle(fontSize: ScreenUtil().getSp(30)),
),
TextField(
maxLines: 10,
controller: widget.postContentController,
decoration: const InputDecoration(
border: InputBorder.none, //去掉输入框的下滑线
hintText: "请输入要发送的文本~,不能为空",
fillColor: Color(0XFFFFF8F4),
filled: true,
), onChanged: (str) { PostProperty_Future().contentString = str; }, ), Expanded( child: buildGridView(snapshot.data), ), Divider( color: Colors.red, ), PostDownPage() ], ), ); } else { return Text('fuck'); } })); }`