StandardFabLocation class abstract

A base class that simplifies building FloatingActionButtonLocations when used with mixins FabTopOffsetY, FabFloatOffsetY, FabDockedOffsetY, FabStartOffsetX, FabCenterOffsetX, FabEndOffsetX, and FabMiniOffsetAdjustment.

A subclass of FloatingActionButtonLocation which implements its getOffset method using three other methods: getOffsetX, getOffsetY, and isMini.

Different mixins on this class override different methods, so that combining a set of mixins creates a floating action button location.

For example: the location FloatingActionButtonLocation.miniEndTop is based on a class that extends StandardFabLocation with mixins FabMiniOffsetAdjustment, FabEndOffsetX, and FabTopOffsetY.

You can create your own subclass of StandardFabLocation to implement a custom FloatingActionButtonLocation.

This is an example of a user-defined FloatingActionButtonLocation.

The example shows a Scaffold with an AppBar, a BottomAppBar, and a FloatingActionButton using a custom FloatingActionButtonLocation.

The new FloatingActionButtonLocation is defined by extending StandardFabLocation with two mixins, FabEndOffsetX and FabFloatOffsetY, and overriding the getOffsetX method to adjust the FAB's x-coordinate, creating a FloatingActionButtonLocation slightly different from FloatingActionButtonLocation.endFloat.

To see it in action, copy and run this code snippet on DartPad.

import 'package:material_ui/material_ui.dart';

/// Flutter code sample for [StandardFabLocation].

void main() => runApp(const StandardFabLocationExampleApp());

class StandardFabLocationExampleApp extends StatelessWidget {
  const StandardFabLocationExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: StandardFabLocationExample());
  }
}

class AlmostEndFloatFabLocation extends StandardFabLocation
    with FabEndOffsetX, FabFloatOffsetY {
  @override
  double getOffsetX(
    ScaffoldPrelayoutGeometry scaffoldGeometry,
    double adjustment,
  ) {
    final double directionalAdjustment = scaffoldGeometry.textDirection == .ltr
        ? -50.0
        : 50.0;
    return super.getOffsetX(scaffoldGeometry, adjustment) +
        directionalAdjustment;
  }
}

class StandardFabLocationExample extends StatelessWidget {
  const StandardFabLocationExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home page')),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          debugPrint('FAB pressed.');
        },
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
      floatingActionButtonLocation: AlmostEndFloatFabLocation(),
    );
  }
}
Inheritance

Constructors

StandardFabLocation()
Abstract const constructor. This constructor enables subclasses to provide const constructors so that they can be used in const expressions.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) → Offset
Places the FloatingActionButton based on the Scaffold's layout.
override
getOffsetX(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) → double
Obtains the x-offset to place the FloatingActionButton based on the Scaffold's layout.
getOffsetY(ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) → double
Obtains the y-offset to place the FloatingActionButton based on the Scaffold's layout.
isMini() → bool
A function returning whether this StandardFabLocation is optimized for mini FloatingActionButtons.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited