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 1 year has passed since last update.

[Flutter]バナーを作る

Posted at

※すみません走り書きです。

以下のような要件のバナーを実装します。

  • 画像のアスペクト比が不定な画像を背景にする
  • バナー自体は画面幅に合わせる

実装方法

  • Cardを使って角丸を表現
  • IntrinsicHeightを使ってStack内のchildrenの高さを揃える
  • StackでMaterial(type=.transparency)を重ねて、タッチエフェクトを表示
Widget banner(
  ImageProvider image, {
  required VoidCallback onTap,
}) {
  // Cardで囲ってバナーっぽい角丸にします
  return Card(
    // IntrinsicHeightで囲むことで、Stackの中のchildrenの高さに合わせたWidgetを構築
    child: IntrinsicHeight(
      child: Stack(
        children: [
          SizedBox(
            width: double.infinity,
            child: Image(image: image, fit: BoxFit.cover),
          )
          // タッチエフェクトを表示するためにMaterialを重ねます
          Material(
            type: MaterialType.transparency,
            child: InkWell(onTap: onClick),
          ),
        ],
      ),
    ),
  );
}
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?