0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flutter】グラデーションの使用方法

Posted at

概要

Flutterでグラデーションを使用する方法

Containerにグラデーションをかける

「Container」ウィジェットのBoxDecorationで設定する

class BodyGradientScreen extends StatelessWidget {
  const BodyGradientScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: double.infinity,
      width: double.infinity,
      decoration: const BoxDecoration(
          gradient: LinearGradient(
        begin: FractionalOffset.topCenter,
        end: FractionalOffset.bottomCenter,
        colors: [
          Color(0xff6DD5FA),
          Color(0xff2980B9),
        ],
        stops: [
          0,
          1,
        ],
      )),
    );
  }
}
グラデーション1

stopsの値を変えるとグラデーションの開始位置や終了位置を変更することができる

class BodyGradientScreen extends StatelessWidget {
  const BodyGradientScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: double.infinity,
      width: double.infinity,
      decoration: const BoxDecoration(
          gradient: LinearGradient(
        begin: FractionalOffset.topCenter,
        end: FractionalOffset.bottomCenter,
        colors: [
          Color(0xff6DD5FA),
          Color(0xff2980B9),
        ],
        stops: [
          0.2,
          0.7,
        ],
      )),
    );
  }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?