如何去除flutter中滚动页面时的Bounceing效果

问题描述 投票:0回答:1

在flutter中,当使用SingleChildScrollView和使用物理AlwaysScrollableScrollPhysics时,我使用3.0.6 dart sdk,而不是默认情况下得到弹跳效果如何删除它。可以通过NeverScrollableScrollPhysics,但我在singleChildScrollView上使用刷新指示器,所以我不能使用这个,现在我怎样才能消除这个弹跳效果。


 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: RefreshIndicator(
        onRefresh: () async {
          await Future.delayed(Duration(milliseconds: 1500));
          call_dashboard();
        },
        child: SingleChildScrollView(
          physics: AlwaysScrollableScrollPhysics(),
          child: GetBuilder<DashBoardController>(
            builder: (dashBoardController) {
              if (dashBoardController.DashBoardLoading.value) {
                return Center(child: CircularProgressIndicator(
                  color: primary,
                ));
              }
              return Column(
                children: [
                  Container(
                    padding: const EdgeInsets.all(12.0),
                    color: primary6,
                    // color: primary6,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          margin: EdgeInsets.only(left: 10),
                          decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              border: Border.fromBorderSide(
                                  BorderSide(width: 2.5, 
                                 color:Colors.white))),
                          child: CircleAvatar(
                            radius: 30,
                            backgroundColor: Colors.white,
                            child: ClipOval(
                              child: Image.network(
                                dashBoardController.DashBoardData['data'][0]['image'].toString(),
                                width: 60, // Adjust the width and height as needed
                                height: 60,
                                fit: BoxFit.cover,
                                errorBuilder: (context, error, stackTrace) {
                                  return Image.asset(
                                    'assets/images/errorImage.png', // Default image path
                                    width: 60,
                                    height: 60,
                                    fit: BoxFit.cover,
                                  );
                                },
                              ),
                            ),
                          )

                        ),
                        sizebox_width_7,
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: [
                            Text(
                                dashBoardController.DashBoardData['data'][0]['name'].toString(),
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.w800,
                                  fontSize: 16,
                                  letterSpacing: 0.25),
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                Icon(
                                  Icons.phone,
                                  color: Colors.white,
                                  size: 18,
                                ),
                                sizebox_width_5,
                                Text(
                                  dashBoardController.DashBoardData['data'][0]['mobile'].toString(),
                                  style: TextStyle(
                                      letterSpacing: 0.25,
                                      fontSize: 14,
                                      color: Colors.white),
                                )
                              ],
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: [
                                Icon(
                                  Icons.email,
                                  color: Colors.white,
                                  size: 18,
                                ),
                                sizebox_width_5,
                                Text(
                                  dashBoardController.DashBoardData['data'][0]['email'].toString(),
                                  style: TextStyle(
                                      letterSpacing: 0.25,
                                      fontSize: 14,
                                      color: Colors.white),
                                )
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                  sizebox_height_20,
                
                ],
              );
            }
          ),
        ),
      ),
    );
  }
}
flutter scrollview pull-to-refresh singlechildscrollview
1个回答
0
投票

您需要将AlwaysScrollableScrollPhysics()替换为ClampingScrollPhysics()

代码:

SingleChildScrollView( 
   physics: ClampingScrollPhysics()
   ....
© www.soinside.com 2019 - 2024. All rights reserved.