Multiple rows in body of flutter application

时间秒杀一切 提交于 2021-02-07 06:46:26

问题


I am trying to create a screen in flutter that has 3 rows stacked on top of each other but I keep getting syntax errors. I have tried multiple containers in the body, Rows etc and keep getting syntax errors, is what im trying to do impossible? I would think Rows would be stackable, or at least containers in a body.

Here is the code:

import 'package:flutter/material.dart';

class Index extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        backgroundColor: const Color(0xFF0099a9),
      ),
      body: Row(
        //ROW 1
        children: [
          Container(
            color: Colors.orange,
            margin: EdgeInsets.all(25.0),
            child: FlutterLogo(
              size: 60.0,
            ),
          ),
          Container(
            color: Colors.blue,
            margin: EdgeInsets.all(25.0),
            child: FlutterLogo(
              size: 60.0,
            ),
          ),
          Container(
            color: Colors.purple,
            margin: EdgeInsets.all(25.0),
            child: FlutterLogo(
              size: 60.0,
            ),
          ),
        ],
      ),
      Row(
        //ROW 2
        children: [
          Container(
            color: Colors.orange,
            margin: EdgeInsets.all(25.0),
            child: FlutterLogo(
              size: 60.0,
            ),
          ),
        ],
      ),
    );
  }
}

回答1:


try to use the Formatter included by the IDE otherwise it will be a disaster to maintain the code.

https://flutter.io/formatting/

Here you have your code:

    class Index extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
              backgroundColor: const Color(0xFF0099a9),
            ),
            body: Column(children: <Widget>[
              Row(
                //ROW 1
                children: [
                  Container(
                    color: Colors.orange,
                    margin: EdgeInsets.all(25.0),
                    child: FlutterLogo(
                      size: 60.0,
                    ),
                  ),
                  Container(
                    color: Colors.blue,
                    margin: EdgeInsets.all(25.0),
                    child: FlutterLogo(
                      size: 60.0,
                    ),
                  ),
                  Container(
                    color: Colors.purple,
                    margin: EdgeInsets.all(25.0),
                    child: FlutterLogo(
                      size: 60.0,
                    ),
                  ),
                ],
              ),
              Row(//ROW 2
                  children: [
                Container(
                  color: Colors.orange,
                  margin: EdgeInsets.all(25.0),
                  child: FlutterLogo(
                    size: 60.0,
                  ),
                ),
                Container(
                  color: Colors.blue,
                  margin: EdgeInsets.all(25.0),
                  child: FlutterLogo(
                    size: 60.0,
                  ),
                ),
                Container(
                  color: Colors.purple,
                  margin: EdgeInsets.all(25.0),
                  child: FlutterLogo(
                    size: 60.0,
                  ),
                )
              ]),
              Row(// ROW 3
                  children: [
                Container(
                  color: Colors.orange,
                  margin: EdgeInsets.all(25.0),
                  child: FlutterLogo(
                    size: 60.0,
                  ),
                ),
                Container(
                  color: Colors.blue,
                  margin: EdgeInsets.all(25.0),
                  child: FlutterLogo(
                    size: 60.0,
                  ),
                ),
                Container(
                  color: Colors.purple,
                  margin: EdgeInsets.all(25.0),
                  child: FlutterLogo(
                    size: 60.0,
                  ),
                ),
              ]),
            ]));
      }
    }


来源:https://stackoverflow.com/questions/52046840/multiple-rows-in-body-of-flutter-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!