【问题标题】:flutter, what is the right way to change appbar leading icon at app theme level?颤振,在应用主题级别更改应用栏领先图标的正确方法是什么?
【发布时间】:2021-09-13 03:10:20
【问题描述】:

flutter,在应用主题级别更改应用栏前导图标的正确方法是什么?所以我不需要在每个屏幕上进行更改?

我知道以下代码适用于特定屏幕...

AppBar(
  title: Text("Hello Appbar"),
  leading: Icon(
    Icons.arrow_back,
  ),
);

但我不想在每个屏幕上都这样做,只是在这里检查我是否可以在应用主题级别设置它,以便所有屏幕都相同...

我参考了 appbar 的 Flutter 文档,但并没有太大帮助。

【问题讨论】:

    标签: flutter flutter-theme


    【解决方案1】:

    你可以这样做

    import 'package:flutter/material.dart';
    
    AppBar MyAppBar({Widget title, Widget leading}) {
      return AppBar(
        title: title,
        leading: leading,
      );
    }
    

    【讨论】:

      【解决方案2】:

      使用 IconButton 更改前导图标。

       AppBar(
        title: Text("Hello Appbar"),
        leading: IconButton(
         onPressed: () {},
         icon: Icon(Icons.arrow_back)
        ),
      );
      

      【讨论】:

        猜你喜欢
        • 2019-06-07
        • 2019-02-19
        • 2020-03-28
        • 2019-02-20
        • 2021-05-02
        • 2020-11-23
        • 2019-03-14
        • 2021-06-23
        • 1970-01-01
        相关资源
        最近更新 更多