LoginSignup
17
10

More than 5 years have passed since last update.

Floating Button を変形してみる

Posted at

Flutterでいろいろなフローティングボタンを生成してみます。

よく見るフローティングボタン

よく見るこんなやつ

スクリーンショット 2018-07-23 21.21.37.png

右下に浮いているフローティングボタンの実装はこんな感じです。

      floatingActionButton: FloatingActionButton(
        onPressed: () {
        },
        child: new Icon(Icons.add),
      ),

こんな実装を Scaffold の中に書きます。

文字入れてみる

スクリーンショット 2018-07-23 21.24.22.png

今度はこんな感じで文字をいれて浮かせたボタンをセンタリングします。

実装はこんな感じ


      floatingActionButton: FloatingActionButton.extended(
        onPressed: () {
        },
        icon: new Icon(Icons.add),
        label: Text("写真を共有する"),
      ),

これも同じく `Scaffold の中に書きます。

メニューの下を下にくっつけてみる

スクリーンショット 2018-07-23 21.41.00.png

次は下にAPP barをひっつけてみます。
最近よくみるマテリアルデザインですね。

    floatingActionButton: FloatingActionButton(
        onPressed: () {
        },
        child: new Icon(Icons.add),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
          hasNotch: false,
          child: new Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              IconButton(
                icon: Icon(Icons.menu),
                onPressed: () {},
              ),
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {},
              )
            ],
          ),
      ),

もちろん文字をいれたフローティングボタンもできます。

スクリーンショット 2018-07-23 21.44.02.png


     floatingActionButton: FloatingActionButton.extended(
        onPressed: () {
        },
        icon: new Icon(Icons.add),
        label: Text("写真を共有する"),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
          hasNotch: false,
          child: new Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              IconButton(
                icon: Icon(Icons.menu),
                onPressed: () {},
              ),
              IconButton(
                icon: Icon(Icons.search),
                onPressed: () {},
              )
            ],
          ),
      ),

Speed dialを実装する

speeduial.gif

↑こんなやつです。

これは一から自作するより便利なプラグインがあるのでそれを使いましょう。

実装はこんな感じ


    floatingActionButton: SpeedDial(
      animatedIcon: AnimatedIcons.menu_close,
      animatedIconTheme: IconThemeData(size: 22.0),
      curve: Curves.bounceIn,
      children: [
        SpeedDialChild(
            child: Icon(Icons.create),
            backgroundColor: Colors.blue,
            label: "グループを作成する",
            onTap: () {
              Navigator.pushNamed(context, "/create_group");
            },
            labelStyle: TextStyle(fontWeight: FontWeight.w500)),
        SpeedDialChild(
            child: Icon(Icons.person_add),
            backgroundColor: Colors.green,
            label: "グループに参加する",
            onTap: () {
              Navigator.pushNamed(context, "/search_group");
            },
            labelStyle: TextStyle(fontWeight: FontWeight.w500)),
      ],
    ),

総括

こんなレイアウトもFlutterでは簡単に作れてしまうところはほんと素晴らしいなと思います。

Flutterに関しての呟きをたくさんしているのでよろしければフォローお願いします。↓
Twitter:https://twitter.com/yshogo87

また、以前Flutterを触ってみて得た知見を記事にしたのでこちらも一緒にお願いします。
「Flutterを触りまくったので知見を公開する」
https://note.mu/shogoyamada/n/n043aa4b7750e

17
10
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
17
10