gpt4 book ai didi

android - 如何在bottomNavigationBar顶部显示FloatingActionButton

转载 作者:行者123 更新时间:2023-12-03 04:01:26 25 4
gpt4 key购买 nike

我想在FloatingActionButton上显示BottomNavigationBar。我为FloatingActionButtonBottomNavigationBar创建了两个单独的小部件。但是当我替换屏幕上的FloatingActionButton时,它将在BottomNavigationBar后面

please see below image



enter image description here

请找到以下代码段。我想在 FloatingActionButton上方显示 bottomNavigationBar

main_screen.dart
  @override
Widget build(BuildContext context) {
return new Scaffold(
appBar: Header().build(context),
backgroundColor: Colors.white,
body: Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavBar(this._onItemTapped, _selectedIndex)],
);
}

bottomNavBar.dart
class BottomNavBar extends StatefulWidget {
final Function onItemTapped;
final int selectedIndex;

BottomNavBar(this.onItemTapped,this.selectedIndex);

@override
State<StatefulWidget> createState() {
return _BottomNavBar();
}
}

class _BottomNavBar extends State<BottomNavBar> {
@override
Widget build(BuildContext context) {
return BottomNavigationBar(
currentIndex: widget.selectedIndex,
items: navigationItems,
onTap: (index) {
widget.onItemTapped(index);
},
fixedColor: Theme.of(context).primaryIconTheme.color,
iconSize: 24.0,
type: BottomNavigationBarType.fixed);
}

}

floatActionButton.dart
FloatingActionButtonStack布局内,并且在 BottomNavigationBarItem内被调用(这是另一个屏幕)
Widget build(BuildContext context) {
return SizedBox(
width: expandedSize,
height: expandedSize,
child: AnimatedBuilder(
animation: _animationController,
builder: (BuildContext context, Widget child) {
return Stack(
alignment: Alignment.center,
children: <Widget>[
_buildExpandedBackground(),
_buildFabCore()
],
);
},
),
);
}

Widget _buildFabCore() {
double scaleFactor = 2 * (_animationController.value - 0.5).abs();
return FloatingActionButton(
onPressed: _onFabTap,
child: Transform(
alignment: Alignment.center,
transform: Matrix4.identity()..scale(1.0, scaleFactor),
child: Icon(
_animationController.value > 0.5 ? Icons.close : Icons.filter_list,
color: Colors.white,
size: 26),
),
backgroundColor: _colorAnimation.value,
);
}

最佳答案

Scaffold内部,将属性floatingActionButtonLocation添加到FloatingActionButtonLocation.endFloat,FloatingActionButtonLocation.endDocked中。
endFloat将在底部导航上方添加FAB。尝试同时应用。

编辑(例如):

import 'package:flutter/material.dart';

void main() {
runApp(MaterialApp(
title: 'Flutter GTranslate Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyApp(),
));
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
"https://images.pexels.com/photos/1054289/pexels-photo-1054289.jpeg",
),
fit: BoxFit.cover,
),
),
),
Center(
child: CircularProgressIndicator(backgroundColor: Colors.red,),
),
],
),
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 4.0,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
onTap: () {},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.person),
Text("Profile"),
],
),
),
InkWell(
onTap: () {},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.favorite),
Text("Favorite"),
],
),
),
InkWell(
onTap: () {},
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.settings),
Text("Settings"),
],
),
),
SizedBox(width: 6.0),
],
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endDocked,
floatingActionButton: FloatingActionButton(onPressed: () {}, child: Icon(Icons.menu),),
);
}
}

关于android - 如何在bottomNavigationBar顶部显示FloatingActionButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56153266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com