簡體   English   中英

Flutter,不能改變容器顏色

[英]Flutter, cannot change container color

我有一個屏幕,上面有一個 SafeArea 小部件,然后里面的所有東西都用容器包裹起來,並作為一個主體傳遞給 safearea。 但是當我想改變容器顏色時,它總是保持白色。

我是否錯誤地實現了這個 UI? 我怎樣才能改變這種顏色?

class _MeetingScreenState extends State<MeetingScreen> {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      left: false,
      right: false,
      child: Container(
// Container color to change
        color: Colors.black87,
        child: Material(
          child: Padding(
            padding: const EdgeInsets.all(16),
            child: Column(
              children: [
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      ActionIconButton(
                          iconState: false,
                          iconStateOn: Icons.cameraswitch_outlined,
                          iconStateOff: Icons.cameraswitch_outlined),
                      Column(
                        children: const [
                          Text('Meeting title'),
                          // TODO implement meeting time
                          Text('04:28')
                        ],
                      ),
                      ActionIconButton(
                          iconState: _switchCamera,
                          iconStateOn: Icons.volume_up_outlined,
                          iconStateOff: Icons.volume_off_outlined,
                      iconBackgroundColor: AppColors.white,
                      activeIconColor: AppColors.white,
                      inactiveColor: AppColors.whiteWithOpacity,)
                    ],
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Material也應用顏色,它在Container之一之上。

您可以移除Container並將您的顏色賦予Material小部件:

改變

Container(
  // Color to change
  color: Colors.black87,
  child: Material(
    // ...
  ),
),

Material(
  // Color to change
  color: Colors.black87,
  // ...
),

Material 小部件負責:

裁剪:如果 clipBehavior 不是 Clip.none,則 Material 會將其小部件子樹裁剪為由 shape、type 和 borderRadius 指定的形狀。 默認情況下,出於性能考慮,clipBehavior 為 Clip.none。 有關這如何影響剪裁 Ink 小部件的示例,請參閱 Ink。 Elevation:Material 通過 elevation 像素在 Z 軸上提升其 widget 子樹,並繪制適當的陰影。 墨跡效果:材質在其子項下方顯示由 InkFeatures(如 InkSplash 和 InkHighlight)實現的墨跡效果。

因此需要根據 Valentin Vignal Answer 在材料小部件中添加 colors。 我希望你明白。

Material(
  // Color to change
  color: Colors.black87,
  // ...
),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM