如何解决在flutter中实现浮动操作按钮等功能
如何通过固定在底部、列表上方并且列表在颤动中滚动来实现此功能? 提前致谢!!!
解决方法
您可以使用 FloatingActionButton.extended()
并在其中创建 Row
,然后用 Row
包裹您的 GestureDetector
以捕获 onTap
。
示例:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),));
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Floating Action Button Extended"),),floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,floatingActionButton: FloatingActionButton.extended(
onPressed: () {},backgroundColor: Colors.white,label: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,children: [
GestureDetector(
onTap: () {
print('button 1');
},child: Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 5.0),child: Icon(
Icons.verified_user,color: Colors.purple,Text(
'Me',style: TextStyle(
fontSize: 15,fontWeight: FontWeight.bold,],SizedBox(width: 30),GestureDetector(
onTap: () {
print('button 2');
},child: Icon(
Icons.qr_code,Text(
'Scan',);
}
}
结果:
,这样做就行了:
Scaffold(
extendBody: true,bottomNavigationBar: Container(
margin: EdgeInsets.only(left: MediaQuery.of(context).size.width/2 - 100,right: MediaQuery.of(context).size.width/2 - 100,bottom: 20),height: 60,decoration: BoxDecoration(
borderRadius: const BorderRadius.all(Radius.circular(10.0)),color: Color.fromRGBO(249,125,27,1),child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,children: <Widget>[
IconButton(
icon: Icon(
Icons.home,color: Colors.white,onPressed: () {},IconButton(
icon: Icon(
Icons.people_alt,
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。