默认情况下,当bottomNavigationBar
中有Scaffold
时,我们可以使用bottomNavigationBar
小部件为FloatingActionButtonLocation.centerDocked
设置此功能,
由于我的应用程序中没有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)],
),
),
),
),
]),
),
答案 0 :(得分:3)
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,
),
),
),
);
}
}