dart FLutter、AppBar行距和活动边距

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

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

这是我的appbar代码

appBar: AppBar(
    iconTheme: IconThemeData(color: Colors.black),
    backgroundColor: Colors.white,
    elevation: 1,
    titleSpacing: 0,
    automaticallyImplyLeading: false,
    leading: IconButton(
      onPressed: () {},
      icon: Icon(Icons.chevron_left),
    ),
    title: Text(
      'City Guide',
      style: Constants.textAppBar3,
    ),
    actions: [
      IconButton(
        onPressed: () {},
        icon: Image.asset(
          'assets/images/icon/icon_search.png',
          width: 24,
          height: 24,
        ),
      ),
      IconButton(
        onPressed: () {},
        icon: Image.asset(
          'assets/images/icon/icon_save.png',
          width: 24,
          height: 24,
        ),
      ),
      IconButton(
        onPressed: () {},
        icon: Image.asset(
          'assets/images/icon/icon_ticket.png',
          width: 24,
          height: 24,
        ),
      ),
    ],
  ),
qhhrdooz

qhhrdooz1#

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

示例x1c 0d1xx 1c 1d 1x

xfyts7mz

xfyts7mz2#

试试这个

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: const IconThemeData(color: Colors.black),
        backgroundColor: Colors.white,
        elevation: 1,
        titleSpacing: 0,
        leading: IconButton(
          onPressed: () {},
          icon: const Icon(Icons.chevron_left),
        ),
        title: const Text(
          'City Guide',
        ),
        actions: [
          IconButton(
            onPressed: () {},
            icon: const Icon(
              Icons.favorite,
              color: Colors.pink,
              size: 24.0,
              semanticLabel: 'Text to announce in accessibility modes',
            ),
          ),
          IconButton(
            onPressed: () {},
            icon: const Icon(
              Icons.local_activity,
              color: Colors.black,
              size: 24.0,
              semanticLabel: 'Text to announce in accessibility modes',
            ),
          ),
          Container(
            margin: const EdgeInsets.only(right: 15),
            child: IconButton(
              onPressed: () {},
              icon: const Icon(
                Icons.radar,
                color: Colors.black,
                size: 24.0,
                semanticLabel: 'Text to announce in accessibility modes',
              ),
            ),
          ),
        ],
      ),
      body: Container(
        margin: const EdgeInsets.only(left: 24, right: 24),
        color: Colors.amber,
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

k75qkfdt

k75qkfdt3#

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

IconButton(
    padding: EdgeInsets.zero,
    constraints: BoxConstraints(),
)

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

相关问题