7
5

More than 5 years have passed since last update.

FlutterでCircleAvatarをタップできるようにする

Last updated at Posted at 2018-10-15

Flutterにはアバターなどを表示するときに円形にクリップしてくれるCircleAvatarという便利ウィジェットがあります。
しかしこのウィジェットはonTapイベントに対応しておらず、アバタータップしたらなにかするような挙動を実装できません。
ついでにアバタータップしたらリップルエフェクトも欲しいですよね。

Stackでウィジェットを重ねることでこれを実現することができます。
こんな感じです。

Stack(
  children: <Widget>[
    CircleAvatar(
      backgroundImage: AssetImage('assets/comp.jpg'),
      radius: 60.0,
    ),
    RawMaterialButton(
      onPressed: () {},
      child: Container(
        width: 120.0, // CircleAvatarのradiusの2倍
        height: 120.0,
      ),
      shape: new CircleBorder(),
      elevation: 0.0,
    ),
  ],
)

7
5
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
7
5