这里是我的代码
Widget FreshProductsShow(double pageHeight, double pageWidth) {
return Container(
height: pageHeight / 1.3,
width: pageWidth,
child: ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return Card(
child: Container(
width: pageWidth,
// height: pageHeight / 7,
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(10)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
textDirection: TextDirection.rtl,
children: [
Image.asset(
"images/peper.png",
width: pageWidth / 4,
height: pageHeight / 8,
),
Padding(
padding: EdgeInsets.only(left: pageWidth / 6.3),
child: Column(
children: [
Padding(
padding: EdgeInsets.only(
left: pageWidth / 10, top: pageHeight / 45),
child: AutoSizeText(
"peper",
style: TextStyle(
fontSize: pageHeight / 48,
fontWeight: FontWeight.bold,
color: Color(0xff54595F)),
),
),
],
),
)
],
),
alignment: Alignment.centerRight,
),
elevation: 5,
);
},
scrollDirection: Axis.vertical,
),
);
}
NotificationListener
我们可以控制每个可滚动窗口小部件的滚动位置。在这里,您的函数将转换为状态方面的函数,如果我正确地获得了逻辑,则实现了逻辑:
ScrollController
是的,如果使用仿真,如果子窗口小部件在顶部或底部。
在这里是创建自定义物理的示例代码:
import 'package:flutter/material.dart';
class CustomScrollPhysics extends ClampingScrollPhysics {
final Function outerController;
bool isMinCheck = false;
CustomScrollPhysics({required this.outerController, ScrollPhysics? parent})
: super(parent: parent);
@override
CustomScrollPhysics applyTo(ScrollPhysics? ancestor) {
return CustomScrollPhysics(
outerController: outerController,
parent: buildParent(ancestor)!,
);
}
@override
Simulation? createBallisticSimulation(
ScrollMetrics position,
double velocity,
) {
if (position.pixels >= position.maxScrollExtent && velocity >= 0.0) {
outerController(velocity, false);
} else if (position.pixels == position.minScrollExtent && isMinCheck) {
outerController(velocity, true);
} else {
isMinCheck = true;
}
return super.createBallisticSimulation(position, velocity);
}
}