zoukankan      html  css  js  c++  java
  • flutter-流式布局

    import 'package:flutter/material.dart';
    
    class WrapDemo extends StatefulWidget {
      @override
      _WrapDemoState createState() => _WrapDemoState();
    }
    
    class _WrapDemoState extends State<WrapDemo> {
      List<Widget> list;
    
      @override
      void initState() {
        list = List<Widget>()..add(buildAddButton());
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        //屏幕的宽度
        final width=MediaQuery.of(context).size.width;
        //屏幕的高度
        final height = MediaQuery.of(context).size.height;
        return Container(
          child: Scaffold(
            appBar: AppBar(title: Text('wrap'),),
            body: Center(
              child: Opacity(
                opacity: 0.8,
                child: Container(
                   width,
                  height: height / 2,
                  color: Colors.grey,
                  child: Wrap(
                    children: list,
                    spacing: 26.0,//间距
                  ),
                ),
              ),
            ),
          ),
        );
      }
    
      Widget buildAddButton(){
        return GestureDetector( //手势识别
          onTap: (){
            if(list.length<9){
              setState(() {
                list.insert(list.length-1, buildPhoto());
              });
              
    
            }
          },
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Container(
               80.0,
              height: 80.0,
              color: Colors.black54,
              child: Icon(Icons.add),
            ),
          ),
        );
      }
    
    Widget buildPhoto(){
      return Padding(
        padding: const EdgeInsets.all(8.0),
        child: Container(
           80.0,
          height: 80.0,
          color: Colors.amber,
          child: Center(
            child: Text('照片'),
          ),
        ),
      );
    }
    
    }

     

  • 相关阅读:
    吉哥系列故事――恨7不成妻
    K
    F
    树状数组
    34.在排序数组中查找元素的第一个和最后一个位置--二分查找
    CSS选择器及其权重
    CSS布局 圣杯和双飞翼
    983. 最低票价 -- 动态规划
    合并k个排序链表 二分
    面试题 16.03. 交点
  • 原文地址:https://www.cnblogs.com/lxz-blogs/p/13235341.html
Copyright © 2011-2022 走看看