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),
)
],
),
);
}
}
User contributions licensed under CC BY-SA 3.0