Search
 
SCRIPT & CODE EXAMPLE
 

DART

define offset for floatingActionButtonLocation flutter

import 'package:flutter/material.dart';
import 'dart:math' as math;


class HomeHeader extends StatefulWidget {
  final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
  @override
  HomeHeaderState createState() {
    return new HomeHeaderState();
  }
}

class HomeHeaderState extends State<HomeHeader> {

  static const FloatingActionButtonLocation centerDocked = _CenterDockedFloatingActionButtonLocation();

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      key: widget._scaffoldKey,
      appBar: AppBar(
        title: Text('duh'),
      ),
      floatingActionButtonLocation:centerDocked,
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add), onPressed: () {

      },),
      body: new Container()
    );
  }
}
class _CenterDockedFloatingActionButtonLocation extends _DockedFloatingActionButtonLocation {
  const _CenterDockedFloatingActionButtonLocation();

  @override
  Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
    final double fabX = (scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width) / 2.0;
    return Offset(fabX, getDockedY(scaffoldGeometry));
  }
}

abstract class _DockedFloatingActionButtonLocation extends FloatingActionButtonLocation {
  const _DockedFloatingActionButtonLocation();
  @protected
  double getDockedY(ScaffoldPrelayoutGeometry scaffoldGeometry) {
    final double contentBottom = scaffoldGeometry.contentTop;
    final double appBarHeight = scaffoldGeometry.bottomSheetSize.height;
    final double fabHeight = scaffoldGeometry.floatingActionButtonSize.height;
    final double snackBarHeight = scaffoldGeometry.snackBarSize.height;

    double fabY = contentBottom - fabHeight / 2.0;
    if (snackBarHeight > 0.0)
      fabY = math.min(fabY, contentBottom - snackBarHeight - fabHeight - kFloatingActionButtonMargin);
    if (appBarHeight > 0.0)
      fabY = math.min(fabY, contentBottom - appBarHeight - fabHeight / 2.0);

    final double maxFabY = scaffoldGeometry.scaffoldSize.height - fabHeight;
    return math.min(maxFabY, fabY);
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: convert timeofday to string flutter 
Dart :: showsnackbar deprecated 
Dart :: dart time 
Dart :: flutter vibration 
Dart :: const vs final flutter 
Dart :: scroll with mouse in flutter 
Dart :: overflow box flutter 
Dart :: dart key value pair list 
Dart :: height of sizedbox for phonescreen 
Dart :: flutter calander last date + 6 days 
Dart :: dart create hash 
Dart :: assign hex to color dart 
Dart :: get second to last item in a list dart 
Dart :: get avarae image from like flutter 
Dart :: flutter widget destructor 
Dart :: dart if else 
Dart :: how to use api key in flutter 
Dart :: change color icon tabbar flutter 
Dart :: flutter set default language 
Dart :: how to run dart code in vscode 
Dart :: flutter row vertical direction 
Dart :: check if animation complete in flutter 
Dart :: future as a parameter with async in flutter 
Dart :: dart list slice 
Dart :: const issue on new flutter version 
Dart :: rouned floating action button flutter 
Swift :: conert data to string swift 
Swift :: delete padding list swiftui 
Swift :: swift get current time 
Swift :: underline uitextfield swift rotate 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =