【自学Flutter】8 Column布局和Row布局的使用

8 Column布局和Row布局的使用

1.源代码

import 'package:flutter/material.dart';

void main () => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  GlobalKey globalKey = new GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
          body: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Column(
                  children: <Widget>[
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                  ],
                ),
                Row(
                  children: <Widget>[
                    Text("我是Row布局"),
                    Text("我是Row布局"),
                    Text("我是Row布局"),
                    Text("我是Row布局"),
                  ],
                )
              ]
          ),
        )
    );
  }
}

2.解释源代码

import 'package:flutter/material.dart';

void main () => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  GlobalKey globalKey = new GlobalKey<FormState>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
          //Column布局
          body: Column(
              //居中表示
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                //Column布局
                Column(
                  children: <Widget>[
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                    Text("我是Column布局"),
                  ],
                ),
                //Row布局
                Row(
                  children: <Widget>[
                    Text("我是Row布局"),
                    Text("我是Row布局"),
                    Text("我是Row布局"),
                    Text("我是Row布局"),
                  ],
                )
              ]
          ),
        )
    );
  }
}

3.效果图

【自学Flutter】8 Column布局和Row布局的使用_第1张图片

你可能感兴趣的:(自学Flutter)