我正在尝试更改AppBar的背景颜色,但它无法正常工作。
根据下图选择颜色0x673AB7
时,AppBar变为灰色而不是紫色。
import "package:flutter/material.dart";
void main() {
runApp(new ControlleApp());
}
class ControlleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: "Controlle Financeiro",
home: new HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
backgroundColor: new Color(0x673AB7),
),
);
}
}
答案 0 :(得分:5)
看起来你的颜色是完全透明的。尝试将颜色更改为0xFF673AB7
答案 1 :(得分:1)
正如@Randal所说,你使用的是没有alpha值的十六进制代码。如果您没有指定它,它将是完全透明的。因此,您可以将前两个值用作alpha,将其他六个值用作RGB。
查看Color
类源代码。有如下评论:
/// Construct a color from the lower 32 bits of an [int].
///
/// The bits are interpreted as follows:
///
/// * Bits 24-31 are the alpha value.
/// * Bits 16-23 are the red value.
/// * Bits 8-15 are the green value.
/// * Bits 0-7 are the blue value.
///
/// In other words, if AA is the alpha value in hex, RR the red value in hex,
/// GG the green value in hex, and BB the blue value in hex, a color can be
/// expressed as `const Color(0xAARRGGBB)`.
///
/// For example, to get a fully opaque orange, you would use `const
/// Color(0xFFFF9000)` (`FF` for the alpha, `FF` for the red, `90` for the
/// green, and `00` for the blue).