美文网首页
Flutter构建布局

Flutter构建布局

作者: FrankyJ | 来源:发表于2019-03-08 14:39 被阅读0次

1、第一个布局

import 'package:flutter/material.dart';

// Uncomment lines 7 and 10 to view the visual layout at runtime.

// import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;

void main() {

  runApp(MyApp());

}

class MyApp extends StatelessWidget{

  @override

  Widget build(BuildContext context) {

    Widget titleSection = Container(

      padding: const EdgeInsets.only(bottom: 11,top: 11,left: 11),

      color: Colors.grey,

      child: Row(

        children: <Widget>[

          /*1*/

          Expanded(child: Column(

            crossAxisAlignment: CrossAxisAlignment.start,

            children: <Widget>[

              /*2*/

              Container(

                color: Colors.lightGreen,

                padding: const EdgeInsets.only(top: 0,bottom: 8,left: 0),

                child: Text('text1',style: TextStyle(fontWeight: FontWeight.bold),),

              ),

              Text('text2',style: TextStyle(color: Colors.red[500]),),

            ],

          )),

          Container(

            height: 100,

            color: Colors.green,

            padding: const EdgeInsets.only(right: 0,top: 0),

            child: Icon(Icons.star,color: Colors.red[500],),

          ),

          Container(

            height: 60,

            color: Colors.greenAccent,

            padding: const EdgeInsets.only(right: 11,bottom: 0,left: 11),

            child: Text('413242342342',),

          ),

        ],

      ),

    );

     var color = Theme.of(context).primaryColor;

     var bottonSection = Container(

       child: Row(

         mainAxisAlignment: MainAxisAlignment.spaceEvenly,

         children: <Widget>[

           _buildButtonColumn(color, Icons.call, 'CALL'),

           _buildButtonColumn(color, Icons.near_me, 'ROUTE'),

           _buildButtonColumn(color, Icons.share, 'SHARE'),

         ],

       ),

     );

     var textSection = Container(

       padding: const EdgeInsets.all(32),

       child: Text(

         'Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese '

         'Alps. Situated 1,578 meters above sea level, it is one of the '

             'larger Alpine Lakes. A gondola ride from Kandersteg, followed by a '

             'half-hour walk through pastures and pine forest, leads you to the '

             'lake, which warms to 20 degrees Celsius in the summer. Activities '

             'enjoyed here include rowing, and riding the summer toboggan run.',

         softWrap: true,

       ),

     );

    return MaterialApp(

      home: Scaffold(

        appBar: AppBar(

          title: Text('layout demo'),

        ),

        body: ListView(

          children: <Widget>[

            Image.asset(

              'assets/images/food05.jpeg',

              width: 600,

              height: 200,

              fit: BoxFit.cover,

            ),

            titleSection,

            bottonSection,

            textSection,

          ],

        ),

      ),

    );

  }

  Column _buildButtonColumn(Color color,IconData icon, String label) {

    return Column(

//      mainAxisSize: MainAxisSize.min,

//      mainAxisAlignment: MainAxisAlignment.center,

      children: <Widget>[

        Icon(icon,color: color,),

        Container(

          child: Text(label,style: TextStyle(

            fontSize: 12,

            fontWeight: FontWeight.w400,

            color: color

          ),),

        ),

      ],

    );

  }

}

添加调试

void main() {

  debugPaintSizeEnabled=true;

  runApp(MyApp());

}

相关文章

  • Flutter 基础性看这个就够了

    构建布局:详情参考:在Flutter中构建布局 - Flutter中文网 对齐,设置style 等 注意点: 1...

  • 移动端混合开发Flutter入坑(三)综合布局

    本章会介绍 Flutter的布局机制如何工作如何纵向和横向布置小部件如何构建Flutter布局 GitHub代码 ...

  • Flutter构建布局

    1、第一个布局 import'package:flutter/material.dart'; //Uncommen...

  • Flutter学习笔记4--Flutter初识

    本文主要介绍Flutter项目的简单界面构建,以及布局 一.创建新的Flutter工程 使用终端进行创建flutt...

  • Flutter -在Flutter中构建布局

    在Flutter中构建布局参考官方文档地址: https://flutterchina.club/tutorial...

  • 在flutter 构建布局

    本文根据官网文档,照抄官方文档布局 构建布局 设置 这里环境必须搭建好,这里不做重复,没有搭建好环境的,请查看别人...

  • Flutter 布局

    Flutter 布局详解 Flutter 布局(一)- Container详解 Flutter 布局(二)- Pa...

  • Flutter 命令

    构建 构建常用参数 构建Flutter Application 构建Flutter Module 构建Packag...

  • Flutter-布局

    一、介绍 flutter布局需要先了解flutter所有布局的widget,首先flutter布局分为Contai...

  • Flutter布局入门

    Flutter布局入门 一、Widget简介 描述 Fullter的核心思想是用widget 来构建你的 UI 界...

网友评论

      本文标题:Flutter构建布局

      本文链接:https://www.haomeiwen.com/subject/jyyrpqtx.html