Flutter MergeableMaterialItem

简介

MaterialSlice 和 MaterialGap的基本类型

  • 所有的MergeableMaterialItem对象都需要LocalKey

基础用法

MaterialSlice进行演示

  • MaterialSlice做为 MergeableMaterial子类。它作为Material,可以和其他的slices合并使用

实例演示


import 'package:flutter/material.dart';

class MergeableMaterialItemDemo extends StatefulWidget {
  _MergeableMaterialItemState createState() => _MergeableMaterialItemState();
}

class _MergeableMaterialItemState extends State<MergeableMaterialItemDemo> {
  final List<MergeableMaterialItem> items = <MergeableMaterialItem>[];
  bool currIndex = false;
  int currIndexNum = 1;

  _isChildExpanded() {
    setState(() {
      currIndex ? currIndex = false : currIndex = true;
      currIndexNum++;
    });
  }

  @override
  Widget build(BuildContext context) {
    items.add(

        //class MaterialSlice extends MergeableMaterialItem
         MaterialSlice(
            key:  ValueKey<int>(currIndexNum),
            child:  Column(children: <Widget>[
              // header,
               AnimatedCrossFade(
                firstChild:  Container(
                  height: 20.0,
                  width: 20.0,
                  color: Colors.green,
                ),
                secondChild:  Container(
                  height: 20.0,
                  width: 20.0,
                  color: Colors.red,
                ),
                crossFadeState: currIndex
                    ? CrossFadeState.showSecond
                    : CrossFadeState.showFirst,
                firstCurve:
                    const Interval(0.0, 0.6, curve: Curves.fastOutSlowIn),
                secondCurve:
                    const Interval(0.4, 1.0, curve: Curves.fastOutSlowIn),
                sizeCurve: Curves.fastOutSlowIn,
                duration: Duration(microseconds: 6),
              )
            ])));

    return Column(
      children: <Widget>[
         MergeableMaterial(hasDividers: true, children: items),
         RaisedButton(
          child: Text("点击添加"),
          onPressed: () {
            _isChildExpanded();
          },
        )
      ],
    );
  }
}

上一篇:动手实战-基于EMR离线数据分析


下一篇:Sonarqube集群安装配置