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

FlutterのDEBUGバナーのようなバナーをお手軽に表示する

Last updated at Posted at 2020-01-08

Flutterをdebugモードで起動すると出てくる右上のアレみたいなバナーを表示するコード。割と使えそうなので備忘録に残しておく。

見た目

Simulator Screen Shot - iPhone 11 - 2020-01-08 at 16.06.15.png

###ソースコード


class WithButtonWidget extends StatelessWidget {
  const WithButtonWidget({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 56.0,
      decoration: BoxDecoration(
          color: Theme.of(context).primaryColor,
          borderRadius: BorderRadius.circular(8.0),
          boxShadow: [BoxShadow(color: Colors.grey[400], blurRadius: 3.0, spreadRadius: 0.0)]
      ),
      child: Row(
        children: <Widget>[
          Container(
            width: 70.0,
            height: 56.0,
            child: ClipRect(
              child: CustomPaint(
                painter: BannerPainter(
                  message: "with",
                  textDirection: Directionality.of(context),
                  layoutDirection: Directionality.of(context),
                  location: BannerLocation.topStart,
                  color: const Color(0xFF0099FF),
                ),
              ),
            ),
          ),
          Text("痴漢をさせない・見逃さない"),
        ],
      ),
    );
  }
}

CustomPaintのpainterにBannerPainterを使うとDEBUGバナーと同じ斜めのバナーを表示してくれる。そのままだと端っこがかっこ悪いので、ClipRectで囲って親のContainerに収まってくれるように調整する。

6
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
6
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?