dart FLutter、AppBar行距和活动边距

2ic8powd  于 2023-05-11  发布在  Flutter
关注(0)|答案(3)|浏览(286)

我如何修改领先和行动与IconButton边距/位置在appbar?什么是leading和IconButton的默认边距我可以只pust leading和title中的action with row,但我想要更干净的代码,所以我尝试使用leading:title:actions:,但leading & actions不在body中的内容行中,body有margin:24左右我很难从一开始就使用leading:title:actions:在flutter中编写代码
我的意思是使引导和动作与身体一致

这是我的appbar代码

  1. appBar: AppBar(
  2. iconTheme: IconThemeData(color: Colors.black),
  3. backgroundColor: Colors.white,
  4. elevation: 1,
  5. titleSpacing: 0,
  6. automaticallyImplyLeading: false,
  7. leading: IconButton(
  8. onPressed: () {},
  9. icon: Icon(Icons.chevron_left),
  10. ),
  11. title: Text(
  12. 'City Guide',
  13. style: Constants.textAppBar3,
  14. ),
  15. actions: [
  16. IconButton(
  17. onPressed: () {},
  18. icon: Image.asset(
  19. 'assets/images/icon/icon_search.png',
  20. width: 24,
  21. height: 24,
  22. ),
  23. ),
  24. IconButton(
  25. onPressed: () {},
  26. icon: Image.asset(
  27. 'assets/images/icon/icon_save.png',
  28. width: 24,
  29. height: 24,
  30. ),
  31. ),
  32. IconButton(
  33. onPressed: () {},
  34. icon: Image.asset(
  35. 'assets/images/icon/icon_ticket.png',
  36. width: 24,
  37. height: 24,
  38. ),
  39. ),
  40. ],
  41. ),
qhhrdooz

qhhrdooz1#

IconButton具有图标的大小(默认值为24),并具有**padding(constrains-min)**本身以创建手势空间。按钮的大小是48,这意味着图标按钮的填充是12,你的身体填充是24,所以我们需要更多的12,尝试用Paddingleft: 12 Package 你的领导

示例x1c 0d1xx 1c 1d 1x

xfyts7mz

xfyts7mz2#

试试这个

  1. import 'package:flutter/material.dart';
  2. void main() {
  3. runApp(const MyApp());
  4. }
  5. class MyApp extends StatelessWidget {
  6. const MyApp({Key? key}) : super(key: key);
  7. // This widget is the root of your application.
  8. @override
  9. Widget build(BuildContext context) {
  10. return MaterialApp(
  11. title: 'Flutter Demo',
  12. debugShowCheckedModeBanner: false,
  13. theme: ThemeData(
  14. primarySwatch: Colors.blue,
  15. ),
  16. home: const MyHomePage(title: 'Flutter Demo Home Page'),
  17. );
  18. }
  19. }
  20. class MyHomePage extends StatefulWidget {
  21. const MyHomePage({Key? key, required this.title}) : super(key: key);
  22. final String title;
  23. @override
  24. State<MyHomePage> createState() => _MyHomePageState();
  25. }
  26. class _MyHomePageState extends State<MyHomePage> {
  27. int _counter = 0;
  28. void _incrementCounter() {
  29. setState(() {
  30. _counter++;
  31. });
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return Scaffold(
  36. appBar: AppBar(
  37. iconTheme: const IconThemeData(color: Colors.black),
  38. backgroundColor: Colors.white,
  39. elevation: 1,
  40. titleSpacing: 0,
  41. leading: IconButton(
  42. onPressed: () {},
  43. icon: const Icon(Icons.chevron_left),
  44. ),
  45. title: const Text(
  46. 'City Guide',
  47. ),
  48. actions: [
  49. IconButton(
  50. onPressed: () {},
  51. icon: const Icon(
  52. Icons.favorite,
  53. color: Colors.pink,
  54. size: 24.0,
  55. semanticLabel: 'Text to announce in accessibility modes',
  56. ),
  57. ),
  58. IconButton(
  59. onPressed: () {},
  60. icon: const Icon(
  61. Icons.local_activity,
  62. color: Colors.black,
  63. size: 24.0,
  64. semanticLabel: 'Text to announce in accessibility modes',
  65. ),
  66. ),
  67. Container(
  68. margin: const EdgeInsets.only(right: 15),
  69. child: IconButton(
  70. onPressed: () {},
  71. icon: const Icon(
  72. Icons.radar,
  73. color: Colors.black,
  74. size: 24.0,
  75. semanticLabel: 'Text to announce in accessibility modes',
  76. ),
  77. ),
  78. ),
  79. ],
  80. ),
  81. body: Container(
  82. margin: const EdgeInsets.only(left: 24, right: 24),
  83. color: Colors.amber,
  84. child: Center(
  85. child: Column(
  86. mainAxisAlignment: MainAxisAlignment.center,
  87. children: <Widget>[
  88. const Text(
  89. 'You have pushed the button this many times:',
  90. ),
  91. Text(
  92. '$_counter',
  93. style: Theme.of(context).textTheme.headline4,
  94. ),
  95. ],
  96. ),
  97. ),
  98. ),
  99. floatingActionButton: FloatingActionButton(
  100. onPressed: _incrementCounter,
  101. tooltip: 'Increment',
  102. child: const Icon(Icons.add),
  103. ), // This trailing comma makes auto-formatting nicer for build methods.
  104. );
  105. }
  106. }

展开查看全部
k75qkfdt

k75qkfdt3#

问题是IconButton小部件中的内置填充。在IconButton上使用这个。

  1. IconButton(
  2. padding: EdgeInsets.zero,
  3. constraints: BoxConstraints(),
  4. )

如果需要更多的填充,可以根据需要修改EdgeInsets。

相关问题