flutter 添加完整页面滚动能力到所有页面

2ic8powd  于 2023-03-09  发布在  Flutter
关注(0)|答案(1)|浏览(127)

我想添加垂直滚动所有页面的功能,所以我尝试在我的一个页面(称为详细信息页面)中实现,每当我添加singlechildscroll视图时,它都会给我错误,我不知道如何修复它,我尝试将扩展的小部件更改为灵活和列,但没有任何效果
我正在尝试:

class DetailsPage extends StatelessWidget {
  final String imageUrl;
  final String title;
  final String name;
  final String description;

  DetailsPage({
    required this.imageUrl,
    required this.title,
    required this.name,
    required this.description,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: SingleChildScrollView(
          child: SafeArea(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Flexible(
                  fit: FlexFit.loose,
                  child: Container(
                    height: 300.0, // set a fixed height
                    margin: EdgeInsets.all(16.0),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(16.0),
                      boxShadow: [
                        BoxShadow(
                          color: Colors.grey.withOpacity(0.5),
                          spreadRadius: 1,
                          blurRadius: 5,
                          offset: Offset(0, 3),
                        ),
                      ],
                    ),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(16.0),
                      child: Image.asset(
                        imageUrl,
                        fit: BoxFit.cover,
                        height: double.infinity,
                        width: double.infinity,
                      ),
                    ),
                  ),
                ),
                Flexible(
                  fit: FlexFit.loose,
                  child: Padding(
                    padding: const EdgeInsets.all(16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          name,
                          style: TextStyle(
                            fontSize: 24.0,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(height: 8.0),
                        Text(
                          description,
                          style: TextStyle(fontSize: 16.0),
                        ),
                        SizedBox(height: 16.0),
                        Text(
                          'Reviews',
                          style: TextStyle(
                            fontSize: 20.0,
                            fontWeight: FontWeight.bold,
                          ),
                        ),
                        SizedBox(height: 8.0),
                        Expanded(
                          child: ListView(
                            children: [
                              ReviewTileWidget('John Doe',
                                  'Great dish, highly recommended!', 4),
                              ReviewTileWidget('Jane Smith',
                                  'Not bad, but not my favorite either.', 2),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ));
  }
}
kxeu7u2r

kxeu7u2r1#

问题是在可滚动小工具(SingleChildScrollView)内使用Expanded

Expanded(
  child: ListView(
    children: [
      ReviewTileWidget('John Doe',
          'Great dish, highly recommended!', 4),
      ReviewTileWidget('Jane Smith',
          'Not bad, but not my favorite either.', 2),
    ],
  ),
),

具有列(已在父级上具有)

SizedBox(height: 8.0),
  ReviewTileWidget(
      'John Doe', 'Great dish, highly recommended!', 4),
  ReviewTileWidget('Jane Smith',
      'Not bad, but not my favorite either.', 2),

相关问题