flutter 想要在扑动中创造一个两个方向的拼字游戏内容

aurhwmvo  于 2023-06-24  发布在  Flutter
关注(0)|答案(1)|浏览(92)

我如何才能使一个15 * 10个盒子的表,这是可滚动的水平和垂直。我还想给予一个唯一的密钥来访问每个网格。建议我,我怎么做在Flutter。
我尝试使用表,GridView.count和GridView.builder,但无法满足结果。

ghhkc1vu

ghhkc1vu1#

尝试下面的示例

List<Widget> _buildCells(int count) {
    return List.generate(
      count,
          (index) => Container(
        alignment: Alignment.center,
        width: 120.0,
        height: 60.0,
        color: Colors.white,
        margin: EdgeInsets.all(4.0),
        child: Text("${index + 1}",),
      ),
    );
  }

  List<Widget> _buildRows(int count) {
    return List.generate(
      count,
          (index) => Row(
        children: _buildCells(10),
      ),
    );
  }

 @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        backgroundColor: Colors.white24,
        appBar: AppBar(
          title: Text("Flutter Demo"),
          centerTitle: true,
          automaticallyImplyLeading: false,
        ),
        body: SingleChildScrollView(
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Flexible(
                child: SingleChildScrollView(
                  scrollDirection: Axis.horizontal,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: _buildRows(20),
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );

  }

相关问题