我想改变FloatingActionButton
的大小。但是,下面不接受height
和width
值。
floatingActionButton: FloatingActionButton(
backgroundColor: Color(0xff33333D),
onPressed: () {},
child: Icon(Icons.camera),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
我如何调整才能做到这一点?
发布于 2021-02-21 09:56:32
FloatingActionButton尺寸在Material Design:https://material.io/components/buttons-floating-action-button中定义
您有两个大小: default和mini:
要定义迷你FloatingActionButton,只需添加mini: true
floatingActionButton: FloatingActionButton(
backgroundColor: Color(0xff33333D),
mini: true,
onPressed: () {},
child: Icon(Icons.camera),
),
现在,如果您想要其他大小,可以使用ElevatedButton
floatingActionButton: ConstrainedBox(
constraints: BoxConstraints.tightFor(width: 200, height: 200),
child: ElevatedButton(
child: Icon(Icons.camera, size: 160),
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
),
),
),
完整的源代码
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: HomePage(),
),
);
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(),
floatingActionButton: ConstrainedBox(
constraints: BoxConstraints.tightFor(width: 200, height: 200),
child: ElevatedButton(
child: Icon(Icons.camera, size: 160),
onPressed: () {},
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
shape: CircularNotchedRectangle(),
notchMargin: 4.0,
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.menu),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
],
),
),
);
}
}
您可以在此处找到定义圆形按钮的其他方法:https://www.kindacode.com/article/how-to-make-circular-buttons-in-flutter/
https://stackoverflow.com/questions/66298315
复制相似问题