簡體   English   中英

將曲線應用於現有 Animation

[英]Apply Curve to an existing Animation

項目

您好,我正在學習如何在 Flutter 中使用AnimatedList 我能夠使用SizeTransition在列表中添加和刪除元素:

代碼

Widget _buildItem(
    BuildContext context, int index, Animation<double> animation) {
  return SizeTransition(
    sizeFactor: animation,
    axis: Axis.vertical,
    child: Padding(
      padding: const EdgeInsets.all(8.0),
      child: Container(
        height: 50,
        color: Colors.orange,
        child: SizedBox(
          child: Center(
            child: Text(displayList[index].toString()),
          ),
        ),
      ),
    ),
  );
}

現在,我無法理解如何向此過渡添加自定義曲線。 這可能嗎?

好問題!

如文檔中的示例所述,您可以使用CurvedAnimation

CurvedAnimation(
  parent: animation,
  curve: Curves.ease,
  reverseCurve: Curves.easeOut,
),

reverseCurve參數是可選的。 如果沒有提供反向曲線,彎曲的 animation 將只使用兩個方向的curve
應用於您的代碼:

return SizeTransition(
  sizeFactor: CurvedAnimation(
    parent: animation,
    curve: Curves.ease,
  ),
  ...
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM