我们如何在Flutter中更改Appbar背景颜色 [英] How can we change appbar background color in flutter

查看:1304
本文介绍了我们如何在Flutter中更改Appbar背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为应用设置通用主题,因此我需要将 appbar 颜色更改为指示十六进制代码#0f0a1a

I am trying to set a common theme for app so I need to change appbar color as a color that indicates hex code #0f0a1a

const MaterialColor toolbarColor = const MaterialColor(
    0xFF151026, const <int, Color>{0: const Color(0xFF151026)});

我尝试用这段代码制作自定义颜色,但失败了。
如何从 themeData 执行此操作?

I try this piece of code to make a custom color but fails. How can I do this from themeData?

推荐答案

像这样声明您的颜色

const PrimaryColor = const Color(0xFF151026);

,然后在 MaterialApp 级别(将更改整个应用程序中的AppBar颜色)更改 PrimaryColor

and then in the MaterialApp level( will change the AppBar Color in the whole app ) change the PrimaryColor

return MaterialApp(
  title: 'Flutter Demo',
  theme: ThemeData(
   primaryColor: PrimaryColor,
   ),
  home: MyApp(),
);

,如果要在Widget级别进行更改,只需更改 backgroundColor

and if you want to change it in the Widget level just change the backgroundColor

  appBar: AppBar(
    backgroundColor: PrimaryColor,
  ),

这篇关于我们如何在Flutter中更改Appbar背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆