I have a StatefulWidget State class in flutter.
I have declared some static const Color member variables. When I try to use these Colors, they are not being drawn. When I take the same Color ctor, and inline it where the static member variables were used, it works.
Am I missing something about member variable initialization in dart?
Observe the local variable color in the build method. If the ternary operator uses the inline ctor color, it works. If it uses the static member var DARK_COLOR....nothing draws.
import 'package:flutter/material.dart';
import 'chess.dart' as chesslib;
class ChessBoard extends StatefulWidget {
@override
_ChessBoardState createState() => _ChessBoardState();
}
class _ChessBoardState extends State<ChessBoard> {
Color LIGHT_COLOR = Color(0xffeeeebb);
Color LIGHT_COLOR_SELECTED = Color(0xffaaaaaa);
Color DARK_COLOR = Color(0xffffffff);
Color DARK_COLOR_SELECTED = Color(0xff119911);
chesslib.Chess _chess;
@override
void initState() {
super.initState();
_chess = new chesslib.Chess();
}
@override
Widget build(BuildContext context) {
Widget result;
result = GridView.count(
crossAxisCount: 8,
children: List.generate(64, (index) {
int row = index ~/ 8;
int col = index % 8;
int modulo = (row % 2 == 0) ? 0 : 1;
Color color = (index % 2 == modulo) ? Color(0xffeeeebb) : DARK_COLOR;
return Container(
color: color,
child: Text (display_str)
);
}),
);
return result;
}
}



#ffffffffrefers to solid white. I imagine that's not the color you want to represent your "dark color". - Abion47