在另一个地方使用FloatingActionButtonLocation.centerDocked颤振

时间:2019-07-29 08:44:53

标签: flutter

默认情况下,当bottomNavigationBar中有Scaffold时,我们可以使用bottomNavigationBar小部件为FloatingActionButtonLocation.centerDocked设置此功能,

enter image description here

由于我的应用程序中没有bottomNavigationBar小部件,我无法设置功能,并且我试图制作此自定义小部件,谁可以帮助我设计此自定义小部件?

我实现了bottomNavigationBar的不是脚手架bottomNavigationBar的孩子的女巫:

body: Container(
  color: applicationBackgroundColor,
  child: Stack(children: <Widget>[
    Align(
      alignment: Alignment.bottomCenter,
      child: BottomExpandableAppBar(
        expandedHeight: 350,
        horizontalMargin: 3,
        bottomOffset: 50.0,
        controller: controller,
        attachSide: Side.Bottom,
        expandedBackColor: Theme.of(context).backgroundColor,
        expandedBody: Center(
          child: Stack(children: <Widget>[
            Text("Hello world!"),
          ]),
        ),
        bottomAppBarBody: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Row(
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[Icon(Icons.add)],
          ),
        ),
      ),
    ),
  ]),
),

1 个答案:

答案 0 :(得分:3)

enter image description here 这是您要找的吗?

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: SafeArea(
          child: MyHomePage(),
        ),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  double position = 0.0;

  @override
  void initState() {
    super.initState();
  }

  void handleXChange(double deltaX) {
    setState(() {
      position = deltaX / MediaQuery.of(context).size.width;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Text(position.toString()),
        DragArea(
          handleXChange: handleXChange,
        ),
      ],
    );
  }
}

class DragArea extends StatefulWidget {
  const DragArea({Key key, @required this.handleXChange}) : super(key: key);

  final void Function(double newX) handleXChange;

  @override
  _DragAreaState createState() => _DragAreaState();
}

class _DragAreaState extends State<DragArea> {
  double initX;

  void onPanStart(DragStartDetails details) {
    initX = details.globalPosition.dx;
  }

  void onPanUpdate(DragUpdateDetails details) {
    var x = details.globalPosition.dx;
    var deltaX = x - initX;
    widget.handleXChange(deltaX);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onPanStart: onPanStart,
      onPanUpdate: onPanUpdate,
      child: Container(
        decoration: BoxDecoration(
          border: Border.all(
            color: Colors.blueAccent,
          ),
        ),
      ),
    );
  }
}