3
0

More than 1 year has passed since last update.

【Flutter】FloatingActionButtonのカスタマイズ位置

Posted at

はじめ

ご存知の通り、FloatingActionButtonの位置はFloatingActionButtonLocationで定義するが、static変数何個かしか用意されてなく、好きな位置調整が簡単にできない。
ここでカスタマイズ方法&ソースを簡単にまとめます。

floatingActionButtonLocation:FloatingActionButtonLocation.centerDocked,

ソース

FloatingActionButtonLocationを継承して偏移値を追加すれば、簡単にできます。

import 'package:flutter/material.dart';

class CustomizeFloatingLocation extends FloatingActionButtonLocation {
  FloatingActionButtonLocation location;
  double offsetX;
  double offsetY;
  CustomizeFloatingLocation(this.location, this.offsetX, this.offsetY);
  @override
  Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
    Offset offset = location.getOffset(scaffoldGeometry);
    return Offset(offset.dx + offsetX, offset.dy + offsetY);
  }
}

使用

floatingActionButtonLocation:CustomizeFloatingLocation(FloatingActionButtonLocation.centerDocked, -90, -30),
3
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
3
0