[Flutter]LinearProgressIndicator内にテキストを表示するには?

Flutter

どうも、ちょげ(@chogetarou)です。

LinearProgressIndicator内にテキストを表示する方法を紹介します。

スポンサーリンク

方法

プログラマー, プログラミング, コード, 仕事, コンピューター

LinearProgressindicator内にテキストを表示するには、Stackウェジェットを使います。

まず、Stackの引数「children」のリストにLinearProgressIndicatorを追加します。

そして、LinearProgressIndicatorの後にTextを追加します。

Stack(
  children: [
    LinearProgressIndicator(),
    Text('テキスト'),
  ],
),

Stackを使えば、LinearProgressIndicator内にテキストを表示することが出来ます。

テキストの位置を変えたい場合は、PositionedウェジェットやAlignウェジェットなどを使います。

使用例

以下は、使用例です。

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SizedBox(
          height: 20,
          child: Stack(
            children: [
              Align(
                child: SizedBox(
                  width: 300,
                  height: 20,
                  child: LinearProgressIndicator(
                    value: 0.75,
                  ),
                ),
                alignment: Alignment.center,
              ),
              Align(
                alignment: Alignment.topCenter,
                child: Text(
                  'Loading....',
                  style: TextStyle(color: Colors.white),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }

コメント

タイトルとURLをコピーしました