| // Copyright 2014 The Flutter Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // Template: dev/snippets/config/templates/stateless_widget_material.tmpl |
| // |
| // Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring |
| // of samples, and may be ignored if you are just exploring the sample. |
| |
| // Flutter code sample for StandardFabLocation |
| // |
| //*************************************************************************** |
| //* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) |
| |
| // 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]. |
| |
| //* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) |
| //*************************************************************************** |
| |
| import 'package:flutter/material.dart'; |
| |
| void main() => runApp(const MyApp()); |
| |
| /// This is the main application widget. |
| class MyApp extends StatelessWidget { |
| const MyApp({Key? key}) : super(key: key); |
| |
| static const String _title = 'Flutter Code Sample'; |
| |
| @override |
| Widget build(BuildContext context) { |
| return const MaterialApp( |
| title: _title, |
| home: MyStatelessWidget(), |
| ); |
| } |
| } |
| |
| //***************************************************************************** |
| //* ▼▼▼▼▼▼▼▼ code-preamble ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) |
| |
| class AlmostEndFloatFabLocation extends StandardFabLocation |
| with FabEndOffsetX, FabFloatOffsetY { |
| @override |
| double getOffsetX( |
| ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) { |
| final double directionalAdjustment = |
| scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0; |
| return super.getOffsetX(scaffoldGeometry, adjustment) + |
| directionalAdjustment; |
| } |
| } |
| |
| //* ▲▲▲▲▲▲▲▲ code-preamble ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) |
| //***************************************************************************** |
| |
| /// This is the stateless widget that the main application instantiates. |
| class MyStatelessWidget extends StatelessWidget { |
| const MyStatelessWidget({Key? key}) : super(key: key); |
| |
| @override |
| //******************************************************************** |
| //* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker) |
| |
| Widget build(BuildContext context) { |
| return Scaffold( |
| appBar: AppBar( |
| title: const Text('Home page'), |
| ), |
| floatingActionButton: FloatingActionButton( |
| onPressed: () { |
| print('FAB pressed.'); |
| }, |
| tooltip: 'Increment', |
| child: const Icon(Icons.add), |
| ), |
| floatingActionButtonLocation: AlmostEndFloatFabLocation(), |
| ); |
| } |
| |
| //* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker) |
| //******************************************************************** |
| |
| } |