我试图为Row()小部件设置背景色,但Row本身没有背景色或 colored颜色 属性.我已经能够将一个容器的背景 colored颜色 设置为灰色,就在紫色背景文本之前,但是文本本身并没有完全填充背景,下面的间隔符也没有任何 colored颜色 .

那么,如何将Row Background设置为"HexColor(COLOR_LIGHT_GREAY)"值,使其跨越整行呢?

有什么 idea 吗?非常感谢!

enter image description here

以下是我到目前为止拥有的代码:

import 'package:flutter/material.dart';
import '../manager/ShoppingListManager.dart';
import '../model/ShoppingListModel.dart';
import '../hexColor.dart';
import '../Constants.dart';

class ShoppingListWidget extends StatelessWidget {
  final Color color = Colors.amberAccent;
  final int shoppingListIndex;

  ShoppingListWidget({this.shoppingListIndex});

  @override
  Widget build(BuildContext context) {
    ShoppingListManager slm = new ShoppingListManager();
    String shoppingListName =
        slm.myShoppingLists.shoppingLists[shoppingListIndex].name;
    int categoryCount =
        slm.myShoppingLists.shoppingLists[shoppingListIndex].categories.length;

    return Scaffold(
      appBar: AppBar(
        title: Text(shoppingListName),
        automaticallyImplyLeading: true,
      ),
      body: ListView.builder(
        itemBuilder: (context, index) {
          Category cat = slm.myShoppingLists.shoppingLists[shoppingListIndex]
              .categories[index];

          return Container(
            decoration: new BoxDecoration(
              border: new Border.all(color: Colors.grey[500]),
              color: Colors.white,
            ),
            child: new Column(
              children: <Widget>[
                getCategoryWidget(context, cat),
                getCategoryItems(context, cat),
              ],
            ),
          );
        },
        itemCount: categoryCount,
      ),
    );
  }

  // Render the category "headline" row where I want to set the background color
  // to HexColor(COLOR_LIGHT_GREY)
  Widget getCategoryWidget(BuildContext context, Category cat) {
    return new Row(
      children: <Widget>[
        new Container(height: 40.0, width: 10.0, color: HexColor(cat.color)),
        new Container(
            height: 40.0, width: 15.0, color: HexColor(COLOR_LIGHT_GREY)),
        new Container(
          child: new Text("Category", textAlign: TextAlign.start,
            style: TextStyle(
                fontFamily: 'Bold',
                fontSize: 18.0,
                color: Colors.black),
          ),
          decoration: new BoxDecoration(
            color: Colors.purple,
          ),
          height: 40.0,
        ),
        Spacer(),

        CircleAvatar(
          backgroundImage:
              new AssetImage('assets/icons/food/food_settings.png'),
          backgroundColor: HexColor(COLOR_LIGHT_GREY),
          radius: 15.0,
        ),
        new Container(height: 15.0, width: 10.0, color: Colors.transparent),
      ],
    );
  }

  // render the category items
  Widget getCategoryItems(BuildContext context, Category cat) {
    return ListView.builder(
      itemBuilder: (context, index) {
        String itemName = "Subcategory";
        return new Row(children: <Widget>[
          new Container(height: 40.0, width: 5.0, color: HexColor(cat.color)),
          new Container(height: 40.0, width: 20.0, color: Colors.white),
          new Container(
            child: new Text(itemName),
              color: Colors.white,
          ),
          Spacer()
        ]);
      },
      itemCount: cat.items.length,
      shrinkWrap: true,
      physics:
          ClampingScrollPhysics(),
    );
  }

}

推荐答案

只需用具有如下 colored颜色 属性的容器包装您的行即可:

   Container(
            color: Colors.black,
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Text('Demo', style: TextStyle(color: Colors.white),),
                )
              ],
            ),
          )

Flutter相关问答推荐

flutter:如何将字体大小设置得更大(更大)

类型flatter doctor get zsh:未找到命令:macO中flatter

如何使用Firebase Firestore来获取外部集合中的文档子集合中的文档

相同的Flutter 代码库,但Firebase登录适用于Web应用程序,但无法登录iOS应用程序

CLI数据库连接后将SHA-1密钥添加到Firebase项目

你能go 掉Flutter 小部件测试中的样板吗?

try 使用fl_Chart of Ffltter,但在导入它时遇到以下错误:Error:';TextScaler';is;t a type

Flutter卡内容未在水平列表视图中居中

播放特定持续时间Flutter 的音频

如何处理平台游戏的对象冲突?

如何修改来自合并 list 的 Android list 权限?

创建混合 TextWidget 和 TextFieldWidget

无法在 ListView (Flutter) 中限制 Card 的最大宽度

Flutter 应用程序在启动画面冻结(java.lang.RuntimeException:无法启动活动 ComponentInfo)

如何在 flutter 中使用 tabbar 作为底部导航栏?

Pub get 尚未运行

Flutter 错误:正文可能正常完成,导致返回null

主题:ThemeData() Flutter

为什么这个循环只发生一次?Flutter /dart

Android Studio 模拟器屏幕闪烁