blob: 2cb8105090a1b40204df7faa6ac668e2a669234c [file] [log] [blame]
// 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.
// Flutter code sample for [StandardFabLocation].
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatelessWidget(),
);
}
}
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;
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({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(),
);
}
}