1
1

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 5 years have passed since last update.

FlutterのAppBarにCircleAvatarを設置してタップ遷移してみた。

Posted at

大晦日ですね。皆様本年は良い年でしたでしょうか?
今RIZINを見ながらカキカキしています。
よくあるやつだと思うんですけど、CircleAvatarにtapイベントってどうやるんだ?となったのでメモがてら記載します。
こんなときはStackを使うのです!ウィジェットの上にボタンウィジェットを重ねてタップできるようにします。
例ではalignmentとPaddingで位置調整をしています。ここはセンスで。

main.dart
appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text('サンプル',
            style: TextStyle(
              fontSize: 20,
              color: Colors.black,
              fontWeight: FontWeight.bold,
            )),
        actions: <Widget>[
          Padding(
            padding: EdgeInsets.only(right: 10.0),
            // タップイベントを効かせるためにStackで包んでCircleAvatarとボタンウィジェットを重ねる
            child: Stack(
              alignment: Alignment.centerRight,
              children: <Widget>[
                CircleAvatar(
                  radius: 20,
                  child: ClipOval(
                    child: Image.network(
                      "https://i.pravatar.cc",
                    ),
                  ),
                  backgroundColor: AppColor.mainColor,
                ),
                Positioned(
                  right: 0.0,
                  width: 40.0,
                  height: 40.0,
                  child: RawMaterialButton(
                    onPressed: () {
                      Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => MyPageScreen(title: 'マイページ')));
                    },
                    shape: CircleBorder(),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),

皆さんにとって来年も良い年でありますように。
でわ!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?