How to modify the status of the flutter dialog externally?

-1

I'm creating a custom dialog. I hope it has three states: loading, success and failed. Then it is similar to [mydialog(type:Loading);] when my network request has results, call [mydialog(). Changetype(type:Success);].The same dialog object is used here怂But I can't change its status. If you know how to do it, please let me know. Thank you very much


enum TipType { LOADING, SUCCESS, FAIL }

class CommonBottomTip extends StatefulWidget {
  CommonBottomTip({this.tipType = TipType.LOADING, this.info = "123"});

  final TipType tipType;
  final String info;
  @override
  _CommonBottomTipState createState() => _CommonBottomTipState();

  show(BuildContext context, {TipType tipType = TipType.LOADING}) {
    Navigator.of(context).pop();
    showModalBottomSheet(
        context: context,
        builder: (BuildContext context) {
          return CommonBottomTip(tipType: tipType);
        });
  }

  _CommonBottomTipState of(BuildContext context) =>
      context.findAncestorStateOfType<_CommonBottomTipState>();
}

class _CommonBottomTipState extends State<CommonBottomTip> {
  TipType myTipType;
  String _tipInfo;
  @override
  void initState() {
    super.initState();
    myTipType = widget.tipType;
    _tipInfo = widget.info;
  }

  Widget buildImageItem() {
    switch (myTipType) {
      case TipType.LOADING:
        {
          this.setState(() {
            _tipInfo = "Loading";
          });
          return CircularProgressIndicator(
            valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
          );
        }
      case TipType.SUCCESS:
        {
          this.setState(() {
            _tipInfo = "Success";
          });
          return Image(
            image: AssetImage("assets/images/save_success.png"),
          );
        }
      case TipType.FAIL:
        {
          this.setState(() {
            _tipInfo = "Fail";
          });
          return Image(
            image: AssetImage("assets/images/save_fail.png"),
          );
        }
      default:
        {
          this.setState(() {
            _tipInfo = "Loading";
          });
          return CircularProgressIndicator(
            valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
          );
        }
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 50,
      alignment: Alignment.centerLeft,
      child: Row(
        children: <Widget>[
          Padding(
            child: SizedBox(
              child: buildImageItem(),
              width: 25,
              height: 25,
            ),
            padding: EdgeInsets.only(left: 30),
          ),
          Padding(
            child: Text(
              _tipInfo,
              style: TextStyle(fontSize: 18, color: Color(0xffff0000)),
            ),
            padding: EdgeInsets.only(left: 30),
          )
        ],
      ),
    );
  }
}
flutter
dialog
statefulwidget
asked on Stack Overflow Sep 3, 2020 by zerong jiang

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0