手风琴小部件颤抖

时间:2020-09-07 11:46:17

标签: flutter dart expandablelistview

我有这三个可扩展的列表,我希望它可以用作小部件手风琴

我想在打开第二个列表时必须关闭第一个列表 所以我想解决这个问题,但是找不到解决方案 您会在下面找到我使用的元素的代码

要使其正常工作,我需要进行哪些更改

import 'package:flutter/material.dart';
class DropDown extends StatefulWidget {
  String txt, text;
  Color color;
  DropDown(this.txt, this.text, this.color);
  @override
  State<StatefulWidget> createState() {
    return _DropDownState(txt, text, color);
  }
}
class _DropDownState extends State<DropDown> {
  String txt;
  Color color;
  String text;
  bool isExpand = false;
  _DropDownState(this.txt, this.text, this.color);
  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 2.0,
      child: ExpansionTile(
        trailing: (isExpand == true)
            ? Icon(
                Icons.arrow_drop_up,
                size: 32,
                color: color,
              )
            : Icon(Icons.arrow_drop_down, size: 32, color: color),
        onExpansionChanged: (value) {
          setState(() {
            isExpand = value;
          });
        },
        title: Text.rich(TextSpan(
            text: text,
            style: TextStyle(fontFamily: "Poppins", fontSize: 16),
            children: <TextSpan>[
              TextSpan(
                  text: txt,
                  style: TextStyle(
                      color: color,
                      fontFamily: "Poppins",
                      fontWeight: FontWeight.w700,
                      fontSize: 16)),
              TextSpan(
                  text: " ?",
                  style: TextStyle(fontFamily: "Poppins", fontSize: 16)),
            ])),
        backgroundColor: Theme.of(context).accentColor.withOpacity(0.025),
        children: const <Widget>[
          ListTile(
            title: Text(
                'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'),
          ),
        ],
      ),
    );
  }
}

0 个答案:

没有答案