Search code examples
flutterdesktop-application

Is it possible to initiate a 2 dimensional array of SizedBox (as an example, I need some kind of square) in Flutter


I want to program a chess game in Flutter so first I need to make my own board. For that, I thought I can initiate a 2 dimension array of SizedBox-es (again, not necessarily) and color it just like a real chess board. But is it possible?


Solution

  • A better option is to add a gridView like this:

    GridView.builder(
                            itemCount: 64,
                            gridDelegate:
                                SliverGridDelegateWithFixedCrossAxisCount(
                                    crossAxisCount: 8,
                                    crossAxisSpacing: 4.0,
                                    mainAxisSpacing: 4.0),
                            itemBuilder: (BuildContext context, int index) {
                              return Container(
                                color: index%2 == 0 ? Colors.white : Colors.black
                              );
                            },
                          )
    

    If you have SizedBox instead, it will be difficult for you to add color, coin image, and alignment etc