在我的界面中,我有一排這樣的容器
.
這個想法是,當我將手指放在這些容器上時,我手指下的那個會變大(還有其他變化,但這不是重點)。
當我用“onTap”點擊容器時,我知道如何使用GestureDetector它并讓它變大。但是,如果您按住手指并將其拖動到另一個容器,則不會發生任何變化。理想情況下,我希望能夠檢測到用戶何時通過手指懸停在觸摸螢屏上的容器。
感謝有人可以提供建議。先感謝您!
uj5u.com熱心網友回復:
您可以onVerticalDragUpdate使用GestureDetector.
class DraUILien extends StatefulWidget {
const DraUILien({super.key});
@override
State<DraUILien> createState() => _DraUILienState();
}
class _DraUILienState extends State<DraUILien> {
int? activeIndex;
final double containerWidth = 30;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: GestureDetector(
onVerticalDragUpdate: (details) {
activeIndex =
details.localPosition.dx ~/ (containerWidth 16); //16 padding
setState(() {});
},
child: SizedBox(
height: 200,
child: Row(
children: List.generate(
10,
(index) => Padding(
padding: const EdgeInsets.all(8.0),
child: AnimatedContainer(
duration: Duration(milliseconds: 300),
color: index == activeIndex ? Colors.blue : Colors.grey,
width: containerWidth,
height: index == activeIndex ? 200 : 100,
),
),
),
),
),
)),
);
}
}
使用邏輯進行更多自定義。如果您需要 onTap 功能,請嘗試包括 onPanDown
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/512880.html
標籤:扑镖颤振布局颤动动画手势
