0

这是根小部件。该小部件有一个子 BuyerPostList(),它是 ListView 类型的小部件。我删除 SingleChildScrollView() 给出了一个渲染异常。添加它后,错误不再出现,但页面仍然不可滚动。

class PostsPage extends StatelessWidget {
  final AuthService _auth = AuthService();
  @override
  Widget build(BuildContext context) {
    return StreamProvider<List<BuyerPost>>.value(
        value: BuyerDatabaseService().buyerPosts,
    child:Scaffold(
      backgroundColor: Colors.white,
      appBar: header(context,isAppTitle: true),
        body:Container(
            child: SingleChildScrollView(
              child: Column(
                children: <Widget>[
                  BuyerPostList(),
                  SizedBox(height: 100,),
                ],
              ),
            ),
        ),
      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => NewPost()),
          );
        },
        label: Text(
          'New',
          style: TextStyle(fontWeight:FontWeight.w900,color:Color.fromRGBO(0, 0, 0, 0.4),),
        ),
        icon: Icon(Icons.add,color:Color.fromRGBO(0, 0, 0, 0.4),),
        backgroundColor:Colors.white,
      ),
    ),
    );
  }
}


这是列表视图 BuyerPostList 小部件()

class BuyerPostList extends StatefulWidget {
  @override
  _BuyerPostListState createState() => _BuyerPostListState();
}

class _BuyerPostListState extends State<BuyerPostList> {
  @override
  Widget build(BuildContext context) {

    final posts = Provider.of<List<BuyerPost>>(context) ?? [];
    return ListView.builder(
      shrinkWrap: true,
      itemCount: posts.length,
      itemBuilder: (context, index) {
        return BuyerPostTile(post: posts[index]);
      },
    );
  }
}

我希望我的解释已经足够清楚了。我将如何使它可滚动?提前致谢。

4

1 回答 1

1

physics: NeverScrollableScrollPhysics(),在里面添加 ListView.builder(

代码:

@override
  Widget build(BuildContext context) {

    final posts = Provider.of<List<BuyerPost>>(context) ?? [];
    return ListView.builder(
      shrinkWrap: true,
      physics: NeverScrollableScrollPhysics(),
      itemCount: posts.length,
      itemBuilder: (context, index) {
        return BuyerPostTile(post: posts[index]);
      },
    );
  }
于 2020-07-20T11:01:37.937 回答