簡體   English   中英

如何像這張圖片那樣在 flutter 中創建堆疊條/進度條

[英]how to create stacked bar/progress bar in flutter like this image

我要展示類似於堆積條

我不知道這種可視化的名稱。

現在,我這里有 3 個數據(總和,.net,取消)

右邊顯示的是取消號,左邊顯示的是堆積條里面的.net號

有了這個欄,用戶將立即通過 .net + 取消知道總數)

有沒有什么 package 可以幫我顯示這個欄

這是您想要的小部件生成器。 也許 MediaQuery 是一個糟糕的選擇。 但您可以使用任何其他尺寸選項。

  Widget _buildProgress(BuildContext context, int progress, int limit) {
    return SizedBox(
      height: 30,
      width: double.infinity,
      child: Stack(
        children: <Widget>[
          Positioned.fill(
            child: Container(
              decoration: const BoxDecoration(
                color: Color(0xFF038918),
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              alignment: Alignment.centerRight,
              padding: const EdgeInsets.only(right: 20),
              child: Text(
                '$limit',
                style: const TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          ),
          Container(
            width: MediaQuery.of(context).size.width / limit * progress,
            decoration: const BoxDecoration(
              color: Color(0xFFe40808),
              borderRadius: BorderRadius.all(Radius.circular(10)),
            ),
            alignment: Alignment.center,
            child: Text(
              '$progress',
              style: const TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
        ],
      ),
    );
  }

最終結果看起來像這樣

暫無
暫無

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

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