簡體   English   中英

flutter TweenAnimationBuilder 不工作

[英]flutter TweenAnimationBuilder is not working

我想只在用戶想要查看產品詳細信息時運行一個標簽 animation 水平一次,但有一個銷售標簽但沒有任何反應。 我查看了所有解決方案,但無法解決自己。

這是教程,我想如何移動線,這是我想移動的堆棧圖像

在此處輸入圖像描述

TweenAnimationBuilder(
                          tween: Tween<double>(
                              begin: 0.0,
                              end: MediaQuery.of(context).size.width),
                          duration: const Duration(milliseconds: 4000),
                          builder: (context, double i, _) {
                            return Stack(
                              children: [
                                Container(
                                  width: 50,
                                  height: 20,
                                  color: Colors.black,
                                  child: const Center(
                                    child: Text(
                                      "SALE",
                                      style: TextStyle(
                                          fontSize: 10,
                                          fontWeight: FontWeight.w500,
                                          color: Colors.white),
                                    ),
                                  ),
                                ),
                                  SizedBox(
                                  height: 20,
                                  width: 115,
                                  child: CustomPaint(
                                    painter: PriceTagPaint(),
                                    child: Center(
                                      child: Padding(
                                        padding: const EdgeInsets.only(
                                            right: 16.0),
                                        child: Align(
                                          alignment: Alignment.centerRight,
                                          child: Text(
                                            widget.listModel.sale!,
                                            textAlign: TextAlign.center,
                                            style: const TextStyle(
                                                fontSize: 10,
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white),
                                          ),
                                        ),
                                      ),
                                    ),
                                  ),
                                ),
                              ],
                            );
                          }),

我在哪里犯錯?

您需要使用Positioned小部件將小部件放置在Stack中。

 TweenAnimationBuilder(
  tween: Tween<double>(
      begin: 0.0, end: MediaQuery.of(context).size.width),
  duration: const Duration(milliseconds: 4000),
  builder: (context, double i, _) {
    return Stack(
      children: [
        ///.....
        Positioned(
          top: i,
          child: Container(
            width: 50,
            height: 20,
            color: Colors.black,
            child: const Center(
              child: Text(
                "SALE",
                style: TextStyle(
                    fontSize: 10,
                    fontWeight: FontWeight.w500,
                    color: Colors.white),
              ),
            ),
          ),
        ),
      ],
    );
  }),

暫無
暫無

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

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