本文共 1922 字,大约阅读时间需要 6 分钟。
MaterialSlice进行演示
import 'package:flutter/material.dart';class MergeableMaterialItemDemo extends StatefulWidget { _MergeableMaterialItemState createState() => _MergeableMaterialItemState();}class _MergeableMaterialItemState extends State{ final List items = []; 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 (currIndexNum), child: Column(children: [ // 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: [ MergeableMaterial(hasDividers: true, children: items), RaisedButton( child: Text("点击添加"), onPressed: () { _isChildExpanded(); }, ) ], ); }}
转载地址:http://yaqwm.baihongyu.com/