Flutter 如何更改颤振表中特定单元格的背景颜色
在我的flatter项目中,我使用Flutter 如何更改颤振表中特定单元格的背景颜色,flutter,tablecell,Flutter,Tablecell,在我的flatter项目中,我使用tablewidget实现了一个类似于表的结构。我想更改/设置该表特定单元格的背景色 我尝试过用容器小部件包装特定单元格的文本小部件,但我得到的颜色格式不正确。它不会填充整个单元格,而是只覆盖单元格的中间部分,如下所示: 我希望整个单元格充满红色。比如: 这是我的表的代码: class SlotsManagement extends StatefulWidget { @override _SlotsManagementState createState(
table
widget实现了一个类似于表的结构。我想更改/设置该表特定单元格的背景色
我尝试过用容器
小部件包装特定单元格的文本
小部件,但我得到的颜色格式不正确。它不会填充整个单元格,而是只覆盖单元格的中间部分,如下所示:
我希望整个单元格充满红色。比如:
这是我的表的代码:
class SlotsManagement extends StatefulWidget {
@override
_SlotsManagementState createState() => _SlotsManagementState();
}
class _SlotsManagementState extends State<SlotsManagement> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: aapBarSection('Slots Management', Colors.blueAccent[700],
'Poppins-Medium', 16.0, context),
body: Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.all(10.0),
child: Table(
defaultColumnWidth: FixedColumnWidth(100.0),
border: TableBorder.all(width: 1.0, color: Colors.black),
textDirection: TextDirection.ltr,
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
// columnWidths: {0: FractionColumnWidth(.4)},
children: [
TableRow(children: [
TableCell(
child: Text(
'\*',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center,
)),
TableCell(
child: Text('Slot 1',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('Slot 2',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('Slot 3',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Monday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('1',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('A',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('B',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Tuesday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('2',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('C',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('D',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Wednesday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('3',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('E',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('F',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Thursday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('4',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Container(
color: Colors.redAccent,
child: Text('G',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))),
TableCell(
child: Text('H',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Friday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('5',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('I',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('J',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Saturday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('6',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('K',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('L',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
TableRow(children: [
TableCell(
child: Text('Sunday',
style: TextStyle(fontSize: 15),
textAlign: TextAlign.center)),
TableCell(
child: Text('7',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('M',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center)),
TableCell(
child: Text('N',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center))
]),
],
),
),
);
}
}
类SlotsManagement扩展StatefulWidget{
@凌驾
_SlotsManagementState createState()=>\u SlotsManagementState();
}
类_SlotsManagementState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:aapBarSection('Slots Management',Colors.blueAccent[700],
“Poppins中等”,16.0,上下文),
主体:容器(
宽度:MediaQuery.of(context).size.width,
保证金:所有边缘套(10.0),
孩子:桌子(
defaultColumnWidth:FixedColumnWidth(100.0),
边框:表格边框。全部(宽度:1.0,颜色:Colors.black),
textDirection:textDirection.ltr,
默认垂直对齐:TableCellVerticalAlignment.middle,
//列宽:{0:FractionColumnWidth(.4)},
儿童:[
TableRow(儿童:[
表细胞(
子:文本(
'\*',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center,
)),
表细胞(
子项:文本('Slot 1',
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子项:文本('Slot 2',
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子项:文本('Slot 3',
样式:TextStyle(字体大小:15),
textAlign:textAlign.center)
]),
TableRow(儿童:[
表细胞(
孩子:文本(‘星期一’,
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子项:文本('1',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
child:Text('A',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
child:Text('B',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center)
]),
TableRow(儿童:[
表细胞(
孩子:文本(‘星期二’,
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子:文本('2',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
child:Text('C',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
子:文本('D',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center)
]),
TableRow(儿童:[
表细胞(
孩子:文本(‘星期三’,
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子:文本('3',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
child:Text('E',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
子:文本('F',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center)
]),
TableRow(儿童:[
表细胞(
孩子:文本(‘星期四’,
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子:文本('4',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
子:容器(
颜色:Colors.redAccent,
child:Text('G',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center)),
表细胞(
child:Text('H',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center)
]),
TableRow(儿童:[
表细胞(
孩子:文本(‘星期五’,
样式:TextStyle(字体大小:15),
textAlign:textAlign.center),
表细胞(
子项:文本('5',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
child:Text('I',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center),
表细胞(
child:Text('J',
样式:TextStyle(字体大小:10),
textAlign:textAlign.center)
]),
TableRow(儿童:[
verticalAlignment: TableCellVerticalAlignment.fill,
alignment: Alignment.center,
TableCell(
verticalAlignment: TableCellVerticalAlignment.fill,
child: Container(
color: Colors.redAccent,
alignment: Alignment.center,
child: Text('G', style: TextStyle(fontSize: 10), textAlign: TextAlign.center),
),
)
class Cell extends StatelessWidget {
final String text;
final Color color;
Cell({@required this.text, @required this.color, Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return TableCell(
verticalAlignment: TableCellVerticalAlignment.fill,
child: Container(
color: color,
alignment: Alignment.center,
child: Text(text, style: TextStyle(fontSize: 10), textAlign: TextAlign.center),
),
);
}
}
Cell(text: 'G', color: Colors.redAccent),
TableCell(
verticalAlignment: TableCellVerticalAlignment.fill,
child: Container(
alignment: Alignment.center,
color: Colors.red,
child: Text('4',
style: TextStyle(fontSize: 10),
textAlign: TextAlign.center),
)),